Add iconClass to resources
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
555afff015
commit
88aa3de784
7 changed files with 62 additions and 3 deletions
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue