aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/Dashboard/Model
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public/Dashboard/Model')
-rw-r--r--lib/public/Dashboard/Model/WidgetButton.php77
-rw-r--r--lib/public/Dashboard/Model/WidgetItem.php156
-rw-r--r--lib/public/Dashboard/Model/WidgetItems.php81
-rw-r--r--lib/public/Dashboard/Model/WidgetOptions.php46
4 files changed, 360 insertions, 0 deletions
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;
+ }
+}