diff --git a/apps/dashboard/appinfo/routes.php b/apps/dashboard/appinfo/routes.php index 2d930b2240d3d..c6891837384c6 100644 --- a/apps/dashboard/appinfo/routes.php +++ b/apps/dashboard/appinfo/routes.php @@ -31,6 +31,7 @@ ['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 bb329888b0975..1062cf1bdba02 100644 --- a/apps/dashboard/lib/Controller/DashboardApiController.php +++ b/apps/dashboard/lib/Controller/DashboardApiController.php @@ -28,7 +28,13 @@ use OCP\AppFramework\OCSController; use OCP\AppFramework\Http\DataResponse; +use OCP\Dashboard\IButtonWidget; +use OCP\Dashboard\IIconWidget; +use OCP\Dashboard\IOptionWidget; use OCP\Dashboard\IManager; +use OCP\Dashboard\IWidget; +use OCP\Dashboard\Model\WidgetButton; +use OCP\Dashboard\Model\WidgetOptions; use OCP\IConfig; use OCP\IRequest; @@ -44,11 +50,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; @@ -62,19 +70,23 @@ public function __construct(string $appName, * * @param array $sinceIds Array indexed by widget Ids, contains date/id from which we want the new items * @param int $limit Limit number of result items per widget + * @param string[] $widgets Limit results to specific widgets * * @NoAdminRequired * @NoCSRFRequired */ - public function getWidgetItems(array $sinceIds = [], int $limit = 7): DataResponse { + public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse { + $showWidgets = $widgets; $items = []; - $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar'); - $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)); + if (empty($showWidgets)) { + $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar'); + $showWidgets = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)); + } $widgets = $this->dashboardManager->getWidgets(); foreach ($widgets as $widget) { - if ($widget instanceof IAPIWidget && in_array($widget->getId(), $userLayout)) { + if ($widget instanceof IAPIWidget && in_array($widget->getId(), $showWidgets)) { $items[$widget->getId()] = array_map(function (WidgetItem $item) { return $item->jsonSerialize(); }, $widget->getItems($this->userId, $sinceIds[$widget->getId()] ?? null, $limit)); @@ -83,4 +95,42 @@ public function getWidgetItems(array $sinceIds = [], int $limit = 7): DataRespon 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) { + $options = ($widget instanceof IOptionWidget) ? $widget->getWidgetOptions() : WidgetOptions::getDefault(); + $data = [ + 'id' => $widget->getId(), + 'title' => $widget->getTitle(), + 'order' => $widget->getOrder(), + 'icon_class' => $widget->getIconClass(), + 'icon_url' => ($widget instanceof IIconWidget) ? $widget->getIconUrl() : '', + 'widget_url' => $widget->getUrl(), + 'item_icons_round' => $options->withRoundItemIcons(), + ]; + if ($widget instanceof IButtonWidget) { + $data += [ + 'buttons' => array_map(function (WidgetButton $button) { + return [ + 'type' => $button->getType(), + 'text' => $button->getText(), + 'link' => $button->getLink(), + ]; + }, $widget->getWidgetButtons($this->userId)), + ]; + } + return $data; + }, $widgets); + + return new DataResponse($items); + } } diff --git a/apps/user_status/lib/Dashboard/UserStatusWidget.php b/apps/user_status/lib/Dashboard/UserStatusWidget.php index 10411dc7f9daf..5a89040dfa587 100644 --- a/apps/user_status/lib/Dashboard/UserStatusWidget.php +++ b/apps/user_status/lib/Dashboard/UserStatusWidget.php @@ -28,50 +28,56 @@ use OCA\UserStatus\AppInfo\Application; use OCA\UserStatus\Db\UserStatus; use OCA\UserStatus\Service\StatusService; -use OCP\Dashboard\IWidget; -use OCP\IInitialStateService; +use OCP\AppFramework\Services\IInitialState; +use OCP\Dashboard\IAPIWidget; +use OCP\Dashboard\IButtonWidget; +use OCP\Dashboard\IIconWidget; +use OCP\Dashboard\IOptionWidget; +use OCP\Dashboard\Model\WidgetItem; +use OCP\Dashboard\Model\WidgetOptions; +use OCP\IDateTimeFormatter; use OCP\IL10N; +use OCP\IURLGenerator; use OCP\IUserManager; use OCP\IUserSession; use OCP\UserStatus\IUserStatus; +use OCP\Util; /** * Class UserStatusWidget * * @package OCA\UserStatus */ -class UserStatusWidget implements IWidget { - - /** @var IL10N */ - private $l10n; - - /** @var IInitialStateService */ - private $initialStateService; - - /** @var IUserManager */ - private $userManager; - - /** @var IUserSession */ - private $userSession; - - /** @var StatusService */ - private $service; +class UserStatusWidget implements IAPIWidget, IIconWidget, IOptionWidget { + private IL10N $l10n; + private IDateTimeFormatter $dateTimeFormatter; + private IURLGenerator $urlGenerator; + private IInitialState $initialStateService; + private IUserManager $userManager; + private IUserSession $userSession; + private StatusService $service; /** * UserStatusWidget constructor * * @param IL10N $l10n - * @param IInitialStateService $initialStateService + * @param IDateTimeFormatter $dateTimeFormatter + * @param IURLGenerator $urlGenerator + * @param IInitialState $initialStateService * @param IUserManager $userManager * @param IUserSession $userSession * @param StatusService $service */ public function __construct(IL10N $l10n, - IInitialStateService $initialStateService, + IDateTimeFormatter $dateTimeFormatter, + IURLGenerator $urlGenerator, + IInitialState $initialStateService, IUserManager $userManager, IUserSession $userSession, StatusService $service) { $this->l10n = $l10n; + $this->dateTimeFormatter = $dateTimeFormatter; + $this->urlGenerator = $urlGenerator; $this->initialStateService = $initialStateService; $this->userManager = $userManager; $this->userSession = $userSession; @@ -106,6 +112,15 @@ public function getIconClass(): string { return 'icon-user-status'; } + /** + * @inheritDoc + */ + public function getIconUrl(): string { + return $this->urlGenerator->getAbsoluteURL( + $this->urlGenerator->imagePath(Application::APP_ID, 'app.svg') + ); + } + /** * @inheritDoc */ @@ -117,28 +132,33 @@ public function getUrl(): ?string { * @inheritDoc */ public function load(): void { - \OCP\Util::addScript(Application::APP_ID, 'dashboard'); + Util::addScript(Application::APP_ID, 'dashboard'); $currentUser = $this->userSession->getUser(); if ($currentUser === null) { - $this->initialStateService->provideInitialState(Application::APP_ID, 'dashboard_data', []); + $this->initialStateService->provideInitialState('dashboard_data', []); return; } $currentUserId = $currentUser->getUID(); + $widgetItemsData = $this->getWidgetData($currentUserId); + $this->initialStateService->provideInitialState('dashboard_data', $widgetItemsData); + } + + private function getWidgetData(string $userId, ?string $since = null, int $limit = 7): array { // Fetch status updates and filter current user $recentStatusUpdates = array_slice( array_filter( - $this->service->findAllRecentStatusChanges(8, 0), - static function (UserStatus $status) use ($currentUserId): bool { - return $status->getUserId() !== $currentUserId; + $this->service->findAllRecentStatusChanges($limit + 1, 0), + static function (UserStatus $status) use ($userId, $since): bool { + return $status->getUserId() !== $userId + && ($since === null || $status->getStatusTimestamp() > (int) $since); } ), 0, - 7 + $limit ); - - $this->initialStateService->provideInitialState(Application::APP_ID, 'dashboard_data', array_map(function (UserStatus $status): array { + return array_map(function (UserStatus $status): array { $user = $this->userManager->get($status->getUserId()); $displayName = $status->getUserId(); if ($user !== null) { @@ -155,6 +175,33 @@ static function (UserStatus $status) use ($currentUserId): bool { 'message' => $status->getCustomMessage(), 'timestamp' => $status->getStatusTimestamp(), ]; - }, $recentStatusUpdates)); + }, $recentStatusUpdates); + } + + /** + * @inheritDoc + */ + public function getItems(string $userId, ?string $since = null, int $limit = 7): array { + $widgetItemsData = $this->getWidgetData($userId, $since, $limit); + + return array_map(function(array $widgetData) { + $formattedDate = $this->dateTimeFormatter->formatTimeSpan($widgetData['timestamp']); + return new WidgetItem( + $widgetData['displayName'], + $widgetData['icon'] . ($widgetData['icon'] ? ' ' : '') . $widgetData['message'] . ', ' . $formattedDate, + // https://nextcloud.local/index.php/u/julien + $this->urlGenerator->getAbsoluteURL( + $this->urlGenerator->linkToRoute('core.ProfilePage.index', ['targetUserId' => $widgetData['userId']]) + ), + $this->urlGenerator->getAbsoluteURL( + $this->urlGenerator->linkToRoute('core.avatar.getAvatar', ['userId' => $widgetData['userId'], 'size' => 44]) + ), + (string) $widgetData['timestamp'] + ); + }, $widgetItemsData); + } + + public function getWidgetOptions(): WidgetOptions { + return new WidgetOptions(true); } } diff --git a/apps/user_status/tests/Unit/Dashboard/UserStatusWidgetTest.php b/apps/user_status/tests/Unit/Dashboard/UserStatusWidgetTest.php index d23b2bc02ff2f..ab7252370ce10 100644 --- a/apps/user_status/tests/Unit/Dashboard/UserStatusWidgetTest.php +++ b/apps/user_status/tests/Unit/Dashboard/UserStatusWidgetTest.php @@ -29,8 +29,10 @@ use OCA\UserStatus\Dashboard\UserStatusWidget; use OCA\UserStatus\Db\UserStatus; use OCA\UserStatus\Service\StatusService; -use OCP\IInitialStateService; +use OCP\AppFramework\Services\IInitialState; +use OCP\IDateTimeFormatter; use OCP\IL10N; +use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; @@ -41,7 +43,13 @@ class UserStatusWidgetTest extends TestCase { /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ private $l10n; - /** @var IInitialStateService|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */ + private $dateTimeFormatter; + + /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ + private $urlGenerator; + + /** @var IInitialState|\PHPUnit\Framework\MockObject\MockObject */ private $initialState; /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ @@ -60,12 +68,14 @@ protected function setUp(): void { parent::setUp(); $this->l10n = $this->createMock(IL10N::class); - $this->initialState = $this->createMock(IInitialStateService::class); + $this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->initialState = $this->createMock(IInitialState::class); $this->userManager = $this->createMock(IUserManager::class); $this->userSession = $this->createMock(IUserSession::class); $this->service = $this->createMock(StatusService::class); - $this->widget = new UserStatusWidget($this->l10n, $this->initialState, $this->userManager, $this->userSession, $this->service); + $this->widget = new UserStatusWidget($this->l10n, $this->dateTimeFormatter, $this->urlGenerator, $this->initialState, $this->userManager, $this->userSession, $this->service); } public function testGetId(): void { @@ -99,7 +109,7 @@ public function testLoadNoUserSession(): void { $this->initialState->expects($this->once()) ->method('provideInitialState') - ->with('user_status', 'dashboard_data', []); + ->with('dashboard_data', []); $this->service->expects($this->never()) ->method('findAllRecentStatusChanges'); @@ -195,7 +205,7 @@ public function testLoadWithCurrentUser(): void { $this->initialState->expects($this->once()) ->method('provideInitialState') - ->with('user_status', 'dashboard_data', $this->callback(function ($data): bool { + ->with('dashboard_data', $this->callback(function ($data): bool { $this->assertEquals([ [ 'userId' => 'user_1', diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index a0a0db6327c04..40a5efea3478c 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -192,13 +192,18 @@ '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\\IOptionWidget' => $baseDir . '/lib/public/Dashboard/IOptionWidget.php', 'OCP\\Dashboard\\IWidget' => $baseDir . '/lib/public/Dashboard/IWidget.php', 'OCP\\Dashboard\\Model\\IWidgetConfig' => $baseDir . '/lib/public/Dashboard/Model/IWidgetConfig.php', 'OCP\\Dashboard\\Model\\IWidgetRequest' => $baseDir . '/lib/public/Dashboard/Model/IWidgetRequest.php', + 'OCP\\Dashboard\\Model\\WidgetButton' => $baseDir . '/lib/public/Dashboard/Model/WidgetButton.php', 'OCP\\Dashboard\\Model\\WidgetItem' => $baseDir . '/lib/public/Dashboard/Model/WidgetItem.php', + 'OCP\\Dashboard\\Model\\WidgetOptions' => $baseDir . '/lib/public/Dashboard/Model/WidgetOptions.php', 'OCP\\Dashboard\\Model\\WidgetSetting' => $baseDir . '/lib/public/Dashboard/Model/WidgetSetting.php', 'OCP\\Dashboard\\Model\\WidgetSetup' => $baseDir . '/lib/public/Dashboard/Model/WidgetSetup.php', 'OCP\\Dashboard\\Model\\WidgetTemplate' => $baseDir . '/lib/public/Dashboard/Model/WidgetTemplate.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 2e71b16807f74..50a2406a8d105 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -225,13 +225,18 @@ 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\\IOptionWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IOptionWidget.php', 'OCP\\Dashboard\\IWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IWidget.php', 'OCP\\Dashboard\\Model\\IWidgetConfig' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/IWidgetConfig.php', 'OCP\\Dashboard\\Model\\IWidgetRequest' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/IWidgetRequest.php', + 'OCP\\Dashboard\\Model\\WidgetButton' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetButton.php', 'OCP\\Dashboard\\Model\\WidgetItem' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetItem.php', + 'OCP\\Dashboard\\Model\\WidgetOptions' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetOptions.php', 'OCP\\Dashboard\\Model\\WidgetSetting' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetSetting.php', 'OCP\\Dashboard\\Model\\WidgetSetup' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetSetup.php', 'OCP\\Dashboard\\Model\\WidgetTemplate' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetTemplate.php', diff --git a/lib/public/Dashboard/IButtonWidget.php b/lib/public/Dashboard/IButtonWidget.php new file mode 100644 index 0000000000000..5745c368c9622 --- /dev/null +++ b/lib/public/Dashboard/IButtonWidget.php @@ -0,0 +1,41 @@ + + * + * @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 . + * + */ +namespace OCP\Dashboard; + +use OCP\Dashboard\Model\WidgetButton; + +/** + * Adds a button to the dashboard api representation + * + * @since 25.0.0 + */ +interface IButtonWidget extends IWidget { + /** + * Get the buttons to show on the widget + * + * @param string $userId + * @return WidgetButton[] + * @since 25.0.0 + */ + public function getWidgetButtons(string $userId): array; +} diff --git a/lib/public/Dashboard/IIconWidget.php b/lib/public/Dashboard/IIconWidget.php new file mode 100644 index 0000000000000..3f5cf5fb050aa --- /dev/null +++ b/lib/public/Dashboard/IIconWidget.php @@ -0,0 +1,38 @@ + + * + * @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 . + * + */ +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 + * @since 25.0.0 + */ + public function getIconUrl(): string; +} diff --git a/lib/public/Dashboard/IOptionWidget.php b/lib/public/Dashboard/IOptionWidget.php new file mode 100644 index 0000000000000..8d5146c524843 --- /dev/null +++ b/lib/public/Dashboard/IOptionWidget.php @@ -0,0 +1,38 @@ + + * + * @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 . + * + */ +namespace OCP\Dashboard; + +use OCP\Dashboard\Model\WidgetOptions; + +/** + * Allow getting widget options + * + * @since 25.0.0 + */ +interface IOptionWidget extends IWidget { + /** + * Get additional options for the widget + * @since 25.0.0 + */ + public function getWidgetOptions(): WidgetOptions; +} diff --git a/lib/public/Dashboard/Model/WidgetButton.php b/lib/public/Dashboard/Model/WidgetButton.php new file mode 100644 index 0000000000000..480249b539fde --- /dev/null +++ b/lib/public/Dashboard/Model/WidgetButton.php @@ -0,0 +1,81 @@ + + * + * @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 . + * + */ + +namespace OCP\Dashboard\Model; + +/** + * Button for a dashboard widget + * + * @since 25.0.0 + */ +class WidgetButton { + public const TYPE_NEW = 'new'; + public const TYPE_MORE = 'more'; + public const TYPE_SETUP = 'setup'; + + private string $type; + private string $link; + private string $text; + + /** + * @param string $type + * @param string $link + * @param string $text + * @since 25.0.0 + */ + public function __construct(string $type, string $link, string $text) { + $this->type = $type; + $this->link = $link; + $this->text = $text; + } + + /** + * Get the button type, either "new", "more" or "setup" + * + * @return string + * @since 25.0.0 + */ + public function getType(): string { + return $this->type; + } + + /** + * Get the absolute url the buttons links to + * + * @return string + * @since 25.0.0 + */ + public function getLink(): string { + return $this->link; + } + + /** + * Get the translated text for the button + * + * @return string + * @since 25.0.0 + */ + public function getText(): string { + return $this->text; + } +} diff --git a/lib/public/Dashboard/Model/WidgetOptions.php b/lib/public/Dashboard/Model/WidgetOptions.php new file mode 100644 index 0000000000000..44efdbda45730 --- /dev/null +++ b/lib/public/Dashboard/Model/WidgetOptions.php @@ -0,0 +1,61 @@ + + * + * @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 . + * + */ + +namespace OCP\Dashboard\Model; + +/** + * Option for displaying a widget + * + * @since 25.0.0 + */ +class WidgetOptions { + private bool $roundItemIcons; + + /** + * @param bool $roundItemIcons + * @since 25.0.0 + */ + public function __construct(bool $roundItemIcons) { + $this->roundItemIcons = $roundItemIcons; + } + + /** + * Get the default set of options + * + * @return WidgetOptions + * @since 25.0.0 + */ + public static function getDefault(): WidgetOptions { + return new WidgetOptions(false); + } + + /** + * Whether the clients should render icons for widget items as round icons + * + * @return bool + * @since 25.0.0 + */ + public function withRoundItemIcons(): bool { + return $this->roundItemIcons; + } +}