Signed-off-by: Robin Appelman <robin@icewind.nl>tags/v25.0.0beta7
@@ -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); |
@@ -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', |
@@ -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', |
@@ -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; | |||
} |