Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: added new FavouriteWidget to display favorite files in dashboard widget #49534

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions apps/files/img/app-favorite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions apps/files/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -120,6 +121,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 {
Expand Down
131 changes: 131 additions & 0 deletions apps/files/lib/Dashboard/FavoriteWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Files\Dashboard;

use OCA\Files\AppInfo\Application;
use OCP\Dashboard\IAPIWidgetV2;
use OCP\Dashboard\IButtonWidget;
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\Model\WidgetButton;
use OCP\Dashboard\Model\WidgetItem;
use OCP\Dashboard\Model\WidgetItems;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\IRootFolder;
use OCP\IL10N;
use OCP\IPreview;
use OCP\ITagManager;
use OCP\IURLGenerator;
use OCP\IUserManager;

class FavoriteWidget implements IIconWidget, IAPIWidgetV2, IButtonWidget {
public function __construct(
private readonly IL10N $l10n,
private readonly IURLGenerator $urlGenerator,
private readonly IMimeTypeDetector $mimeTypeDetector,
private readonly IUserManager $userManager,
private readonly ITagManager $tagManager,
private readonly IRootFolder $rootFolder,
private readonly IPreview $previewManager,
) {

}

public function getId(): string {
return Application::APP_ID.'-favorites';
}

public function getTitle(): string {
return $this->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('files', 'app-favorite.svg')
);
}

public function getUrl(): ?string {
return $this->urlGenerator->getAbsoluteURL('index.php/apps/files/favorites');
yemkareems marked this conversation as resolved.
Show resolved Hide resolved
}

public function load(): void {
return;
}

public function getItems(string $userId, ?string $since = null, int $limit = 7): array {
yemkareems marked this conversation as resolved.
Show resolved Hide resolved
$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);
foreach ($favorites as $favorite) {
$node = $userFolder->getFirstNodeById($favorite);
if ($node) {
$url = $this->urlGenerator->linkToRouteAbsolute(
'files.viewcontroller.showFile', ['fileid' => $node->getId()]
yemkareems marked this conversation as resolved.
Show resolved Hide resolved
);
if ($this->previewManager->isAvailable($node)) {
$icon = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', [
'x' => 256,
'y' => 256,
'fileId' => $node->getId(),
'c' => $node->getEtag(),
]);
} else {
$icon = $this->urlGenerator->getAbsoluteURL(
$this->mimeTypeDetector->mimeTypeIcon($node->getMimetype())
);
}
$favoriteNodes[] = new WidgetItem(
$node->getName(),
'',
$url,
$icon,
(string)$node->getCreationTime()
);
}
}

return $favoriteNodes;
}

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 favorites') : '',
);
}

public function getWidgetButtons(string $userId): array {
return [
new WidgetButton(
WidgetButton::TYPE_MORE,
$this->urlGenerator->getAbsoluteURL('index.php/apps/files/favorites'),
yemkareems marked this conversation as resolved.
Show resolved Hide resolved
$this->l10n->t('More favorites')
),
];
}
}
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
'OC\\' => array($baseDir . '/lib/private'),
'OCP\\' => array($baseDir . '/lib/public'),
'NCU\\' => array($baseDir . '/lib/unstable'),
'Bamarni\\Composer\\Bin\\' => array($vendorDir . '/bamarni/composer-bin-plugin/src'),
yemkareems marked this conversation as resolved.
Show resolved Hide resolved
'' => array($baseDir . '/lib/private/legacy'),
);
8 changes: 8 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
array (
'NCU\\' => 4,
),
'B' =>
array (
'Bamarni\\Composer\\Bin\\' => 21,
),
);

public static $prefixDirsPsr4 = array (
Expand All @@ -40,6 +44,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
array (
0 => __DIR__ . '/../../..' . '/lib/unstable',
),
'Bamarni\\Composer\\Bin\\' =>
array (
0 => __DIR__ . '/..' . '/bamarni/composer-bin-plugin/src',
),
);

public static $fallbackDirsPsr4 = array (
Expand Down
Loading