-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
yemkareems
wants to merge
4
commits into
master
Choose a base branch
from
feature/23308/create-new-favorite-dashboard-widget
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+182
−7
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
341e377
feat: added new FavouriteWidget to display favorite files in dashboar…
yemkareems 69ab81d
fix: added widget star icon, run build/autoloaderchecker.sh, removed …
yemkareems 7ad8f46
fix: removed IAPIWidget
yemkareems c6fdaca
fix: ui fixes to remove rounded corners and make the ui/ux similar to…
yemkareems File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
#panel-files-favorites { | ||
.avatardiv { | ||
border-radius: var(--border-radius); | ||
flex-shrink: 0; | ||
|
||
& > img { | ||
border-radius: var(--border-radius); | ||
flex-shrink: 0; | ||
margin-right: 9px; | ||
} | ||
|
||
background: none !important; | ||
margin-left: 8px; | ||
margin-right: 9px; | ||
} | ||
.item-list__entry { | ||
padding-left: 0; | ||
padding-right: 0; | ||
} | ||
.item__details { | ||
white-space: nowrap; | ||
margin-bottom: -8px; | ||
display: inline-block; | ||
max-width: 170px; | ||
color: var(--color-main-text); | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
padding-left: 0; | ||
border-radius: var(--border-radius); | ||
} | ||
h3 { | ||
font-weight: 400; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?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; | ||
use OCP\Util; | ||
|
||
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->linkToRouteAbsolute('files.View.indexView', ['view' => 'favorites']); | ||
} | ||
|
||
public function load(): void { | ||
Util::addStyle('files', 'style'); | ||
} | ||
|
||
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); | ||
foreach ($favorites as $favorite) { | ||
$node = $userFolder->getFirstNodeById($favorite); | ||
if ($node) { | ||
$url = $this->urlGenerator->linkToRouteAbsolute( | ||
'files.view.showFile', ['fileid' => $node->getId()] | ||
); | ||
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 array_slice($favoriteNodes, 0, $limit); | ||
} | ||
|
||
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') | ||
), | ||
]; | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not slice, you should count in the foreach and stop at
$limit
. Otherwise you are building a lot of WidgetItem instances for nothing.