diff --git a/css/admin.scss b/css/admin.scss index 17414dc9c..c832ee5df 100644 --- a/css/admin.scss +++ b/css/admin.scss @@ -46,8 +46,10 @@ } ul { display: flex; + flex-wrap: wrap; li { $size: 150px; + $sizeY: $size / 210 * 297; $space: 10px; border-radius: var(--border-radius); border: 1px solid var(--color-border); @@ -60,7 +62,7 @@ margin: $space; img { width: $size; - height: $size; + height: $sizeY; background-color: var(--color-background-dark); } figcaption { @@ -70,7 +72,7 @@ .delete-cover, .delete-template { width: $size; - height: $size; + height: $sizeY; top: 0; left: 0; position: absolute; @@ -78,7 +80,7 @@ opacity: 0; transition: opacity 250ms ease-in-out; z-index: 3; - line-height: $size; + line-height: $sizeY; text-align: center; font-size: 20px; background-size: 24px; diff --git a/lib/Controller/TemplatesController.php b/lib/Controller/TemplatesController.php index ef3f707ec..740b7b094 100644 --- a/lib/Controller/TemplatesController.php +++ b/lib/Controller/TemplatesController.php @@ -1,4 +1,5 @@ * @@ -27,6 +28,7 @@ use OCA\Richdocuments\TemplateManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\NotFoundResponse; use OCP\Files\Node; @@ -189,7 +191,7 @@ class TemplatesController extends Controller { bool $forceIcon = true, string $mode): Http\Response { - if (!($node instanceof File) || (!$forceIcon && !$this->preview->isAvailable($node))) { + if (!($node instanceof Node) || (!$forceIcon && !$this->preview->isAvailable($node))) { return new DataResponse([], Http::STATUS_NOT_FOUND); } if (!$node->isReadable()) { diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 8f8f70a7e..04692c1cb 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -61,7 +61,7 @@ class Admin implements ISettings { 'doc_format' => $this->config->getAppValue('richdocuments', 'doc_format'), 'external_apps' => $this->config->getAppValue('richdocuments', 'external_apps'), 'canonical_webroot' => $this->config->getAppValue('richdocuments', 'canonical_webroot'), - 'templates' => $this->manager->getGlobals() + 'templates' => $this->manager->getUser() ], 'blank' ); diff --git a/lib/TemplateManager.php b/lib/TemplateManager.php index 372296b58..bf5ced6ef 100644 --- a/lib/TemplateManager.php +++ b/lib/TemplateManager.php @@ -1,4 +1,5 @@ * @@ -23,7 +24,6 @@ namespace OCA\Richdocuments; -use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IAppData; use OCP\Files\IRootFolder; @@ -92,12 +92,12 @@ class TemplateManager { * @param IPreview $previewManager */ public function __construct(string $appName, - string $userId, - IConfig $config, - Factory $appDataFactory, - IURLGenerator $urlGenerator, - IRootFolder $rootFolder, - IPreview $previewManager) { + string $userId, + IConfig $config, + Factory $appDataFactory, + IURLGenerator $urlGenerator, + IRootFolder $rootFolder, + IPreview $previewManager) { $this->appName = $appName; $this->userId = $userId; $this->config = $config; @@ -114,7 +114,7 @@ class TemplateManager { } /** - * Get template file/node + * Get template ISimpleFile|Node * * @param string $templateName * @return ISimpleFile|Node @@ -129,18 +129,19 @@ class TemplateManager { try { $templateFile = $templateDir->get($templateName); } catch (NotFoundException $e) { - throw new NotFoundException($e); + throw new NotFoundException($e->getMessage()); } } return $templateFile; - // return $this->formatNodeReturn($templateFile); } /** * Get all global templates + * + * @return array */ - public function getGlobals() { + public function getSystem(): array{ $templateFiles = $this->folder->getDirectoryListing(); return array_map(function (ISimpleFile $templateFile) { @@ -148,14 +149,28 @@ class TemplateManager { }, $templateFiles); } + /** + * Get all user templates + * + * @return array + */ + public function getUser(): array{ + $templateDir = $this->getUserTemplateDir(); + $templateFiles = $templateDir->getDirectoryListing(); + + return array_map(function (Node $templateFile) { + return $this->formatNodeReturn($templateFile); + }, $templateFiles); + } + /** * Add a template to the global template folder * * @param string $templateName * @param string $templateFile - * @return void + * @return array */ - public function add(string $templateName, string $templateFile) { + public function add(string $templateName, string $templateFile): array{ try { $template = $this->folder->getFile($templateName); } catch (NotFoundException $e) { @@ -170,15 +185,17 @@ class TemplateManager { * Delete a template to the global template folder * * @param string $templateName - * @return void + * @return boolean + * @throws NotFoundException */ - public function delete(string $templateName) { + public function delete(string $templateName): bool { try { $template = $this->get($templateName); $template->delete(); } catch (NotFoundException $e) { - throw new NotFoundException($e); + throw new NotFoundException($e->getMessage()); } + return true; } @@ -214,7 +231,7 @@ class TemplateManager { try { $templateDir = $this->userFolder->get('Templates'); } catch (NotFoundException $e) { - throw new NotFoundException($e); + throw new NotFoundException($e->getMessage()); } } @@ -233,7 +250,7 @@ class TemplateManager { 'preview' => $this->urlGenerator->linkToRoute('richdocuments.templates.getPreview', ['templateName' => $template->getName()]), 'ext' => $this->flipTypes[$template->getMimeType()], 'etag' => $template->getETag(), - 'delete' => $this->urlGenerator->linkToRoute('richdocuments.templates.delete', ['templateName' => $template->getName()]), + 'delete' => $this->urlGenerator->linkToRoute('richdocuments.templates.delete', ['templateName' => $template->getName()]) ]; } }