Skip to content

Commit 4d207d3

Browse files
committed
Allow userdefined order and start with drag and drop resorting
Signed-off-by: Julius Härtl <[email protected]>
1 parent 2825e4d commit 4d207d3

File tree

6 files changed

+333
-30
lines changed

6 files changed

+333
-30
lines changed

apps/dashboard/appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
return [
2525
'routes' => [
2626
['name' => 'dashboard#index', 'url' => '/', 'verb' => 'GET'],
27+
['name' => 'dashboard#updateLayout', 'url' => '/layout', 'verb' => 'POST'],
2728
]
2829
];

apps/dashboard/lib/Controller/DashboardController.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323

2424
namespace OCA\Dashboard\Controller;
2525

26+
use OCA\Dashboard\AppInfo\Application;
2627
use OCA\Viewer\Event\LoadViewer;
2728
use OCP\AppFramework\Controller;
29+
use OCP\AppFramework\Http\JSONResponse;
2830
use OCP\AppFramework\Http\TemplateResponse;
2931
use OCP\Dashboard\IManager;
3032
use OCP\Dashboard\IPanel;
3133
use OCP\Dashboard\RegisterPanelEvent;
3234
use OCP\EventDispatcher\IEventDispatcher;
35+
use OCP\IConfig;
3336
use OCP\IInitialStateService;
3437
use OCP\IRequest;
3538

@@ -41,19 +44,27 @@ class DashboardController extends Controller {
4144
private $eventDispatcher;
4245
/** @var IManager */
4346
private $dashboardManager;
47+
/** @var IConfig */
48+
private $config;
49+
/** @var string */
50+
private $userId;
4451

4552
public function __construct(
4653
$appName,
4754
IRequest $request,
4855
IInitialStateService $initialStateService,
4956
IEventDispatcher $eventDispatcher,
50-
IManager $dashboardManager
57+
IManager $dashboardManager,
58+
IConfig $config,
59+
$userId
5160
) {
5261
parent::__construct($appName, $request);
5362

5463
$this->inititalStateService = $initialStateService;
5564
$this->eventDispatcher = $eventDispatcher;
5665
$this->dashboardManager = $dashboardManager;
66+
$this->config = $config;
67+
$this->userId = $userId;
5768
}
5869

5970
/**
@@ -64,21 +75,32 @@ public function __construct(
6475
public function index(): TemplateResponse {
6576
$this->eventDispatcher->dispatchTyped(new RegisterPanelEvent($this->dashboardManager));
6677

67-
$dashboardManager = $this->dashboardManager;
78+
$userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', 'calendar,recommendations,talk,mail'));
6879
$panels = array_map(function (IPanel $panel) {
6980
return [
7081
'id' => $panel->getId(),
7182
'title' => $panel->getTitle(),
7283
'iconClass' => $panel->getIconClass(),
7384
'url' => $panel->getUrl()
7485
];
75-
}, $dashboardManager->getPanels());
86+
}, $this->dashboardManager->getPanels());
7687
$this->inititalStateService->provideInitialState('dashboard', 'panels', $panels);
88+
$this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout);
7789

7890
if (class_exists(LoadViewer::class)) {
7991
$this->eventDispatcher->dispatchTyped(new LoadViewer());
8092
}
8193

8294
return new TemplateResponse('dashboard', 'index');
8395
}
96+
97+
/**
98+
* @NoAdminRequired
99+
* @param string $layout
100+
* @return JSONResponse
101+
*/
102+
public function updateLayout(string $layout): JSONResponse {
103+
$this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout);
104+
return new JSONResponse(['layout' => $layout]);
105+
}
84106
}

0 commit comments

Comments
 (0)