From 0e5944748df24fde54e34cb1fcc0f15fb0d734de Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 23 Aug 2022 15:03:41 +0200 Subject: [PATCH 01/12] add dashboard api to list widgets Signed-off-by: Robin Appelman --- apps/dashboard/appinfo/routes.php | 1 + .../lib/Controller/DashboardApiController.php | 26 +++++++++++++ lib/public/Dashboard/IIconWidget.php | 37 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 lib/public/Dashboard/IIconWidget.php 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..2e80659a2fdd5 100644 --- a/apps/dashboard/lib/Controller/DashboardApiController.php +++ b/apps/dashboard/lib/Controller/DashboardApiController.php @@ -28,7 +28,9 @@ use OCP\AppFramework\OCSController; use OCP\AppFramework\Http\DataResponse; +use OCP\Dashboard\IIconWidget; use OCP\Dashboard\IManager; +use OCP\Dashboard\IWidget; use OCP\IConfig; use OCP\IRequest; @@ -83,4 +85,28 @@ 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) { + return [ + 'id' => $widget->getId(), + 'title' => $widget->getTitle(), + 'order' => $widget->getOrder(), + 'icon_class' => $widget->getIconClass(), + 'icon_url' => ($widget instanceof IIconWidget) ? $widget->getIconUrl() : '', + 'url' => $widget->getUrl(), + ]; + }, $widgets); + + return new DataResponse($items); + } } diff --git a/lib/public/Dashboard/IIconWidget.php b/lib/public/Dashboard/IIconWidget.php new file mode 100644 index 0000000000000..b9928d5a6b375 --- /dev/null +++ b/lib/public/Dashboard/IIconWidget.php @@ -0,0 +1,37 @@ + + * + * @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 + */ + public function getIconUrl(): string; +} From 7f52a99ffbecd23c8a93284b97b1285411a5ddca Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 23 Aug 2022 15:04:13 +0200 Subject: [PATCH 02/12] allow filtering dashboard items api by widgets Signed-off-by: Robin Appelman --- .../lib/Controller/DashboardApiController.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/dashboard/lib/Controller/DashboardApiController.php b/apps/dashboard/lib/Controller/DashboardApiController.php index 2e80659a2fdd5..3a41c42cc9b0f 100644 --- a/apps/dashboard/lib/Controller/DashboardApiController.php +++ b/apps/dashboard/lib/Controller/DashboardApiController.php @@ -64,19 +64,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 ($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)); From 79adca6b8b9b0be024899938f6e641c0379a14ed Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 29 Aug 2022 16:12:43 +0200 Subject: [PATCH 03/12] allow adding button to dashboard api output Signed-off-by: Robin Appelman --- .../lib/Controller/DashboardApiController.php | 29 ++++++++--- lib/composer/composer/autoload_classmap.php | 2 + lib/composer/composer/autoload_static.php | 2 + lib/public/Dashboard/IButtonWidget.php | 51 +++++++++++++++++++ 4 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 lib/public/Dashboard/IButtonWidget.php diff --git a/apps/dashboard/lib/Controller/DashboardApiController.php b/apps/dashboard/lib/Controller/DashboardApiController.php index 3a41c42cc9b0f..f27a5ea025208 100644 --- a/apps/dashboard/lib/Controller/DashboardApiController.php +++ b/apps/dashboard/lib/Controller/DashboardApiController.php @@ -28,6 +28,7 @@ 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 @@ public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widg 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); diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index a0a0db6327c04..16ca9b856c7c1 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -192,8 +192,10 @@ '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', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 2e71b16807f74..a818d684c36cd 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.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', diff --git a/lib/public/Dashboard/IButtonWidget.php b/lib/public/Dashboard/IButtonWidget.php new file mode 100644 index 0000000000000..cc0297fe7bc7d --- /dev/null +++ b/lib/public/Dashboard/IButtonWidget.php @@ -0,0 +1,51 @@ + + * + * @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; + +/** + * 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; +} From a3912e264a26d5ab3d042e6b47e7c75d2b123ada Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 1 Sep 2022 17:12:43 +0200 Subject: [PATCH 04/12] change widget button api to support multiple button types Signed-off-by: Robin Appelman --- .../lib/Controller/DashboardApiController.php | 13 ++-- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/public/Dashboard/IButtonWidget.php | 24 ++---- lib/public/Dashboard/Model/WidgetButton.php | 75 +++++++++++++++++++ 5 files changed, 92 insertions(+), 22 deletions(-) create mode 100644 lib/public/Dashboard/Model/WidgetButton.php diff --git a/apps/dashboard/lib/Controller/DashboardApiController.php b/apps/dashboard/lib/Controller/DashboardApiController.php index f27a5ea025208..9f9872dc91613 100644 --- a/apps/dashboard/lib/Controller/DashboardApiController.php +++ b/apps/dashboard/lib/Controller/DashboardApiController.php @@ -32,6 +32,7 @@ use OCP\Dashboard\IIconWidget; use OCP\Dashboard\IManager; use OCP\Dashboard\IWidget; +use OCP\Dashboard\Model\WidgetButton; use OCP\IConfig; use OCP\IRequest; @@ -114,11 +115,13 @@ public function getWidgets(): DataResponse { ]; if ($widget instanceof IButtonWidget) { $data += [ - 'button' => [ - 'text' => $widget->getButtonText(), - 'icon_url' => $widget->getButtonIconUrl(), - 'url' => $widget->getUrl(), - ], + 'buttons' => array_map(function(WidgetButton $button) { + return [ + 'type' => $button->getType(), + 'text' => $button->getText(), + 'link' => $button->getLink(), + ]; + }, $widget->getWidgetButtons($this->userId)), ]; } return $data; diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 16ca9b856c7c1..3f37d7cad6f10 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -200,6 +200,7 @@ '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\\WidgetSetting' => $baseDir . '/lib/public/Dashboard/Model/WidgetSetting.php', 'OCP\\Dashboard\\Model\\WidgetSetup' => $baseDir . '/lib/public/Dashboard/Model/WidgetSetup.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index a818d684c36cd..aaef7c44b8fe8 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -233,6 +233,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 '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\\WidgetSetting' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetSetting.php', 'OCP\\Dashboard\\Model\\WidgetSetup' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetSetup.php', diff --git a/lib/public/Dashboard/IButtonWidget.php b/lib/public/Dashboard/IButtonWidget.php index cc0297fe7bc7d..5745c368c9622 100644 --- a/lib/public/Dashboard/IButtonWidget.php +++ b/lib/public/Dashboard/IButtonWidget.php @@ -22,6 +22,8 @@ */ namespace OCP\Dashboard; +use OCP\Dashboard\Model\WidgetButton; + /** * Adds a button to the dashboard api representation * @@ -29,23 +31,11 @@ */ 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 + * Get the buttons to show on the widget * - * @return string + * @param string $userId + * @return WidgetButton[] + * @since 25.0.0 */ - public function getButtonText(): string; + public function getWidgetButtons(string $userId): array; } diff --git a/lib/public/Dashboard/Model/WidgetButton.php b/lib/public/Dashboard/Model/WidgetButton.php new file mode 100644 index 0000000000000..c56ab232963a3 --- /dev/null +++ b/lib/public/Dashboard/Model/WidgetButton.php @@ -0,0 +1,75 @@ + + * + * @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 { + const TYPE_NEW = 'new'; + const TYPE_MORE = 'more'; + const TYPE_SETUP = 'setup'; + + private string $type; + private string $link; + private string $text; + + 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; + } +} From 845149bb7ccba5f0de37d145c6b7d13a7532e68b Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Thu, 8 Sep 2022 11:48:00 +0200 Subject: [PATCH 05/12] add IItemOptionWidget to define some item-related parameters, only getItemIconsRound() for now Signed-off-by: Julien Veyssier --- .../lib/Controller/DashboardApiController.php | 2 + lib/public/Dashboard/IItemOptionWidget.php | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 lib/public/Dashboard/IItemOptionWidget.php diff --git a/apps/dashboard/lib/Controller/DashboardApiController.php b/apps/dashboard/lib/Controller/DashboardApiController.php index 9f9872dc91613..b0859a088c649 100644 --- a/apps/dashboard/lib/Controller/DashboardApiController.php +++ b/apps/dashboard/lib/Controller/DashboardApiController.php @@ -30,6 +30,7 @@ use OCP\AppFramework\Http\DataResponse; use OCP\Dashboard\IButtonWidget; use OCP\Dashboard\IIconWidget; +use OCP\Dashboard\IItemOptionWidget; use OCP\Dashboard\IManager; use OCP\Dashboard\IWidget; use OCP\Dashboard\Model\WidgetButton; @@ -112,6 +113,7 @@ public function getWidgets(): DataResponse { 'icon_class' => $widget->getIconClass(), 'icon_url' => ($widget instanceof IIconWidget) ? $widget->getIconUrl() : '', 'widget_url' => $widget->getUrl(), + 'item_icons_round' => ($widget instanceof IItemOptionWidget) ? $widget->getItemIconsRound() : false, ]; if ($widget instanceof IButtonWidget) { $data += [ diff --git a/lib/public/Dashboard/IItemOptionWidget.php b/lib/public/Dashboard/IItemOptionWidget.php new file mode 100644 index 0000000000000..9826286b0418f --- /dev/null +++ b/lib/public/Dashboard/IItemOptionWidget.php @@ -0,0 +1,37 @@ + + * + * @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 widget options + * + * @since 25.0.0 + */ +interface IItemOptionWidget extends IWidget { + /** + * Should the item icons be rendered round (or raw/square) by the clients? + * + * @return bool + */ + public function getItemIconsRound(): bool; +} From d9e75f00b1977da7325db14554729419f5fe02c9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 13 Sep 2022 13:03:35 +0200 Subject: [PATCH 06/12] move widget options into a Option class Signed-off-by: Robin Appelman --- .../lib/Controller/DashboardApiController.php | 8 ++- lib/composer/composer/autoload_classmap.php | 2 + lib/composer/composer/autoload_static.php | 2 + ...ItemOptionWidget.php => IOptionWidget.php} | 10 +-- lib/public/Dashboard/Model/WidgetButton.php | 6 +- lib/public/Dashboard/Model/WidgetOptions.php | 61 +++++++++++++++++++ 6 files changed, 78 insertions(+), 11 deletions(-) rename lib/public/Dashboard/{IItemOptionWidget.php => IOptionWidget.php} (83%) create mode 100644 lib/public/Dashboard/Model/WidgetOptions.php diff --git a/apps/dashboard/lib/Controller/DashboardApiController.php b/apps/dashboard/lib/Controller/DashboardApiController.php index b0859a088c649..f7a1d6961c28c 100644 --- a/apps/dashboard/lib/Controller/DashboardApiController.php +++ b/apps/dashboard/lib/Controller/DashboardApiController.php @@ -30,10 +30,11 @@ use OCP\AppFramework\Http\DataResponse; use OCP\Dashboard\IButtonWidget; use OCP\Dashboard\IIconWidget; -use OCP\Dashboard\IItemOptionWidget; +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; @@ -106,6 +107,7 @@ 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(), @@ -113,11 +115,11 @@ public function getWidgets(): DataResponse { 'icon_class' => $widget->getIconClass(), 'icon_url' => ($widget instanceof IIconWidget) ? $widget->getIconUrl() : '', 'widget_url' => $widget->getUrl(), - 'item_icons_round' => ($widget instanceof IItemOptionWidget) ? $widget->getItemIconsRound() : false, + 'item_icons_round' => $options->withRoundItemIcons(), ]; if ($widget instanceof IButtonWidget) { $data += [ - 'buttons' => array_map(function(WidgetButton $button) { + 'buttons' => array_map(function (WidgetButton $button) { return [ 'type' => $button->getType(), 'text' => $button->getText(), diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 3f37d7cad6f10..40a5efea3478c 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -197,11 +197,13 @@ '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 aaef7c44b8fe8..50a2406a8d105 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -230,11 +230,13 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 '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/IItemOptionWidget.php b/lib/public/Dashboard/IOptionWidget.php similarity index 83% rename from lib/public/Dashboard/IItemOptionWidget.php rename to lib/public/Dashboard/IOptionWidget.php index 9826286b0418f..0cc129a508768 100644 --- a/lib/public/Dashboard/IItemOptionWidget.php +++ b/lib/public/Dashboard/IOptionWidget.php @@ -22,16 +22,16 @@ */ namespace OCP\Dashboard; +use OCP\Dashboard\Model\WidgetOptions; + /** * Allow getting widget options * * @since 25.0.0 */ -interface IItemOptionWidget extends IWidget { +interface IOptionWidget extends IWidget { /** - * Should the item icons be rendered round (or raw/square) by the clients? - * - * @return bool + * Get additional options for the widget */ - public function getItemIconsRound(): bool; + public function getWidgetOptions(): WidgetOptions; } diff --git a/lib/public/Dashboard/Model/WidgetButton.php b/lib/public/Dashboard/Model/WidgetButton.php index c56ab232963a3..f3e706bf652d3 100644 --- a/lib/public/Dashboard/Model/WidgetButton.php +++ b/lib/public/Dashboard/Model/WidgetButton.php @@ -29,9 +29,9 @@ * @since 25.0.0 */ class WidgetButton { - const TYPE_NEW = 'new'; - const TYPE_MORE = 'more'; - const TYPE_SETUP = 'setup'; + public const TYPE_NEW = 'new'; + public const TYPE_MORE = 'more'; + public const TYPE_SETUP = 'setup'; private string $type; private string $link; 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; + } +} From 8e2e3b4a9f243b0a3d02b5dcdc9e7ef02d9c3d35 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 7 Sep 2022 12:46:56 +0200 Subject: [PATCH 07/12] implement IAPIWidget in user_status Signed-off-by: Julien Veyssier --- .../lib/Dashboard/UserStatusWidget.php | 86 +++++++++++++------ 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/apps/user_status/lib/Dashboard/UserStatusWidget.php b/apps/user_status/lib/Dashboard/UserStatusWidget.php index 10411dc7f9daf..112e957cbcc44 100644 --- a/apps/user_status/lib/Dashboard/UserStatusWidget.php +++ b/apps/user_status/lib/Dashboard/UserStatusWidget.php @@ -28,50 +28,52 @@ 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\Model\WidgetItem; +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 { + 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; @@ -117,7 +119,7 @@ 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) { @@ -126,19 +128,24 @@ public function load(): void { } $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 +162,29 @@ 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['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); } } From 500ba958f3ddfb203fae5638069e6631e054f084 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 7 Sep 2022 13:11:44 +0200 Subject: [PATCH 08/12] implement IButtonWidget and IIconWidget in user_status Signed-off-by: Julien Veyssier --- .../lib/Dashboard/UserStatusWidget.php | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/user_status/lib/Dashboard/UserStatusWidget.php b/apps/user_status/lib/Dashboard/UserStatusWidget.php index 112e957cbcc44..0e2ecbe54bf3e 100644 --- a/apps/user_status/lib/Dashboard/UserStatusWidget.php +++ b/apps/user_status/lib/Dashboard/UserStatusWidget.php @@ -30,6 +30,8 @@ use OCA\UserStatus\Service\StatusService; use OCP\AppFramework\Services\IInitialState; use OCP\Dashboard\IAPIWidget; +use OCP\Dashboard\IButtonWidget; +use OCP\Dashboard\IIconWidget; use OCP\Dashboard\Model\WidgetItem; use OCP\IDateTimeFormatter; use OCP\IL10N; @@ -44,7 +46,7 @@ * * @package OCA\UserStatus */ -class UserStatusWidget implements IAPIWidget { +class UserStatusWidget implements IAPIWidget, IButtonWidget, IIconWidget { private IL10N $l10n; private IDateTimeFormatter $dateTimeFormatter; private IURLGenerator $urlGenerator; @@ -108,6 +110,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 */ @@ -123,7 +134,7 @@ public function load(): void { $currentUser = $this->userSession->getUser(); if ($currentUser === null) { - $this->initialStateService->provideInitialState(Application::APP_ID, 'dashboard_data', []); + $this->initialStateService->provideInitialState('dashboard_data', []); return; } $currentUserId = $currentUser->getUID(); @@ -175,7 +186,7 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7): $formattedDate = $this->dateTimeFormatter->formatTimeSpan($widgetData['timestamp']); return new WidgetItem( $widgetData['displayName'], - $widgetData['icon'] . ' ' . $widgetData['message'] . ', ' . $formattedDate, + $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']]) @@ -187,4 +198,11 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7): ); }, $widgetItemsData); } + + /** + * @inheritDoc + */ + public function getWidgetButtons(string $userId): array { + return []; + } } From 9ba26ee326887428f3b2b61edfac4109305a3db2 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 13 Sep 2022 13:54:42 +0200 Subject: [PATCH 09/12] set round item icons for user status widget Signed-off-by: Robin Appelman --- apps/user_status/lib/Dashboard/UserStatusWidget.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/user_status/lib/Dashboard/UserStatusWidget.php b/apps/user_status/lib/Dashboard/UserStatusWidget.php index 0e2ecbe54bf3e..5a89040dfa587 100644 --- a/apps/user_status/lib/Dashboard/UserStatusWidget.php +++ b/apps/user_status/lib/Dashboard/UserStatusWidget.php @@ -32,7 +32,9 @@ 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; @@ -46,7 +48,7 @@ * * @package OCA\UserStatus */ -class UserStatusWidget implements IAPIWidget, IButtonWidget, IIconWidget { +class UserStatusWidget implements IAPIWidget, IIconWidget, IOptionWidget { private IL10N $l10n; private IDateTimeFormatter $dateTimeFormatter; private IURLGenerator $urlGenerator; @@ -199,10 +201,7 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7): }, $widgetItemsData); } - /** - * @inheritDoc - */ - public function getWidgetButtons(string $userId): array { - return []; + public function getWidgetOptions(): WidgetOptions { + return new WidgetOptions(true); } } From da74da8a9c5ace9b10bc9dbd60fad229d477b073 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Thu, 15 Sep 2022 18:24:43 +0200 Subject: [PATCH 10/12] adjust empty array check Signed-off-by: Julien Veyssier --- apps/dashboard/lib/Controller/DashboardApiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dashboard/lib/Controller/DashboardApiController.php b/apps/dashboard/lib/Controller/DashboardApiController.php index f7a1d6961c28c..1062cf1bdba02 100644 --- a/apps/dashboard/lib/Controller/DashboardApiController.php +++ b/apps/dashboard/lib/Controller/DashboardApiController.php @@ -79,7 +79,7 @@ public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widg $showWidgets = $widgets; $items = []; - if ($showWidgets === []) { + if (empty($showWidgets)) { $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar'); $showWidgets = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)); } From 9c402eb745c39a2b5122f45cdd1c3e673b72850a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Sep 2022 08:23:04 +0200 Subject: [PATCH 11/12] Add since tags Signed-off-by: Joas Schilling --- lib/public/Dashboard/IIconWidget.php | 1 + lib/public/Dashboard/IOptionWidget.php | 1 + lib/public/Dashboard/Model/WidgetButton.php | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/lib/public/Dashboard/IIconWidget.php b/lib/public/Dashboard/IIconWidget.php index b9928d5a6b375..3f5cf5fb050aa 100644 --- a/lib/public/Dashboard/IIconWidget.php +++ b/lib/public/Dashboard/IIconWidget.php @@ -32,6 +32,7 @@ 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 index 0cc129a508768..8d5146c524843 100644 --- a/lib/public/Dashboard/IOptionWidget.php +++ b/lib/public/Dashboard/IOptionWidget.php @@ -32,6 +32,7 @@ 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 index f3e706bf652d3..480249b539fde 100644 --- a/lib/public/Dashboard/Model/WidgetButton.php +++ b/lib/public/Dashboard/Model/WidgetButton.php @@ -37,6 +37,12 @@ class WidgetButton { 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; From 3009e023249fc1ec68dae101c1abd4ca52c03125 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Sep 2022 11:03:44 +0200 Subject: [PATCH 12/12] Fix phpunit Signed-off-by: Joas Schilling --- .../Unit/Dashboard/UserStatusWidgetTest.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) 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',