diff options
author | provokateurin <kate@provokateurin.de> | 2024-01-19 22:23:20 +0100 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2024-05-10 09:44:01 +0200 |
commit | 5f53e446da58cbddc6d6a89736c3fe86edc4695c (patch) | |
tree | 0294798d7b29a4a06e5c67b8a5fd1918d5b2187c /apps | |
parent | d82fe6c7b406465d3ec903c1a69bc81adbfeb481 (diff) | |
download | nextcloud-server-5f53e446da58cbddc6d6a89736c3fe86edc4695c.tar.gz nextcloud-server-5f53e446da58cbddc6d6a89736c3fe86edc4695c.zip |
refactor(dashboard): Let the statuses and layout endpoints use a saner format
Signed-off-by: provokateurin <kate@provokateurin.de>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dashboard/lib/Controller/DashboardApiController.php | 16 | ||||
-rw-r--r-- | apps/dashboard/lib/Controller/DashboardController.php | 15 | ||||
-rw-r--r-- | apps/dashboard/openapi.json | 24 | ||||
-rw-r--r-- | apps/dashboard/src/DashboardApp.vue | 17 |
4 files changed, 46 insertions, 26 deletions
diff --git a/apps/dashboard/lib/Controller/DashboardApiController.php b/apps/dashboard/lib/Controller/DashboardApiController.php index 62aeca4e607..65ec8235a7e 100644 --- a/apps/dashboard/lib/Controller/DashboardApiController.php +++ b/apps/dashboard/lib/Controller/DashboardApiController.php @@ -194,13 +194,13 @@ class DashboardApiController extends OCSController { * Update the layout * * @NoAdminRequired - * @param string $layout The new layout - * @return DataResponse<Http::STATUS_OK, array{layout: string}, array{}> + * @param list<string> $layout The new layout + * @return DataResponse<Http::STATUS_OK, array{layout: list<string>}, array{}> * * 200: Statuses updated successfully */ - public function updateLayout(string $layout): DataResponse { - $this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout); + public function updateLayout(array $layout): DataResponse { + $this->config->setUserValue($this->userId, 'dashboard', 'layout', implode(',', $layout)); return new DataResponse(['layout' => $layout]); } @@ -208,13 +208,13 @@ class DashboardApiController extends OCSController { * Update the statuses * * @NoAdminRequired - * @param string $statuses The new statuses - * @return DataResponse<Http::STATUS_OK, array{statuses: string}, array{}> + * @param list<string> $statuses The new statuses + * @return DataResponse<Http::STATUS_OK, array{statuses: list<string>}, array{}> * * 200: Statuses updated successfully */ - public function updateStatuses(string $statuses): DataResponse { - $this->config->setUserValue($this->userId, 'dashboard', 'statuses', $statuses); + public function updateStatuses(array $statuses): DataResponse { + $this->config->setUserValue($this->userId, 'dashboard', 'statuses', implode(',', $statuses)); return new DataResponse(['statuses' => $statuses]); } } diff --git a/apps/dashboard/lib/Controller/DashboardController.php b/apps/dashboard/lib/Controller/DashboardController.php index f84dab491d8..61b7ccc83ad 100644 --- a/apps/dashboard/lib/Controller/DashboardController.php +++ b/apps/dashboard/lib/Controller/DashboardController.php @@ -30,6 +30,7 @@ declare(strict_types=1); */ namespace OCA\Dashboard\Controller; +use JsonException; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\OpenAPI; @@ -68,7 +69,7 @@ class DashboardController extends Controller { \OCP\Util::addScript('dashboard', 'main', 'theming'); $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar'); - $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)); + $userLayout = array_filter(explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)), fn (string $value) => $value !== ''); $widgets = array_map(function (IWidget $widget) { return [ 'id' => $widget->getId(), @@ -78,10 +79,14 @@ class DashboardController extends Controller { ]; }, $this->dashboardManager->getWidgets()); $configStatuses = $this->config->getUserValue($this->userId, 'dashboard', 'statuses', ''); - $statuses = json_decode($configStatuses, true); - // We avoid getting an empty array as it will not produce an object in UI's JS - // It does not matter if some statuses are missing from the array, missing ones are considered enabled - $statuses = ($statuses && count($statuses) > 0) ? $statuses : ['weather' => true]; + try { + // Parse the old format + $statuses = json_decode($configStatuses, true, 512, JSON_THROW_ON_ERROR); + // We avoid getting an empty array as it will not produce an object in UI's JS + $statuses = array_keys(array_filter($statuses, static fn (bool $value) => $value)); + } catch (JsonException $e) { + $statuses = array_filter(explode(',', $configStatuses), fn (string $value) => $value !== ''); + } $this->initialState->provideInitialState('panels', $widgets); $this->initialState->provideInitialState('statuses', $statuses); diff --git a/apps/dashboard/openapi.json b/apps/dashboard/openapi.json index 21021be9df2..495479ae837 100644 --- a/apps/dashboard/openapi.json +++ b/apps/dashboard/openapi.json @@ -448,12 +448,15 @@ ], "parameters": [ { - "name": "layout", + "name": "layout[]", "in": "query", "description": "The new layout", "required": true, "schema": { - "type": "string" + "type": "array", + "items": { + "type": "string" + } } }, { @@ -495,7 +498,10 @@ ], "properties": { "layout": { - "type": "string" + "type": "array", + "items": { + "type": "string" + } } } } @@ -526,12 +532,15 @@ ], "parameters": [ { - "name": "statuses", + "name": "statuses[]", "in": "query", "description": "The new statuses", "required": true, "schema": { - "type": "string" + "type": "array", + "items": { + "type": "string" + } } }, { @@ -573,7 +582,10 @@ ], "properties": { "statuses": { - "type": "string" + "type": "array", + "items": { + "type": "string" + } } } } diff --git a/apps/dashboard/src/DashboardApp.vue b/apps/dashboard/src/DashboardApp.vue index c7143335078..b3dd3d285be 100644 --- a/apps/dashboard/src/DashboardApp.vue +++ b/apps/dashboard/src/DashboardApp.vue @@ -229,7 +229,7 @@ export default { return (panel) => this.layout.indexOf(panel.id) > -1 }, isStatusActive() { - return (status) => !(status in this.enabledStatuses) || this.enabledStatuses[status] + return (status) => this.enabledStatuses.findIndex((s) => s === status) !== -1 }, sortedAllStatuses() { @@ -350,12 +350,12 @@ export default { }, saveLayout() { axios.post(generateOcsUrl('/apps/dashboard/api/v3/layout'), { - layout: this.layout.join(','), + layout: this.layout, }) }, saveStatuses() { axios.post(generateOcsUrl('/apps/dashboard/api/v3/statuses'), { - statuses: JSON.stringify(this.enabledStatuses), + statuses: this.enabledStatuses, }) }, showModal() { @@ -395,15 +395,18 @@ export default { } }, enableStatus(app) { - this.enabledStatuses[app] = true + this.enabledStatuses.push(app) this.registerStatus(app, this.allCallbacksStatus[app]) this.saveStatuses() }, disableStatus(app) { - this.enabledStatuses[app] = false - const i = this.registeredStatus.findIndex((s) => s === app) + const i = this.enabledStatuses.findIndex((s) => s === app) if (i !== -1) { - this.registeredStatus.splice(i, 1) + this.enabledStatuses.splice(i, 1) + } + const j = this.registeredStatus.findIndex((s) => s === app) + if (j !== -1) { + this.registeredStatus.splice(j, 1) Vue.set(this.statuses, app, { mounted: false }) this.$nextTick(() => { Vue.delete(this.callbacksStatus, app) |