Skip to content

Commit

Permalink
use mimeIcon is preview not available
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Sep 21, 2022
1 parent 82850dc commit 950869c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/build
/node_modules
/vendor/

.idea/
41 changes: 32 additions & 9 deletions lib/Dashboard/RecommendationWidget.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
*
Expand Down Expand Up @@ -30,6 +33,7 @@
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\IWidget;
use OCP\Dashboard\Model\WidgetItem;
use OCP\Files\IMimeTypeDetector;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
Expand All @@ -40,19 +44,22 @@ class RecommendationWidget implements IWidget, IIconWidget, IAPIWidget {
private IUserSession $userSession;
private IL10N $l10n;
private IURLGenerator $urlGenerator;
private IMimeTypeDetector $mimeTypeDetector;
private RecommendationService $recommendationService;
private IUserManager $userManager;

public function __construct(
IUserSession $userSession,
IL10N $l10n,
IURLGenerator $urlGenerator,
IMimeTypeDetector $mimeTypeDetector,
RecommendationService $recommendationService,
IUserManager $userManager
) {
$this->userSession = $userSession;
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
$this->mimeTypeDetector = $mimeTypeDetector;
$this->recommendationService = $recommendationService;
$this->userManager = $userManager;
}
Expand Down Expand Up @@ -96,15 +103,31 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
}
$recommendations = $this->recommendationService->getRecommendations($user, $limit);

return array_map(function(IRecommendation $recommendation) {
$url = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $recommendation->getNode()->getId()]);
$icon = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', [
'x' => 256,
'y' => 256,
'fileId' => $recommendation->getNode()->getId(),
'c' => $recommendation->getNode()->getEtag(),
]);
return new WidgetItem($recommendation->getNode()->getName(), '', $url, $icon, $recommendation->getTimestamp());
return array_map(function (IRecommendation $recommendation) {
$url = $this->urlGenerator->linkToRouteAbsolute(
'files.viewcontroller.showFile', ['fileid' => $recommendation->getNode()->getId()]
);

if ($recommendation->hasPreview()) {
$icon = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', [
'x' => 256,
'y' => 256,
'fileId' => $recommendation->getNode()->getId(),
'c' => $recommendation->getNode()->getEtag(),
]);
} else {
$icon = $this->urlGenerator->getAbsoluteURL(
$this->mimeTypeDetector->mimeTypeIcon($recommendation->getNode()->getMimetype())
);
}

return new WidgetItem(
$recommendation->getNode()->getName(),
'',
$url,
$icon,
(string)$recommendation->getTimestamp()
);
}, $recommendations);
}
}

0 comments on commit 950869c

Please sign in to comment.