summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-08-23 15:03:41 +0200
committerJulien Veyssier <eneiluj@posteo.net>2022-09-15 18:05:52 +0200
commit0e5944748df24fde54e34cb1fcc0f15fb0d734de (patch)
tree1db9950f0d21c4757947b6cb0ab1a920767b943c
parentca747b91d4aa907b191119f080d213bfb5e60fd2 (diff)
downloadnextcloud-server-0e5944748df24fde54e34cb1fcc0f15fb0d734de.tar.gz
nextcloud-server-0e5944748df24fde54e34cb1fcc0f15fb0d734de.zip
add dashboard api to list widgets
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--apps/dashboard/appinfo/routes.php1
-rw-r--r--apps/dashboard/lib/Controller/DashboardApiController.php26
-rw-r--r--lib/public/Dashboard/IIconWidget.php37
3 files changed, 64 insertions, 0 deletions
diff --git a/apps/dashboard/appinfo/routes.php b/apps/dashboard/appinfo/routes.php
index 2d930b2240d..c6891837384 100644
--- a/apps/dashboard/appinfo/routes.php
+++ b/apps/dashboard/appinfo/routes.php
@@ -31,6 +31,7 @@ return [
['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'],
]
];
diff --git a/apps/dashboard/lib/Controller/DashboardApiController.php b/apps/dashboard/lib/Controller/DashboardApiController.php
index bb329888b09..2e80659a2fd 100644
--- a/apps/dashboard/lib/Controller/DashboardApiController.php
+++ b/apps/dashboard/lib/Controller/DashboardApiController.php
@@ -28,7 +28,9 @@ namespace OCA\Dashboard\Controller;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Http\DataResponse;
+use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\IManager;
+use OCP\Dashboard\IWidget;
use OCP\IConfig;
use OCP\IRequest;
@@ -83,4 +85,28 @@ class DashboardApiController extends OCSController {
return new DataResponse($items);
}
+
+ /**
+ * Example request with Curl:
+ * curl -u user:passwd http://my.nc/ocs/v2.php/apps/dashboard/api/v1/widgets
+ *
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ */
+ public function getWidgets(): DataResponse {
+ $widgets = $this->dashboardManager->getWidgets();
+
+ $items = array_map(function(IWidget $widget) {
+ return [
+ 'id' => $widget->getId(),
+ 'title' => $widget->getTitle(),
+ 'order' => $widget->getOrder(),
+ 'icon_class' => $widget->getIconClass(),
+ 'icon_url' => ($widget instanceof IIconWidget) ? $widget->getIconUrl() : '',
+ 'url' => $widget->getUrl(),
+ ];
+ }, $widgets);
+
+ return new DataResponse($items);
+ }
}
diff --git a/lib/public/Dashboard/IIconWidget.php b/lib/public/Dashboard/IIconWidget.php
new file mode 100644
index 00000000000..b9928d5a6b3
--- /dev/null
+++ b/lib/public/Dashboard/IIconWidget.php
@@ -0,0 +1,37 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCP\Dashboard;
+
+/**
+ * Allow getting the absolute icon url for a widget
+ *
+ * @since 25.0.0
+ */
+interface IIconWidget extends IWidget {
+ /**
+ * Get the absolute url for the widget icon
+ *
+ * @return string
+ */
+ public function getIconUrl(): string;
+}