2323
2424namespace OCA \Dashboard \Controller ;
2525
26+ use OCA \Dashboard \AppInfo \Application ;
2627use OCA \Viewer \Event \LoadViewer ;
2728use OCP \AppFramework \Controller ;
29+ use OCP \AppFramework \Http \JSONResponse ;
2830use OCP \AppFramework \Http \TemplateResponse ;
2931use OCP \Dashboard \IManager ;
3032use OCP \Dashboard \IPanel ;
3133use OCP \Dashboard \RegisterPanelEvent ;
3234use OCP \EventDispatcher \IEventDispatcher ;
35+ use OCP \IConfig ;
3336use OCP \IInitialStateService ;
3437use 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