Skip to content

Commit

Permalink
refactor(dashboard): Migrate saving layout and statuses to OCS
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Feb 20, 2024
1 parent 0805a45 commit 95290bb
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 28 deletions.
4 changes: 2 additions & 2 deletions apps/dashboard/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
return [
'routes' => [
['name' => 'dashboard#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'dashboard#updateLayout', 'url' => '/layout', 'verb' => 'POST'],
['name' => 'dashboard#updateStatuses', 'url' => '/statuses', 'verb' => 'POST'],
],
'ocs' => [
['name' => 'dashboardApi#getWidgets', 'url' => '/api/v1/widgets', 'verb' => 'GET'],
['name' => 'dashboardApi#getWidgetItems', 'url' => '/api/v1/widget-items', 'verb' => 'GET'],
['name' => 'dashboardApi#getWidgetItemsV2', 'url' => '/api/v2/widget-items', 'verb' => 'GET'],
['name' => 'dashboardApi#updateLayout', 'url' => '/layout', 'verb' => 'POST'],
['name' => 'dashboardApi#updateStatuses', 'url' => '/statuses', 'verb' => 'POST'],
]
];
28 changes: 28 additions & 0 deletions apps/dashboard/lib/Controller/DashboardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,32 @@ public function getWidgets(): DataResponse {

return new DataResponse($items);
}

/**
* Update the layout
*
* @NoAdminRequired
* @param string $layout The new layout
* @return DataResponse<Http::STATUS_OK, array{layout: string}, array{}>
*
* 200: Statuses updated successfully
*/
public function updateLayout(string $layout): DataResponse {
$this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout);
return new DataResponse(['layout' => $layout]);
}

/**
* Update the statuses
*
* @NoAdminRequired
* @param string $statuses The new statuses
* @return DataResponse<Http::STATUS_OK, array{statuses: string}, array{}>
*
* 200: Statuses updated successfully
*/
public function updateStatuses(string $statuses): DataResponse {
$this->config->setUserValue($this->userId, 'dashboard', 'statuses', $statuses);
return new DataResponse(['statuses' => $statuses]);
}
}
21 changes: 0 additions & 21 deletions apps/dashboard/lib/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Dashboard\IManager;
Expand Down Expand Up @@ -123,24 +122,4 @@ public function index(): TemplateResponse {

return $response;
}

/**
* @NoAdminRequired
* @param string $layout
* @return JSONResponse
*/
public function updateLayout(string $layout): JSONResponse {
$this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout);
return new JSONResponse(['layout' => $layout]);
}

/**
* @NoAdminRequired
* @param string $statuses
* @return JSONResponse
*/
public function updateStatuses(string $statuses): JSONResponse {
$this->config->setUserValue($this->userId, 'dashboard', 'statuses', $statuses);
return new JSONResponse(['statuses' => $statuses]);
}
}
156 changes: 156 additions & 0 deletions apps/dashboard/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,162 @@
}
}
}
},
"/ocs/v2.php/apps/dashboard/layout": {
"post": {
"operationId": "dashboard_api-update-layout",
"summary": "Update the layout",
"tags": [
"dashboard_api"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "layout",
"in": "query",
"description": "The new layout",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "Statuses updated successfully",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"layout"
],
"properties": {
"layout": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/apps/dashboard/statuses": {
"post": {
"operationId": "dashboard_api-update-statuses",
"summary": "Update the statuses",
"tags": [
"dashboard_api"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "statuses",
"in": "query",
"description": "The new statuses",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "Statuses updated successfully",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"statuses"
],
"properties": {
"statuses": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"tags": []
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/DashboardApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ export default {
}
},
saveLayout() {
axios.post(generateUrl('/apps/dashboard/layout'), {
axios.post(generateOcsUrl('/apps/dashboard/layout'), {
layout: this.layout.join(','),
})
},
saveStatuses() {
axios.post(generateUrl('/apps/dashboard/statuses'), {
axios.post(generateOcsUrl('/apps/dashboard/statuses'), {
statuses: JSON.stringify(this.enabledStatuses),
})
},
Expand Down
4 changes: 2 additions & 2 deletions dist/dashboard-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dashboard-main.js.map

Large diffs are not rendered by default.

0 comments on commit 95290bb

Please sign in to comment.