@@ -45,152 +45,152 @@ |
||
| 45 | 45 | |
| 46 | 46 | class DashboardController extends Controller { |
| 47 | 47 | |
| 48 | - /** @var IInitialStateService */ |
|
| 49 | - private $inititalStateService; |
|
| 50 | - /** @var IEventDispatcher */ |
|
| 51 | - private $eventDispatcher; |
|
| 52 | - /** @var IManager */ |
|
| 53 | - private $dashboardManager; |
|
| 54 | - /** @var IConfig */ |
|
| 55 | - private $config; |
|
| 56 | - /** @var string */ |
|
| 57 | - private $userId; |
|
| 58 | - /** |
|
| 59 | - * @var BackgroundService |
|
| 60 | - */ |
|
| 61 | - private $backgroundService; |
|
| 62 | - |
|
| 63 | - public function __construct( |
|
| 64 | - string $appName, |
|
| 65 | - IRequest $request, |
|
| 66 | - IInitialStateService $initialStateService, |
|
| 67 | - IEventDispatcher $eventDispatcher, |
|
| 68 | - IManager $dashboardManager, |
|
| 69 | - IConfig $config, |
|
| 70 | - BackgroundService $backgroundService, |
|
| 71 | - $userId |
|
| 72 | - ) { |
|
| 73 | - parent::__construct($appName, $request); |
|
| 74 | - |
|
| 75 | - $this->inititalStateService = $initialStateService; |
|
| 76 | - $this->eventDispatcher = $eventDispatcher; |
|
| 77 | - $this->dashboardManager = $dashboardManager; |
|
| 78 | - $this->config = $config; |
|
| 79 | - $this->backgroundService = $backgroundService; |
|
| 80 | - $this->userId = $userId; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @NoCSRFRequired |
|
| 85 | - * @NoAdminRequired |
|
| 86 | - * @return TemplateResponse |
|
| 87 | - */ |
|
| 88 | - public function index(): TemplateResponse { |
|
| 89 | - \OCP\Util::addStyle('dashboard', 'dashboard'); |
|
| 90 | - $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
| 91 | - if (class_exists(LoadViewer::class)) { |
|
| 92 | - $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $this->eventDispatcher->dispatchTyped(new RegisterWidgetEvent($this->dashboardManager)); |
|
| 96 | - |
|
| 97 | - $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', 'recommendations,spreed,mail,calendar')); |
|
| 98 | - $widgets = array_map(function (IWidget $widget) { |
|
| 99 | - return [ |
|
| 100 | - 'id' => $widget->getId(), |
|
| 101 | - 'title' => $widget->getTitle(), |
|
| 102 | - 'iconClass' => $widget->getIconClass(), |
|
| 103 | - 'url' => $widget->getUrl() |
|
| 104 | - ]; |
|
| 105 | - }, $this->dashboardManager->getWidgets()); |
|
| 106 | - $configStatuses = $this->config->getUserValue($this->userId, 'dashboard', 'statuses', '{}'); |
|
| 107 | - $statuses = json_decode($configStatuses, true); |
|
| 108 | - $this->inititalStateService->provideInitialState('dashboard', 'panels', $widgets); |
|
| 109 | - $this->inititalStateService->provideInitialState('dashboard', 'statuses', $statuses); |
|
| 110 | - $this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout); |
|
| 111 | - $this->inititalStateService->provideInitialState('dashboard', 'firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1'); |
|
| 112 | - $this->inititalStateService->provideInitialState('dashboard', 'shippedBackgrounds', BackgroundService::SHIPPED_BACKGROUNDS); |
|
| 113 | - $this->inititalStateService->provideInitialState('dashboard', 'background', $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default')); |
|
| 114 | - $this->inititalStateService->provideInitialState('dashboard', 'version', $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', 0)); |
|
| 115 | - $this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0'); |
|
| 116 | - |
|
| 117 | - $response = new TemplateResponse('dashboard', 'index'); |
|
| 118 | - |
|
| 119 | - // For the weather widget we should allow the geolocation |
|
| 120 | - $featurePolicy = new Http\FeaturePolicy(); |
|
| 121 | - $featurePolicy->addAllowedGeoLocationDomain('\'self\''); |
|
| 122 | - $response->setFeaturePolicy($featurePolicy); |
|
| 123 | - |
|
| 124 | - return $response; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @NoAdminRequired |
|
| 129 | - * @param string $layout |
|
| 130 | - * @return JSONResponse |
|
| 131 | - */ |
|
| 132 | - public function updateLayout(string $layout): JSONResponse { |
|
| 133 | - $this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout); |
|
| 134 | - return new JSONResponse(['layout' => $layout]); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @NoAdminRequired |
|
| 139 | - * @param string $statuses |
|
| 140 | - * @return JSONResponse |
|
| 141 | - */ |
|
| 142 | - public function updateStatuses(string $statuses): JSONResponse { |
|
| 143 | - $this->config->setUserValue($this->userId, 'dashboard', 'statuses', $statuses); |
|
| 144 | - return new JSONResponse(['statuses' => $statuses]); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @NoAdminRequired |
|
| 149 | - */ |
|
| 150 | - public function setBackground(string $type = 'default', string $value = ''): JSONResponse { |
|
| 151 | - $currentVersion = (int)$this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', '0'); |
|
| 152 | - try { |
|
| 153 | - switch ($type) { |
|
| 154 | - case 'shipped': |
|
| 155 | - $this->backgroundService->setShippedBackground($value); |
|
| 156 | - break; |
|
| 157 | - case 'custom': |
|
| 158 | - $this->backgroundService->setFileBackground($value); |
|
| 159 | - break; |
|
| 160 | - case 'color': |
|
| 161 | - $this->backgroundService->setColorBackground($value); |
|
| 162 | - break; |
|
| 163 | - case 'default': |
|
| 164 | - $this->backgroundService->setDefaultBackground(); |
|
| 165 | - break; |
|
| 166 | - default: |
|
| 167 | - return new JSONResponse(['error' => 'Invalid type provided'], Http::STATUS_BAD_REQUEST); |
|
| 168 | - } |
|
| 169 | - } catch (\InvalidArgumentException $e) { |
|
| 170 | - return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
| 171 | - } catch (\Throwable $e) { |
|
| 172 | - return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 173 | - } |
|
| 174 | - $currentVersion++; |
|
| 175 | - $this->config->setUserValue($this->userId, 'dashboard', 'backgroundVersion', (string)$currentVersion); |
|
| 176 | - return new JSONResponse([ |
|
| 177 | - 'type' => $type, |
|
| 178 | - 'value' => $value, |
|
| 179 | - 'version' => $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', $currentVersion) |
|
| 180 | - ]); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * @NoAdminRequired |
|
| 185 | - * @NoCSRFRequired |
|
| 186 | - */ |
|
| 187 | - public function getBackground() { |
|
| 188 | - $file = $this->backgroundService->getBackground(); |
|
| 189 | - if ($file !== null) { |
|
| 190 | - $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]); |
|
| 191 | - $response->cacheFor(24 * 60 * 60); |
|
| 192 | - return $response; |
|
| 193 | - } |
|
| 194 | - return new NotFoundResponse(); |
|
| 195 | - } |
|
| 48 | + /** @var IInitialStateService */ |
|
| 49 | + private $inititalStateService; |
|
| 50 | + /** @var IEventDispatcher */ |
|
| 51 | + private $eventDispatcher; |
|
| 52 | + /** @var IManager */ |
|
| 53 | + private $dashboardManager; |
|
| 54 | + /** @var IConfig */ |
|
| 55 | + private $config; |
|
| 56 | + /** @var string */ |
|
| 57 | + private $userId; |
|
| 58 | + /** |
|
| 59 | + * @var BackgroundService |
|
| 60 | + */ |
|
| 61 | + private $backgroundService; |
|
| 62 | + |
|
| 63 | + public function __construct( |
|
| 64 | + string $appName, |
|
| 65 | + IRequest $request, |
|
| 66 | + IInitialStateService $initialStateService, |
|
| 67 | + IEventDispatcher $eventDispatcher, |
|
| 68 | + IManager $dashboardManager, |
|
| 69 | + IConfig $config, |
|
| 70 | + BackgroundService $backgroundService, |
|
| 71 | + $userId |
|
| 72 | + ) { |
|
| 73 | + parent::__construct($appName, $request); |
|
| 74 | + |
|
| 75 | + $this->inititalStateService = $initialStateService; |
|
| 76 | + $this->eventDispatcher = $eventDispatcher; |
|
| 77 | + $this->dashboardManager = $dashboardManager; |
|
| 78 | + $this->config = $config; |
|
| 79 | + $this->backgroundService = $backgroundService; |
|
| 80 | + $this->userId = $userId; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @NoCSRFRequired |
|
| 85 | + * @NoAdminRequired |
|
| 86 | + * @return TemplateResponse |
|
| 87 | + */ |
|
| 88 | + public function index(): TemplateResponse { |
|
| 89 | + \OCP\Util::addStyle('dashboard', 'dashboard'); |
|
| 90 | + $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
| 91 | + if (class_exists(LoadViewer::class)) { |
|
| 92 | + $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $this->eventDispatcher->dispatchTyped(new RegisterWidgetEvent($this->dashboardManager)); |
|
| 96 | + |
|
| 97 | + $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', 'recommendations,spreed,mail,calendar')); |
|
| 98 | + $widgets = array_map(function (IWidget $widget) { |
|
| 99 | + return [ |
|
| 100 | + 'id' => $widget->getId(), |
|
| 101 | + 'title' => $widget->getTitle(), |
|
| 102 | + 'iconClass' => $widget->getIconClass(), |
|
| 103 | + 'url' => $widget->getUrl() |
|
| 104 | + ]; |
|
| 105 | + }, $this->dashboardManager->getWidgets()); |
|
| 106 | + $configStatuses = $this->config->getUserValue($this->userId, 'dashboard', 'statuses', '{}'); |
|
| 107 | + $statuses = json_decode($configStatuses, true); |
|
| 108 | + $this->inititalStateService->provideInitialState('dashboard', 'panels', $widgets); |
|
| 109 | + $this->inititalStateService->provideInitialState('dashboard', 'statuses', $statuses); |
|
| 110 | + $this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout); |
|
| 111 | + $this->inititalStateService->provideInitialState('dashboard', 'firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1'); |
|
| 112 | + $this->inititalStateService->provideInitialState('dashboard', 'shippedBackgrounds', BackgroundService::SHIPPED_BACKGROUNDS); |
|
| 113 | + $this->inititalStateService->provideInitialState('dashboard', 'background', $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default')); |
|
| 114 | + $this->inititalStateService->provideInitialState('dashboard', 'version', $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', 0)); |
|
| 115 | + $this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0'); |
|
| 116 | + |
|
| 117 | + $response = new TemplateResponse('dashboard', 'index'); |
|
| 118 | + |
|
| 119 | + // For the weather widget we should allow the geolocation |
|
| 120 | + $featurePolicy = new Http\FeaturePolicy(); |
|
| 121 | + $featurePolicy->addAllowedGeoLocationDomain('\'self\''); |
|
| 122 | + $response->setFeaturePolicy($featurePolicy); |
|
| 123 | + |
|
| 124 | + return $response; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @NoAdminRequired |
|
| 129 | + * @param string $layout |
|
| 130 | + * @return JSONResponse |
|
| 131 | + */ |
|
| 132 | + public function updateLayout(string $layout): JSONResponse { |
|
| 133 | + $this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout); |
|
| 134 | + return new JSONResponse(['layout' => $layout]); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @NoAdminRequired |
|
| 139 | + * @param string $statuses |
|
| 140 | + * @return JSONResponse |
|
| 141 | + */ |
|
| 142 | + public function updateStatuses(string $statuses): JSONResponse { |
|
| 143 | + $this->config->setUserValue($this->userId, 'dashboard', 'statuses', $statuses); |
|
| 144 | + return new JSONResponse(['statuses' => $statuses]); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @NoAdminRequired |
|
| 149 | + */ |
|
| 150 | + public function setBackground(string $type = 'default', string $value = ''): JSONResponse { |
|
| 151 | + $currentVersion = (int)$this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', '0'); |
|
| 152 | + try { |
|
| 153 | + switch ($type) { |
|
| 154 | + case 'shipped': |
|
| 155 | + $this->backgroundService->setShippedBackground($value); |
|
| 156 | + break; |
|
| 157 | + case 'custom': |
|
| 158 | + $this->backgroundService->setFileBackground($value); |
|
| 159 | + break; |
|
| 160 | + case 'color': |
|
| 161 | + $this->backgroundService->setColorBackground($value); |
|
| 162 | + break; |
|
| 163 | + case 'default': |
|
| 164 | + $this->backgroundService->setDefaultBackground(); |
|
| 165 | + break; |
|
| 166 | + default: |
|
| 167 | + return new JSONResponse(['error' => 'Invalid type provided'], Http::STATUS_BAD_REQUEST); |
|
| 168 | + } |
|
| 169 | + } catch (\InvalidArgumentException $e) { |
|
| 170 | + return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
| 171 | + } catch (\Throwable $e) { |
|
| 172 | + return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 173 | + } |
|
| 174 | + $currentVersion++; |
|
| 175 | + $this->config->setUserValue($this->userId, 'dashboard', 'backgroundVersion', (string)$currentVersion); |
|
| 176 | + return new JSONResponse([ |
|
| 177 | + 'type' => $type, |
|
| 178 | + 'value' => $value, |
|
| 179 | + 'version' => $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', $currentVersion) |
|
| 180 | + ]); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * @NoAdminRequired |
|
| 185 | + * @NoCSRFRequired |
|
| 186 | + */ |
|
| 187 | + public function getBackground() { |
|
| 188 | + $file = $this->backgroundService->getBackground(); |
|
| 189 | + if ($file !== null) { |
|
| 190 | + $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]); |
|
| 191 | + $response->cacheFor(24 * 60 * 60); |
|
| 192 | + return $response; |
|
| 193 | + } |
|
| 194 | + return new NotFoundResponse(); |
|
| 195 | + } |
|
| 196 | 196 | } |
@@ -25,11 +25,11 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | return [ |
| 28 | - 'routes' => [ |
|
| 29 | - ['name' => 'dashboard#index', 'url' => '/', 'verb' => 'GET'], |
|
| 30 | - ['name' => 'dashboard#updateLayout', 'url' => '/layout', 'verb' => 'POST'], |
|
| 31 | - ['name' => 'dashboard#updateStatuses', 'url' => '/statuses', 'verb' => 'POST'], |
|
| 32 | - ['name' => 'dashboard#getBackground', 'url' => '/background', 'verb' => 'GET'], |
|
| 33 | - ['name' => 'dashboard#setBackground', 'url' => '/background/{type}', 'verb' => 'POST'], |
|
| 34 | - ] |
|
| 28 | + 'routes' => [ |
|
| 29 | + ['name' => 'dashboard#index', 'url' => '/', 'verb' => 'GET'], |
|
| 30 | + ['name' => 'dashboard#updateLayout', 'url' => '/layout', 'verb' => 'POST'], |
|
| 31 | + ['name' => 'dashboard#updateStatuses', 'url' => '/statuses', 'verb' => 'POST'], |
|
| 32 | + ['name' => 'dashboard#getBackground', 'url' => '/background', 'verb' => 'GET'], |
|
| 33 | + ['name' => 'dashboard#setBackground', 'url' => '/background/{type}', 'verb' => 'POST'], |
|
| 34 | + ] |
|
| 35 | 35 | ]; |