@@ -46,166 +46,166 @@ |
||
46 | 46 | |
47 | 47 | class DashboardController extends Controller { |
48 | 48 | |
49 | - /** @var IInitialStateService */ |
|
50 | - private $inititalStateService; |
|
51 | - /** @var IEventDispatcher */ |
|
52 | - private $eventDispatcher; |
|
53 | - /** @var IAppManager */ |
|
54 | - private $appManager; |
|
55 | - /** @var IManager */ |
|
56 | - private $dashboardManager; |
|
57 | - /** @var IConfig */ |
|
58 | - private $config; |
|
59 | - /** @var string */ |
|
60 | - private $userId; |
|
61 | - /** |
|
62 | - * @var BackgroundService |
|
63 | - */ |
|
64 | - private $backgroundService; |
|
65 | - |
|
66 | - public function __construct( |
|
67 | - string $appName, |
|
68 | - IRequest $request, |
|
69 | - IInitialStateService $initialStateService, |
|
70 | - IEventDispatcher $eventDispatcher, |
|
71 | - IAppManager $appManager, |
|
72 | - IManager $dashboardManager, |
|
73 | - IConfig $config, |
|
74 | - BackgroundService $backgroundService, |
|
75 | - $userId |
|
76 | - ) { |
|
77 | - parent::__construct($appName, $request); |
|
78 | - |
|
79 | - $this->inititalStateService = $initialStateService; |
|
80 | - $this->eventDispatcher = $eventDispatcher; |
|
81 | - $this->appManager = $appManager; |
|
82 | - $this->dashboardManager = $dashboardManager; |
|
83 | - $this->config = $config; |
|
84 | - $this->backgroundService = $backgroundService; |
|
85 | - $this->userId = $userId; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @NoCSRFRequired |
|
90 | - * @NoAdminRequired |
|
91 | - * @return TemplateResponse |
|
92 | - */ |
|
93 | - public function index(): TemplateResponse { |
|
94 | - \OCP\Util::addStyle('dashboard', 'dashboard'); |
|
95 | - $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
96 | - if (class_exists(LoadViewer::class)) { |
|
97 | - $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
98 | - } |
|
99 | - |
|
100 | - $this->eventDispatcher->dispatchTyped(new RegisterWidgetEvent($this->dashboardManager)); |
|
101 | - |
|
102 | - $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar'); |
|
103 | - $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)); |
|
104 | - $widgets = array_map(function (IWidget $widget) { |
|
105 | - return [ |
|
106 | - 'id' => $widget->getId(), |
|
107 | - 'title' => $widget->getTitle(), |
|
108 | - 'iconClass' => $widget->getIconClass(), |
|
109 | - 'url' => $widget->getUrl() |
|
110 | - ]; |
|
111 | - }, $this->dashboardManager->getWidgets()); |
|
112 | - $configStatuses = $this->config->getUserValue($this->userId, 'dashboard', 'statuses', ''); |
|
113 | - $statuses = json_decode($configStatuses, true); |
|
114 | - // We avoid getting an empty array as it will not produce an object in UI's JS |
|
115 | - // It does not matter if some statuses are missing from the array, missing ones are considered enabled |
|
116 | - $statuses = ($statuses && count($statuses) > 0) ? $statuses : ['weather' => true]; |
|
117 | - |
|
118 | - // if theming app is enabled and wants to override default, we pass it |
|
119 | - $themingDefaultBackground = $this->appManager->isEnabledForUser('theming') |
|
120 | - ? $this->config->getAppValue('theming', 'backgroundMime', '') |
|
121 | - : ''; |
|
122 | - $this->inititalStateService->provideInitialState('dashboard', 'themingDefaultBackground', $themingDefaultBackground); |
|
123 | - $this->inititalStateService->provideInitialState('dashboard', 'panels', $widgets); |
|
124 | - $this->inititalStateService->provideInitialState('dashboard', 'statuses', $statuses); |
|
125 | - $this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout); |
|
126 | - $this->inititalStateService->provideInitialState('dashboard', 'firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1'); |
|
127 | - $this->inititalStateService->provideInitialState('dashboard', 'shippedBackgrounds', BackgroundService::SHIPPED_BACKGROUNDS); |
|
128 | - $this->inititalStateService->provideInitialState('dashboard', 'background', $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default')); |
|
129 | - $this->inititalStateService->provideInitialState('dashboard', 'version', $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', 0)); |
|
130 | - $this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0'); |
|
131 | - |
|
132 | - $response = new TemplateResponse('dashboard', 'index'); |
|
133 | - |
|
134 | - // For the weather widget we should allow the geolocation |
|
135 | - $featurePolicy = new Http\FeaturePolicy(); |
|
136 | - $featurePolicy->addAllowedGeoLocationDomain('\'self\''); |
|
137 | - $response->setFeaturePolicy($featurePolicy); |
|
138 | - |
|
139 | - return $response; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @NoAdminRequired |
|
144 | - * @param string $layout |
|
145 | - * @return JSONResponse |
|
146 | - */ |
|
147 | - public function updateLayout(string $layout): JSONResponse { |
|
148 | - $this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout); |
|
149 | - return new JSONResponse(['layout' => $layout]); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @NoAdminRequired |
|
154 | - * @param string $statuses |
|
155 | - * @return JSONResponse |
|
156 | - */ |
|
157 | - public function updateStatuses(string $statuses): JSONResponse { |
|
158 | - $this->config->setUserValue($this->userId, 'dashboard', 'statuses', $statuses); |
|
159 | - return new JSONResponse(['statuses' => $statuses]); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @NoAdminRequired |
|
164 | - */ |
|
165 | - public function setBackground(string $type = 'default', string $value = ''): JSONResponse { |
|
166 | - $currentVersion = (int)$this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', '0'); |
|
167 | - try { |
|
168 | - switch ($type) { |
|
169 | - case 'shipped': |
|
170 | - $this->backgroundService->setShippedBackground($value); |
|
171 | - break; |
|
172 | - case 'custom': |
|
173 | - $this->backgroundService->setFileBackground($value); |
|
174 | - break; |
|
175 | - case 'color': |
|
176 | - $this->backgroundService->setColorBackground($value); |
|
177 | - break; |
|
178 | - case 'default': |
|
179 | - $this->backgroundService->setDefaultBackground(); |
|
180 | - break; |
|
181 | - default: |
|
182 | - return new JSONResponse(['error' => 'Invalid type provided'], Http::STATUS_BAD_REQUEST); |
|
183 | - } |
|
184 | - } catch (\InvalidArgumentException $e) { |
|
185 | - return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
186 | - } catch (\Throwable $e) { |
|
187 | - return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
188 | - } |
|
189 | - $currentVersion++; |
|
190 | - $this->config->setUserValue($this->userId, 'dashboard', 'backgroundVersion', (string)$currentVersion); |
|
191 | - return new JSONResponse([ |
|
192 | - 'type' => $type, |
|
193 | - 'value' => $value, |
|
194 | - 'version' => $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', $currentVersion) |
|
195 | - ]); |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * @NoAdminRequired |
|
200 | - * @NoCSRFRequired |
|
201 | - */ |
|
202 | - public function getBackground() { |
|
203 | - $file = $this->backgroundService->getBackground(); |
|
204 | - if ($file !== null) { |
|
205 | - $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]); |
|
206 | - $response->cacheFor(24 * 60 * 60); |
|
207 | - return $response; |
|
208 | - } |
|
209 | - return new NotFoundResponse(); |
|
210 | - } |
|
49 | + /** @var IInitialStateService */ |
|
50 | + private $inititalStateService; |
|
51 | + /** @var IEventDispatcher */ |
|
52 | + private $eventDispatcher; |
|
53 | + /** @var IAppManager */ |
|
54 | + private $appManager; |
|
55 | + /** @var IManager */ |
|
56 | + private $dashboardManager; |
|
57 | + /** @var IConfig */ |
|
58 | + private $config; |
|
59 | + /** @var string */ |
|
60 | + private $userId; |
|
61 | + /** |
|
62 | + * @var BackgroundService |
|
63 | + */ |
|
64 | + private $backgroundService; |
|
65 | + |
|
66 | + public function __construct( |
|
67 | + string $appName, |
|
68 | + IRequest $request, |
|
69 | + IInitialStateService $initialStateService, |
|
70 | + IEventDispatcher $eventDispatcher, |
|
71 | + IAppManager $appManager, |
|
72 | + IManager $dashboardManager, |
|
73 | + IConfig $config, |
|
74 | + BackgroundService $backgroundService, |
|
75 | + $userId |
|
76 | + ) { |
|
77 | + parent::__construct($appName, $request); |
|
78 | + |
|
79 | + $this->inititalStateService = $initialStateService; |
|
80 | + $this->eventDispatcher = $eventDispatcher; |
|
81 | + $this->appManager = $appManager; |
|
82 | + $this->dashboardManager = $dashboardManager; |
|
83 | + $this->config = $config; |
|
84 | + $this->backgroundService = $backgroundService; |
|
85 | + $this->userId = $userId; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @NoCSRFRequired |
|
90 | + * @NoAdminRequired |
|
91 | + * @return TemplateResponse |
|
92 | + */ |
|
93 | + public function index(): TemplateResponse { |
|
94 | + \OCP\Util::addStyle('dashboard', 'dashboard'); |
|
95 | + $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
96 | + if (class_exists(LoadViewer::class)) { |
|
97 | + $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
98 | + } |
|
99 | + |
|
100 | + $this->eventDispatcher->dispatchTyped(new RegisterWidgetEvent($this->dashboardManager)); |
|
101 | + |
|
102 | + $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar'); |
|
103 | + $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)); |
|
104 | + $widgets = array_map(function (IWidget $widget) { |
|
105 | + return [ |
|
106 | + 'id' => $widget->getId(), |
|
107 | + 'title' => $widget->getTitle(), |
|
108 | + 'iconClass' => $widget->getIconClass(), |
|
109 | + 'url' => $widget->getUrl() |
|
110 | + ]; |
|
111 | + }, $this->dashboardManager->getWidgets()); |
|
112 | + $configStatuses = $this->config->getUserValue($this->userId, 'dashboard', 'statuses', ''); |
|
113 | + $statuses = json_decode($configStatuses, true); |
|
114 | + // We avoid getting an empty array as it will not produce an object in UI's JS |
|
115 | + // It does not matter if some statuses are missing from the array, missing ones are considered enabled |
|
116 | + $statuses = ($statuses && count($statuses) > 0) ? $statuses : ['weather' => true]; |
|
117 | + |
|
118 | + // if theming app is enabled and wants to override default, we pass it |
|
119 | + $themingDefaultBackground = $this->appManager->isEnabledForUser('theming') |
|
120 | + ? $this->config->getAppValue('theming', 'backgroundMime', '') |
|
121 | + : ''; |
|
122 | + $this->inititalStateService->provideInitialState('dashboard', 'themingDefaultBackground', $themingDefaultBackground); |
|
123 | + $this->inititalStateService->provideInitialState('dashboard', 'panels', $widgets); |
|
124 | + $this->inititalStateService->provideInitialState('dashboard', 'statuses', $statuses); |
|
125 | + $this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout); |
|
126 | + $this->inititalStateService->provideInitialState('dashboard', 'firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1'); |
|
127 | + $this->inititalStateService->provideInitialState('dashboard', 'shippedBackgrounds', BackgroundService::SHIPPED_BACKGROUNDS); |
|
128 | + $this->inititalStateService->provideInitialState('dashboard', 'background', $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default')); |
|
129 | + $this->inititalStateService->provideInitialState('dashboard', 'version', $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', 0)); |
|
130 | + $this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0'); |
|
131 | + |
|
132 | + $response = new TemplateResponse('dashboard', 'index'); |
|
133 | + |
|
134 | + // For the weather widget we should allow the geolocation |
|
135 | + $featurePolicy = new Http\FeaturePolicy(); |
|
136 | + $featurePolicy->addAllowedGeoLocationDomain('\'self\''); |
|
137 | + $response->setFeaturePolicy($featurePolicy); |
|
138 | + |
|
139 | + return $response; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @NoAdminRequired |
|
144 | + * @param string $layout |
|
145 | + * @return JSONResponse |
|
146 | + */ |
|
147 | + public function updateLayout(string $layout): JSONResponse { |
|
148 | + $this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout); |
|
149 | + return new JSONResponse(['layout' => $layout]); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @NoAdminRequired |
|
154 | + * @param string $statuses |
|
155 | + * @return JSONResponse |
|
156 | + */ |
|
157 | + public function updateStatuses(string $statuses): JSONResponse { |
|
158 | + $this->config->setUserValue($this->userId, 'dashboard', 'statuses', $statuses); |
|
159 | + return new JSONResponse(['statuses' => $statuses]); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @NoAdminRequired |
|
164 | + */ |
|
165 | + public function setBackground(string $type = 'default', string $value = ''): JSONResponse { |
|
166 | + $currentVersion = (int)$this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', '0'); |
|
167 | + try { |
|
168 | + switch ($type) { |
|
169 | + case 'shipped': |
|
170 | + $this->backgroundService->setShippedBackground($value); |
|
171 | + break; |
|
172 | + case 'custom': |
|
173 | + $this->backgroundService->setFileBackground($value); |
|
174 | + break; |
|
175 | + case 'color': |
|
176 | + $this->backgroundService->setColorBackground($value); |
|
177 | + break; |
|
178 | + case 'default': |
|
179 | + $this->backgroundService->setDefaultBackground(); |
|
180 | + break; |
|
181 | + default: |
|
182 | + return new JSONResponse(['error' => 'Invalid type provided'], Http::STATUS_BAD_REQUEST); |
|
183 | + } |
|
184 | + } catch (\InvalidArgumentException $e) { |
|
185 | + return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
186 | + } catch (\Throwable $e) { |
|
187 | + return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
188 | + } |
|
189 | + $currentVersion++; |
|
190 | + $this->config->setUserValue($this->userId, 'dashboard', 'backgroundVersion', (string)$currentVersion); |
|
191 | + return new JSONResponse([ |
|
192 | + 'type' => $type, |
|
193 | + 'value' => $value, |
|
194 | + 'version' => $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', $currentVersion) |
|
195 | + ]); |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * @NoAdminRequired |
|
200 | + * @NoCSRFRequired |
|
201 | + */ |
|
202 | + public function getBackground() { |
|
203 | + $file = $this->backgroundService->getBackground(); |
|
204 | + if ($file !== null) { |
|
205 | + $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]); |
|
206 | + $response->cacheFor(24 * 60 * 60); |
|
207 | + return $response; |
|
208 | + } |
|
209 | + return new NotFoundResponse(); |
|
210 | + } |
|
211 | 211 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | |
102 | 102 | $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar'); |
103 | 103 | $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)); |
104 | - $widgets = array_map(function (IWidget $widget) { |
|
104 | + $widgets = array_map(function(IWidget $widget) { |
|
105 | 105 | return [ |
106 | 106 | 'id' => $widget->getId(), |
107 | 107 | 'title' => $widget->getTitle(), |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @NoAdminRequired |
164 | 164 | */ |
165 | 165 | public function setBackground(string $type = 'default', string $value = ''): JSONResponse { |
166 | - $currentVersion = (int)$this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', '0'); |
|
166 | + $currentVersion = (int) $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', '0'); |
|
167 | 167 | try { |
168 | 168 | switch ($type) { |
169 | 169 | case 'shipped': |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR); |
188 | 188 | } |
189 | 189 | $currentVersion++; |
190 | - $this->config->setUserValue($this->userId, 'dashboard', 'backgroundVersion', (string)$currentVersion); |
|
190 | + $this->config->setUserValue($this->userId, 'dashboard', 'backgroundVersion', (string) $currentVersion); |
|
191 | 191 | return new JSONResponse([ |
192 | 192 | 'type' => $type, |
193 | 193 | 'value' => $value, |