aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-08-29 16:12:43 +0200
committerJulien Veyssier <eneiluj@posteo.net>2022-09-15 18:05:52 +0200
commit79adca6b8b9b0be024899938f6e641c0379a14ed (patch)
tree7e8949b4fa2caf1cea6e958b438b9accfe3009f6
parent7f52a99ffbecd23c8a93284b97b1285411a5ddca (diff)
downloadnextcloud-server-79adca6b8b9b0be024899938f6e641c0379a14ed.tar.gz
nextcloud-server-79adca6b8b9b0be024899938f6e641c0379a14ed.zip
allow adding button to dashboard api output
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--apps/dashboard/lib/Controller/DashboardApiController.php29
-rw-r--r--lib/composer/composer/autoload_classmap.php2
-rw-r--r--lib/composer/composer/autoload_static.php2
-rw-r--r--lib/public/Dashboard/IButtonWidget.php51
4 files changed, 76 insertions, 8 deletions
diff --git a/apps/dashboard/lib/Controller/DashboardApiController.php b/apps/dashboard/lib/Controller/DashboardApiController.php
index 3a41c42cc9b..f27a5ea0252 100644
--- a/apps/dashboard/lib/Controller/DashboardApiController.php
+++ b/apps/dashboard/lib/Controller/DashboardApiController.php
@@ -28,6 +28,7 @@ namespace OCA\Dashboard\Controller;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Http\DataResponse;
+use OCP\Dashboard\IButtonWidget;
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IWidget;
@@ -46,11 +47,13 @@ class DashboardApiController extends OCSController {
/** @var string|null */
private $userId;
- public function __construct(string $appName,
- IRequest $request,
- IManager $dashboardManager,
- IConfig $config,
- ?string $userId) {
+ public function __construct(
+ string $appName,
+ IRequest $request,
+ IManager $dashboardManager,
+ IConfig $config,
+ ?string $userId
+ ) {
parent::__construct($appName, $request);
$this->dashboardManager = $dashboardManager;
@@ -100,15 +103,25 @@ class DashboardApiController extends OCSController {
public function getWidgets(): DataResponse {
$widgets = $this->dashboardManager->getWidgets();
- $items = array_map(function(IWidget $widget) {
- return [
+ $items = array_map(function (IWidget $widget) {
+ $data = [
'id' => $widget->getId(),
'title' => $widget->getTitle(),
'order' => $widget->getOrder(),
'icon_class' => $widget->getIconClass(),
'icon_url' => ($widget instanceof IIconWidget) ? $widget->getIconUrl() : '',
- 'url' => $widget->getUrl(),
+ 'widget_url' => $widget->getUrl(),
];
+ if ($widget instanceof IButtonWidget) {
+ $data += [
+ 'button' => [
+ 'text' => $widget->getButtonText(),
+ 'icon_url' => $widget->getButtonIconUrl(),
+ 'url' => $widget->getUrl(),
+ ],
+ ];
+ }
+ return $data;
}, $widgets);
return new DataResponse($items);
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index a0a0db6327c..16ca9b856c7 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -192,8 +192,10 @@ return array(
'OCP\\DB\\Types' => $baseDir . '/lib/public/DB/Types.php',
'OCP\\Dashboard\\Exceptions\\DashboardAppNotAvailableException' => $baseDir . '/lib/public/Dashboard/Exceptions/DashboardAppNotAvailableException.php',
'OCP\\Dashboard\\IAPIWidget' => $baseDir . '/lib/public/Dashboard/IAPIWidget.php',
+ 'OCP\\Dashboard\\IButtonWidget' => $baseDir . '/lib/public/Dashboard/IButtonWidget.php',
'OCP\\Dashboard\\IDashboardManager' => $baseDir . '/lib/public/Dashboard/IDashboardManager.php',
'OCP\\Dashboard\\IDashboardWidget' => $baseDir . '/lib/public/Dashboard/IDashboardWidget.php',
+ 'OCP\\Dashboard\\IIconWidget' => $baseDir . '/lib/public/Dashboard/IIconWidget.php',
'OCP\\Dashboard\\IManager' => $baseDir . '/lib/public/Dashboard/IManager.php',
'OCP\\Dashboard\\IWidget' => $baseDir . '/lib/public/Dashboard/IWidget.php',
'OCP\\Dashboard\\Model\\IWidgetConfig' => $baseDir . '/lib/public/Dashboard/Model/IWidgetConfig.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 2e71b16807f..a818d684c36 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -225,8 +225,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\DB\\Types' => __DIR__ . '/../../..' . '/lib/public/DB/Types.php',
'OCP\\Dashboard\\Exceptions\\DashboardAppNotAvailableException' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Exceptions/DashboardAppNotAvailableException.php',
'OCP\\Dashboard\\IAPIWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IAPIWidget.php',
+ 'OCP\\Dashboard\\IButtonWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IButtonWidget.php',
'OCP\\Dashboard\\IDashboardManager' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IDashboardManager.php',
'OCP\\Dashboard\\IDashboardWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IDashboardWidget.php',
+ 'OCP\\Dashboard\\IIconWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IIconWidget.php',
'OCP\\Dashboard\\IManager' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IManager.php',
'OCP\\Dashboard\\IWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IWidget.php',
'OCP\\Dashboard\\Model\\IWidgetConfig' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/IWidgetConfig.php',
diff --git a/lib/public/Dashboard/IButtonWidget.php b/lib/public/Dashboard/IButtonWidget.php
new file mode 100644
index 00000000000..cc0297fe7bc
--- /dev/null
+++ b/lib/public/Dashboard/IButtonWidget.php
@@ -0,0 +1,51 @@
+<?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;
+
+/**
+ * Adds a button to the dashboard api representation
+ *
+ * @since 25.0.0
+ */
+interface IButtonWidget extends IWidget {
+ /**
+ * Get the absolute url for the button target
+ *
+ * @return string
+ */
+ public function getButtonUrl(): string;
+
+ /**
+ * Get the absolute url for the button icon
+ *
+ * @return string
+ */
+ public function getButtonIconUrl(): ?string;
+
+ /**
+ * Get the text to show in the button
+ *
+ * @return string
+ */
+ public function getButtonText(): string;
+}