diff options
Diffstat (limited to 'lib/public/Dashboard')
-rw-r--r-- | lib/public/Dashboard/IAPIWidget.php | 25 | ||||
-rw-r--r-- | lib/public/Dashboard/IAPIWidgetV2.php | 24 | ||||
-rw-r--r-- | lib/public/Dashboard/IButtonWidget.php | 26 | ||||
-rw-r--r-- | lib/public/Dashboard/IConditionalWidget.php | 26 | ||||
-rw-r--r-- | lib/public/Dashboard/IIconWidget.php | 25 | ||||
-rw-r--r-- | lib/public/Dashboard/IManager.php | 29 | ||||
-rw-r--r-- | lib/public/Dashboard/IOptionWidget.php | 23 | ||||
-rw-r--r-- | lib/public/Dashboard/IReloadableWidget.php | 22 | ||||
-rw-r--r-- | lib/public/Dashboard/IWidget.php | 64 | ||||
-rw-r--r-- | lib/public/Dashboard/Model/WidgetButton.php | 77 | ||||
-rw-r--r-- | lib/public/Dashboard/Model/WidgetItem.php | 156 | ||||
-rw-r--r-- | lib/public/Dashboard/Model/WidgetItems.php | 81 | ||||
-rw-r--r-- | lib/public/Dashboard/Model/WidgetOptions.php | 46 |
13 files changed, 624 insertions, 0 deletions
diff --git a/lib/public/Dashboard/IAPIWidget.php b/lib/public/Dashboard/IAPIWidget.php new file mode 100644 index 00000000000..c8f98290a0e --- /dev/null +++ b/lib/public/Dashboard/IAPIWidget.php @@ -0,0 +1,25 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Dashboard; + +use OCP\Dashboard\Model\WidgetItem; + +/** + * interface IAPIWidget + * + * @since 22.0.0 + */ +interface IAPIWidget extends IWidget { + /** + * @return list<WidgetItem> The widget items + * @since 22.0.0 + */ + public function getItems(string $userId, ?string $since = null, int $limit = 7): array; +} diff --git a/lib/public/Dashboard/IAPIWidgetV2.php b/lib/public/Dashboard/IAPIWidgetV2.php new file mode 100644 index 00000000000..3acd675202d --- /dev/null +++ b/lib/public/Dashboard/IAPIWidgetV2.php @@ -0,0 +1,24 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Dashboard; + +use OCP\Dashboard\Model\WidgetItems; + +/** + * Interface IAPIWidgetV2 + * + * @since 27.1.0 + */ +interface IAPIWidgetV2 extends IWidget { + /** + * Items to render in the widget + * + * @since 27.1.0 + */ + public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems; +} diff --git a/lib/public/Dashboard/IButtonWidget.php b/lib/public/Dashboard/IButtonWidget.php new file mode 100644 index 00000000000..f4ebd9253c7 --- /dev/null +++ b/lib/public/Dashboard/IButtonWidget.php @@ -0,0 +1,26 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +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 list<WidgetButton> + * @since 25.0.0 + */ + public function getWidgetButtons(string $userId): array; +} diff --git a/lib/public/Dashboard/IConditionalWidget.php b/lib/public/Dashboard/IConditionalWidget.php new file mode 100644 index 00000000000..5c1445bbca8 --- /dev/null +++ b/lib/public/Dashboard/IConditionalWidget.php @@ -0,0 +1,26 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Dashboard; + +/** + * interface IConditionalWidget + * + * Allows an app to lazy-register a widget and in the lazy part of the code + * it can decide if the widget should really be registered. + * + * @since 26.0.0 + */ +interface IConditionalWidget extends IWidget { + /** + * @return bool Whether the widget is enabled and should be registered + * @since 26.0.0 + */ + public function isEnabled(): bool; +} diff --git a/lib/public/Dashboard/IIconWidget.php b/lib/public/Dashboard/IIconWidget.php new file mode 100644 index 00000000000..203a89279b0 --- /dev/null +++ b/lib/public/Dashboard/IIconWidget.php @@ -0,0 +1,25 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +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 (should be colored black or not have a color) + * + * The icon will be inverted automatically in mobile clients and when using dark mode + * + * @return string + * @since 25.0.0 + */ + public function getIconUrl(): string; +} diff --git a/lib/public/Dashboard/IManager.php b/lib/public/Dashboard/IManager.php new file mode 100644 index 00000000000..e69bf78225e --- /dev/null +++ b/lib/public/Dashboard/IManager.php @@ -0,0 +1,29 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Dashboard; + +/** + * Interface IManager + * + * @since 20.0.0 + */ +interface IManager { + /** + * @param string $widgetClass + * @since 20.0.0 + */ + public function lazyRegisterWidget(string $widgetClass, string $appId): void; + + /** + * @since 20.0.0 + * + * @return array<string, IWidget> + */ + public function getWidgets(): array; +} diff --git a/lib/public/Dashboard/IOptionWidget.php b/lib/public/Dashboard/IOptionWidget.php new file mode 100644 index 00000000000..3f4cd4dcd2e --- /dev/null +++ b/lib/public/Dashboard/IOptionWidget.php @@ -0,0 +1,23 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +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/IReloadableWidget.php b/lib/public/Dashboard/IReloadableWidget.php new file mode 100644 index 00000000000..80f0181a33c --- /dev/null +++ b/lib/public/Dashboard/IReloadableWidget.php @@ -0,0 +1,22 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Dashboard; + +/** + * Allow {@see IAPIWidgetV2} to reload their items + * + * @since 27.1.0 + */ +interface IReloadableWidget extends IAPIWidgetV2 { + /** + * Periodic interval in seconds in which to reload the widget's items + * + * @since 27.1.0 + */ + public function getReloadInterval(): int; +} diff --git a/lib/public/Dashboard/IWidget.php b/lib/public/Dashboard/IWidget.php new file mode 100644 index 00000000000..c6bac98cae2 --- /dev/null +++ b/lib/public/Dashboard/IWidget.php @@ -0,0 +1,64 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Dashboard; + +/** + * Interface IWidget + * + * @since 20.0.0 + */ +interface IWidget { + /** + * Get a unique identifier for the widget + * + * To ensure uniqueness, it is recommended to user the app id or start with the + * app id followed by a dash. + * + * @return string Unique id that identifies the widget, e.g. the app id. Only use alphanumeric characters, dash and underscore + * @since 20.0.0 + */ + public function getId(): string; + + /** + * @return string User facing title of the widget + * @since 20.0.0 + */ + public function getTitle(): string; + + /** + * @return int Initial order for widget sorting + * @since 20.0.0 + */ + public function getOrder(): int; + + /** + * CSS class that shows the widget icon (should be colored black or not have a color) + * + * The icon will be inverted automatically in mobile clients and when using dark mode. + * Therefore, it is NOT recommended to use a css class that sets the background with: + * `var(--icon-…)` as those will adapt to dark/bright mode in the web and still be inverted + * resulting in a dark icon on dark background. + * + * @return string css class that displays an icon next to the widget title + * @since 20.0.0 + */ + public function getIconClass(): string; + + /** + * @return string|null The absolute url to the apps own view + * @since 20.0.0 + */ + public function getUrl(): ?string; + + /** + * Execute widget bootstrap code like loading scripts and providing initial state + * @since 20.0.0 + */ + public function load(): void; +} diff --git a/lib/public/Dashboard/Model/WidgetButton.php b/lib/public/Dashboard/Model/WidgetButton.php new file mode 100644 index 00000000000..1c9ea6266a9 --- /dev/null +++ b/lib/public/Dashboard/Model/WidgetButton.php @@ -0,0 +1,77 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Dashboard\Model; + +/** + * Button for a dashboard widget + * + * @since 25.0.0 + */ +class WidgetButton { + /** + * @since 25.0.0 + */ + public const TYPE_NEW = 'new'; + + /** + * @since 25.0.0 + */ + public const TYPE_MORE = 'more'; + + /** + * @since 25.0.0 + */ + 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/WidgetItem.php b/lib/public/Dashboard/Model/WidgetItem.php new file mode 100644 index 00000000000..680daf1b114 --- /dev/null +++ b/lib/public/Dashboard/Model/WidgetItem.php @@ -0,0 +1,156 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Dashboard\Model; + +use JsonSerializable; + +/** + * Interface WidgetItem + * + * This class is used by IAPIWidget interface. + * It represents an widget item data that can be provided to clients via the Dashboard API + * @see IAPIWidget::getItems + * + * @since 22.0.0 + * + */ +final class WidgetItem implements JsonSerializable { + /** @var string */ + private $title = ''; + + /** @var string */ + private $subtitle = ''; + + /** @var string */ + private $link = ''; + + /** @var string */ + private $iconUrl = ''; + + /** @var string + * Timestamp or ID used by the dashboard API to avoid getting already retrieved items + */ + private $sinceId = ''; + + /** + * Overlay icon to show in the bottom right corner of {@see $iconUrl} + * + * @since 27.1.0 + */ + private string $overlayIconUrl = ''; + + /** + * WidgetItem constructor + * + * @since 22.0.0 + */ + public function __construct(string $title = '', + string $subtitle = '', + string $link = '', + string $iconUrl = '', + string $sinceId = '', + string $overlayIconUrl = '') { + $this->title = $title; + $this->subtitle = $subtitle; + $this->iconUrl = $iconUrl; + $this->link = $link; + $this->sinceId = $sinceId; + $this->overlayIconUrl = $overlayIconUrl; + } + + /** + * Get the item title + * + * @since 22.0.0 + * + * @return string + */ + public function getTitle(): string { + return $this->title; + } + + /** + * Get the item subtitle + * + * @since 22.0.0 + * + * @return string + */ + public function getSubtitle(): string { + return $this->subtitle; + } + + /** + * Get the item link + * + * @since 22.0.0 + * + * @return string + */ + public function getLink(): string { + return $this->link; + } + + /** + * Get the item icon URL + * The icon should be a square svg or a jpg/png of at least 44x44px + * + * @since 22.0.0 + * + * @return string + */ + public function getIconUrl(): string { + return $this->iconUrl; + } + + /** + * Get the item since ID + * + * @since 22.0.0 + * + * @return string + */ + public function getSinceId(): string { + return $this->sinceId; + } + + /** + * Get the overlay icon url + * + * @since 27.1.0 + * + * @return string + */ + public function getOverlayIconUrl(): string { + return $this->overlayIconUrl; + } + + /** + * @since 22.0.0 + * @return array{ + * subtitle: string, + * title: string, + * link: string, + * iconUrl: string, + * overlayIconUrl: string, + * sinceId: string, + * } + */ + public function jsonSerialize(): array { + return [ + 'subtitle' => $this->getSubtitle(), + 'title' => $this->getTitle(), + 'link' => $this->getLink(), + 'iconUrl' => $this->getIconUrl(), + 'overlayIconUrl' => $this->getOverlayIconUrl(), + 'sinceId' => $this->getSinceId(), + ]; + } +} diff --git a/lib/public/Dashboard/Model/WidgetItems.php b/lib/public/Dashboard/Model/WidgetItems.php new file mode 100644 index 00000000000..87491175964 --- /dev/null +++ b/lib/public/Dashboard/Model/WidgetItems.php @@ -0,0 +1,81 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Dashboard\Model; + +use JsonSerializable; +use OCP\Dashboard\IAPIWidgetV2; + +/** + * Interface WidgetItems + * + * This class is used by {@see IAPIWidgetV2} interface. + * It represents an array of widget items and additional context information that can be provided to clients via the Dashboard API + * + * @see IAPIWidgetV2::getItemsV2 + * + * @since 27.1.0 + */ +class WidgetItems implements JsonSerializable { + /** + * @param $items WidgetItem[] + * + * @since 27.1.0 + */ + public function __construct( + private array $items = [], + private string $emptyContentMessage = '', + private string $halfEmptyContentMessage = '', + ) { + } + + /** + * Items to render in the widgets + * + * @since 27.1.0 + * + * @return WidgetItem[] + */ + public function getItems(): array { + return $this->items; + } + + /** + * The "half" empty content message to show above the list of items. + * + * A non-empty string enables this feature. + * An empty string hides the message and disables this feature. + * + * @since 27.1.0 + */ + public function getEmptyContentMessage(): string { + return $this->emptyContentMessage; + } + + /** + * The empty content message to show in case of no items at all + * + * @since 27.1.0 + */ + public function getHalfEmptyContentMessage(): string { + return $this->halfEmptyContentMessage; + } + + /** + * @since 27.1.0 + */ + public function jsonSerialize(): array { + $items = array_map(static function (WidgetItem $item) { + return $item->jsonSerialize(); + }, $this->getItems()); + return [ + 'items' => $items, + 'emptyContentMessage' => $this->getEmptyContentMessage(), + 'halfEmptyContentMessage' => $this->getHalfEmptyContentMessage(), + ]; + } +} diff --git a/lib/public/Dashboard/Model/WidgetOptions.php b/lib/public/Dashboard/Model/WidgetOptions.php new file mode 100644 index 00000000000..7d0f567ca15 --- /dev/null +++ b/lib/public/Dashboard/Model/WidgetOptions.php @@ -0,0 +1,46 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +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; + } +} |