diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2023-08-17 15:09:30 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-08-22 08:36:53 +0200 |
commit | 6982597b6a6d319dacfbe3bee2edd2a39b3d6d68 (patch) | |
tree | 9a3cfc98c5ce08542e204ef37365491fa0a0404e /apps/user_status/lib | |
parent | 82835eaa4623180c41dad927b0ac1db1ed449362 (diff) | |
download | nextcloud-server-6982597b6a6d319dacfbe3bee2edd2a39b3d6d68.tar.gz nextcloud-server-6982597b6a6d319dacfbe3bee2edd2a39b3d6d68.zip |
feat(dashboard): implement widget item api v2
This API enables the dashboard to render all widgets from the API data
alone without having apps to provide their own bundles. This saves a lot
of traffic and execution time as a lot less javascript has to be parsed
on the frontend.
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'apps/user_status/lib')
-rw-r--r-- | apps/user_status/lib/Dashboard/UserStatusWidget.php | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/apps/user_status/lib/Dashboard/UserStatusWidget.php b/apps/user_status/lib/Dashboard/UserStatusWidget.php index 2e1de3cd6cf..89b9c05f805 100644 --- a/apps/user_status/lib/Dashboard/UserStatusWidget.php +++ b/apps/user_status/lib/Dashboard/UserStatusWidget.php @@ -6,6 +6,7 @@ declare(strict_types=1); * @copyright Copyright (c) 2020, Georg Ehrke * * @author Georg Ehrke <oc.list@georgehrke.com> + * @author Richard Steinmetz <richard@steinmetz.cloud> * * @license GNU AGPL version 3 or any later version * @@ -31,9 +32,11 @@ use OCA\UserStatus\Service\StatusService; use OCP\AppFramework\Services\IInitialState; use OCP\Dashboard\IAPIWidget; use OCP\Dashboard\IButtonWidget; +use OCP\Dashboard\IAPIWidgetV2; use OCP\Dashboard\IIconWidget; use OCP\Dashboard\IOptionWidget; use OCP\Dashboard\Model\WidgetItem; +use OCP\Dashboard\Model\WidgetItems; use OCP\Dashboard\Model\WidgetOptions; use OCP\IDateTimeFormatter; use OCP\IL10N; @@ -48,7 +51,7 @@ use OCP\Util; * * @package OCA\UserStatus */ -class UserStatusWidget implements IAPIWidget, IIconWidget, IOptionWidget { +class UserStatusWidget implements IAPIWidget, IAPIWidgetV2, IIconWidget, IOptionWidget { private IL10N $l10n; private IDateTimeFormatter $dateTimeFormatter; private IURLGenerator $urlGenerator; @@ -132,17 +135,6 @@ class UserStatusWidget implements IAPIWidget, IIconWidget, IOptionWidget { * @inheritDoc */ public function load(): void { - Util::addScript(Application::APP_ID, 'dashboard'); - - $currentUser = $this->userSession->getUser(); - if ($currentUser === null) { - $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 { @@ -201,6 +193,17 @@ class UserStatusWidget implements IAPIWidget, IIconWidget, IOptionWidget { }, $widgetItemsData); } + /** + * @inheritDoc + */ + public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems { + $items = $this->getItems($userId, $since, $limit); + return new WidgetItems( + $items, + count($items) === 0 ? $this->l10n->t('No recent status changes') : '', + ); + } + public function getWidgetOptions(): WidgetOptions { return new WidgetOptions(true); } |