aboutsummaryrefslogtreecommitdiffstats
path: root/apps
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 /apps
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>
Diffstat (limited to 'apps')
-rw-r--r--apps/dashboard/lib/Controller/DashboardApiController.php29
1 files changed, 21 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);