From 91f568e01b1b91e08874a087ba2e17a9312f11ef Mon Sep 17 00:00:00 2001 From: yemkareems Date: Thu, 28 Nov 2024 12:28:39 +0530 Subject: [PATCH 1/3] feat(dashboard): added new FavouriteWidget to display favorite files in dashboard widget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added widget star icon * run build/autoloaderchecker.sh * removed unwanted IWidget and usersession * renamed id * renamed class to FavoriteWidget * removed limit logic * removed IAPIWidget * ui fixes to remove rounded corners and make the ui/ux similar to recommendation widget. * cs fix + composer fix no dev and review comments from Joas and Côme addressed * added count and removed slice Signed-off-by: yemkareems Co-authored-by: Ferdinand Thiessen Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com> --- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + apps/files/lib/AppInfo/Application.php | 2 + apps/files/lib/Dashboard/FavoriteWidget.php | 136 ++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 apps/files/lib/Dashboard/FavoriteWidget.php diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php index 103a4377223d2..7975c6f3d8310 100644 --- a/apps/files/composer/composer/autoload_classmap.php +++ b/apps/files/composer/composer/autoload_classmap.php @@ -48,6 +48,7 @@ 'OCA\\Files\\Controller\\TemplateController' => $baseDir . '/../lib/Controller/TemplateController.php', 'OCA\\Files\\Controller\\TransferOwnershipController' => $baseDir . '/../lib/Controller/TransferOwnershipController.php', 'OCA\\Files\\Controller\\ViewController' => $baseDir . '/../lib/Controller/ViewController.php', + 'OCA\\Files\\Dashboard\\FavoriteWidget' => $baseDir . '/../lib/Dashboard/FavoriteWidget.php', 'OCA\\Files\\Db\\OpenLocalEditor' => $baseDir . '/../lib/Db/OpenLocalEditor.php', 'OCA\\Files\\Db\\OpenLocalEditorMapper' => $baseDir . '/../lib/Db/OpenLocalEditorMapper.php', 'OCA\\Files\\Db\\TransferOwnership' => $baseDir . '/../lib/Db/TransferOwnership.php', diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php index bb2195eaf0f00..f2cb858f31346 100644 --- a/apps/files/composer/composer/autoload_static.php +++ b/apps/files/composer/composer/autoload_static.php @@ -63,6 +63,7 @@ class ComposerStaticInitFiles 'OCA\\Files\\Controller\\TemplateController' => __DIR__ . '/..' . '/../lib/Controller/TemplateController.php', 'OCA\\Files\\Controller\\TransferOwnershipController' => __DIR__ . '/..' . '/../lib/Controller/TransferOwnershipController.php', 'OCA\\Files\\Controller\\ViewController' => __DIR__ . '/..' . '/../lib/Controller/ViewController.php', + 'OCA\\Files\\Dashboard\\FavoriteWidget' => __DIR__ . '/..' . '/../lib/Dashboard/FavoriteWidget.php', 'OCA\\Files\\Db\\OpenLocalEditor' => __DIR__ . '/..' . '/../lib/Db/OpenLocalEditor.php', 'OCA\\Files\\Db\\OpenLocalEditorMapper' => __DIR__ . '/..' . '/../lib/Db/OpenLocalEditorMapper.php', 'OCA\\Files\\Db\\TransferOwnership' => __DIR__ . '/..' . '/../lib/Db/TransferOwnership.php', diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index 84387983946aa..8d00912f7bba4 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -13,6 +13,7 @@ use OCA\Files\Collaboration\Resources\Listener; use OCA\Files\Collaboration\Resources\ResourceProvider; use OCA\Files\Controller\ApiController; +use OCA\Files\Dashboard\FavoriteWidget; use OCA\Files\DirectEditingCapabilities; use OCA\Files\Event\LoadSearchPlugins; use OCA\Files\Event\LoadSidebar; @@ -123,6 +124,7 @@ public function register(IRegistrationContext $context): void { $context->registerSearchProvider(FilesSearchProvider::class); $context->registerNotifierService(Notifier::class); + $context->registerDashboardWidget(FavoriteWidget::class); } public function boot(IBootContext $context): void { diff --git a/apps/files/lib/Dashboard/FavoriteWidget.php b/apps/files/lib/Dashboard/FavoriteWidget.php new file mode 100644 index 0000000000000..a36dd65c81bc7 --- /dev/null +++ b/apps/files/lib/Dashboard/FavoriteWidget.php @@ -0,0 +1,136 @@ +l10n->t('Favorite files'); + } + + public function getOrder(): int { + return 0; + } + + public function getIconClass(): string { + return 'icon-star-dark'; + } + + public function getIconUrl(): string { + return $this->urlGenerator->getAbsoluteURL( + $this->urlGenerator->imagePath('core', 'actions/star.svg') + ); + } + + public function getUrl(): ?string { + return $this->urlGenerator->linkToRouteAbsolute('files.View.indexView', ['view' => 'favorites']); + } + + public function load(): void { + } + + public function getItems(string $userId, int $limit = 7): array { + $user = $this->userManager->get($userId); + + if (!$user) { + return []; + } + $tags = $this->tagManager->load('files', [], false, $userId); + $favorites = $tags->getFavorites(); + if (empty($favorites)) { + return []; + } + $favoriteNodes = []; + $userFolder = $this->rootFolder->getUserFolder($userId); + $count = 0; + foreach ($favorites as $favorite) { + $node = $userFolder->getFirstNodeById($favorite); + if ($node) { + $url = $this->urlGenerator->linkToRouteAbsolute( + 'files.view.showFile', ['fileid' => $node->getId()] + ); + $icon = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', [ + 'x' => 256, + 'y' => 256, + 'fileId' => $node->getId(), + 'c' => $node->getEtag(), + 'mimeFallback' => true, + ]); + $favoriteNodes[] = new WidgetItem( + $node->getName(), + '', + $url, + $icon, + (string)$node->getCreationTime() + ); + $count++; + if ($count >= $limit) { + break; + } + } + } + + return $favoriteNodes; + } + + public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems { + $items = $this->getItems($userId, $limit); + return new WidgetItems( + $items, + count($items) === 0 ? $this->l10n->t('No favorites') : '', + ); + } + + public function getWidgetButtons(string $userId): array { + return [ + new WidgetButton( + WidgetButton::TYPE_MORE, + $this->urlGenerator->linkToRouteAbsolute('files.View.indexView', ['view' => 'favorites']), + $this->l10n->t('More favorites') + ), + ]; + } + + public function getWidgetOptions(): WidgetOptions { + return new WidgetOptions(roundItemIcons: false); + } +} From bbde7681520ded0dee0b999d69e5b50789a7ac15 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 14 Jan 2025 17:55:10 +0100 Subject: [PATCH 2/3] fix(dashboard): Correctly handle non-rounded icons for dashboard widgets Signed-off-by: Ferdinand Thiessen --- apps/dashboard/src/DashboardApp.vue | 4 +- .../src/components/ApiDashboardWidget.vue | 29 ++++---- .../src/components/ApiDashboardWidgetItem.vue | 68 +++++++++++++++++++ 3 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 apps/dashboard/src/components/ApiDashboardWidgetItem.vue diff --git a/apps/dashboard/src/DashboardApp.vue b/apps/dashboard/src/DashboardApp.vue index 864571842cc8c..055f1e68cb6cc 100644 --- a/apps/dashboard/src/DashboardApp.vue +++ b/apps/dashboard/src/DashboardApp.vue @@ -461,8 +461,8 @@ export default { } }, async fetchApiWidgets() { - const response = await axios.get(generateOcsUrl('/apps/dashboard/api/v1/widgets')) - this.apiWidgets = response.data.ocs.data + const { data } = await axios.get(generateOcsUrl('/apps/dashboard/api/v1/widgets')) + this.apiWidgets = data.ocs.data }, async fetchApiWidgetItems(widgetIds, merge = false) { try { diff --git a/apps/dashboard/src/components/ApiDashboardWidget.vue b/apps/dashboard/src/components/ApiDashboardWidget.vue index e82b977b04189..22834abadd534 100644 --- a/apps/dashboard/src/components/ApiDashboardWidget.vue +++ b/apps/dashboard/src/components/ApiDashboardWidget.vue @@ -10,16 +10,7 @@ :show-items-and-empty-content="!!halfEmptyContentMessage" :half-empty-content-message="halfEmptyContentMessage">