From 88aa3de7842a5113de5f137ba57bdae1f77777b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 23 Jan 2019 17:48:24 +0100 Subject: [PATCH] Add iconClass to resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../Collaboration/Resources/ResourceProvider.php | 12 ++++++++++++ .../src/components/CollectionListItem.vue | 2 +- .../CollaborationResourcesController.php | 5 +++-- lib/private/Collaboration/Resources/Manager.php | 16 ++++++++++++++++ lib/private/Collaboration/Resources/Resource.php | 15 +++++++++++++++ lib/public/Collaboration/Resources/IProvider.php | 9 +++++++++ lib/public/Collaboration/Resources/IResource.php | 6 ++++++ 7 files changed, 62 insertions(+), 3 deletions(-) diff --git a/apps/files/lib/Collaboration/Resources/ResourceProvider.php b/apps/files/lib/Collaboration/Resources/ResourceProvider.php index 6d9b1b5978..62dcbe19c1 100644 --- a/apps/files/lib/Collaboration/Resources/ResourceProvider.php +++ b/apps/files/lib/Collaboration/Resources/ResourceProvider.php @@ -25,6 +25,7 @@ namespace OCA\Files\Collaboration\Resources; use OCP\Collaboration\Resources\IProvider; use OCP\Collaboration\Resources\IResource; use OCP\Files\IRootFolder; +use OCP\Files\Node; use OCP\IUser; class ResourceProvider implements IProvider { @@ -80,4 +81,15 @@ class ResourceProvider implements IProvider { return false; } + + /** + * Get the icon class of a resource + * + * @param IResource $resource + * @return string + * @since 15.0.0 + */ + public function getIconClass(IResource $resource): string { + return 'icon-folder'; + } } diff --git a/apps/files_sharing/src/components/CollectionListItem.vue b/apps/files_sharing/src/components/CollectionListItem.vue index aebab670ac..f22d5238d6 100644 --- a/apps/files_sharing/src/components/CollectionListItem.vue +++ b/apps/files_sharing/src/components/CollectionListItem.vue @@ -92,7 +92,7 @@ ] }, getIcon() { - return (resource) => [window.OCP.Collaboration.getIcon(resource.type)] + return (resource) => [window.OCP.Collaboration.getIcon(resource.type), resource.iconClass] }, getLink() { return (resource) => window.OCP.Collaboration.getLink(resource.type, resource.id) diff --git a/core/Controller/CollaborationResourcesController.php b/core/Controller/CollaborationResourcesController.php index a5a40145fb..565e0ba473 100644 --- a/core/Controller/CollaborationResourcesController.php +++ b/core/Controller/CollaborationResourcesController.php @@ -197,15 +197,16 @@ class CollaborationResourcesController extends OCSController { ]; } - protected function prepareResources(IResource $resource): array { + protected function prepareResources(IResource $resource): ?array { if (!$resource->canAccess($this->userSession->getUser())) { - return []; + return null; } return [ 'type' => $resource->getType(), 'id' => $resource->getId(), 'name' => $resource->getName(), + 'iconClass' => $resource->getIconClass() ]; } } diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php index 82a14f47d9..cc09089c71 100644 --- a/lib/private/Collaboration/Resources/Manager.php +++ b/lib/private/Collaboration/Resources/Manager.php @@ -119,6 +119,22 @@ class Manager implements IManager { return ''; } + /** + * + * @param IResource $resource + * @return string + */ + public function getIconClass(IResource $resource): string { + foreach ($this->getProviders() as $provider) { + try { + return $provider->getIconClass($resource); + } catch (ResourceException $e) { + } + } + + return ''; + } + /** * Can a user/guest access the collection * diff --git a/lib/private/Collaboration/Resources/Resource.php b/lib/private/Collaboration/Resources/Resource.php index 3013f1f5c4..2f491663a8 100644 --- a/lib/private/Collaboration/Resources/Resource.php +++ b/lib/private/Collaboration/Resources/Resource.php @@ -47,6 +47,9 @@ class Resource implements IResource { /** @var string|null */ protected $name; + /** @var string|null */ + protected $iconClass; + public function __construct( IManager $manager, IDBConnection $connection, @@ -87,6 +90,18 @@ class Resource implements IResource { return $this->name; } + /** + * @return string + * @since 15.0.0 + */ + public function getIconClass(): string { + if ($this->iconClass === null) { + $this->iconClass = $this->manager->getIconClass($this); + } + + return $this->iconClass; + } + /** * Can a user/guest access the resource * diff --git a/lib/public/Collaboration/Resources/IProvider.php b/lib/public/Collaboration/Resources/IProvider.php index bf33811300..c5f6f7ed56 100644 --- a/lib/public/Collaboration/Resources/IProvider.php +++ b/lib/public/Collaboration/Resources/IProvider.php @@ -35,6 +35,15 @@ interface IProvider { */ public function getName(IResource $resource): string; + /** + * Get the icon class of a resource + * + * @param IResource $resource + * @return string + * @since 15.0.0 + */ + public function getIconClass(IResource $resource): string; + /** * Can a user/guest access the collection * diff --git a/lib/public/Collaboration/Resources/IResource.php b/lib/public/Collaboration/Resources/IResource.php index 242ad9432d..9a4b2b30d1 100644 --- a/lib/public/Collaboration/Resources/IResource.php +++ b/lib/public/Collaboration/Resources/IResource.php @@ -47,6 +47,12 @@ interface IResource { */ public function getName(): string; + /** + * @return string + * @since 15.0.0 + */ + public function getIconClass(): string; + /** * Can a user/guest access the resource *