From 4f90766ba314171bbfc78d1e988307c50633e7f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Tue, 19 Jan 2021 16:38:51 +0100 Subject: [PATCH] Skip template picker if none available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- .../lib/Controller/TemplateController.php | 12 +-- apps/files/lib/Controller/ViewController.php | 2 +- apps/files/src/components/TemplatePreview.vue | 45 ++++++--- apps/files/src/services/Templates.js | 29 ++++++ apps/files/src/templates.js | 91 +++++++++++++---- apps/files/src/utils/davUtils.js | 18 +++- apps/files/src/views/TemplatePicker.vue | 72 +++++++++----- core/css/css-variables.scss | 3 + core/css/icons.scss | 1 + core/img/actions/template-add.svg | 1 + .../Files/Template/TemplateManager.php | 97 +++++++++++++------ lib/private/legacy/OC_Util.php | 6 +- .../Files/Template/ITemplateManager.php | 4 +- .../Files/Template/TemplateFileCreator.php | 19 +++- 14 files changed, 295 insertions(+), 105 deletions(-) create mode 100644 apps/files/src/services/Templates.js create mode 100644 core/img/actions/template-add.svg diff --git a/apps/files/lib/Controller/TemplateController.php b/apps/files/lib/Controller/TemplateController.php index 08a324a46e..5a16334322 100644 --- a/apps/files/lib/Controller/TemplateController.php +++ b/apps/files/lib/Controller/TemplateController.php @@ -64,12 +64,12 @@ class TemplateController extends OCSController { */ public function path(string $templatePath = '', bool $copySystemTemplates = false) { try { - $this->templateManager->setTemplatePath($templatePath); - if ($copySystemTemplates) { - $this->templateManager->initializeTemplateDirectory($templatePath); - } - return new DataResponse(); - } catch (GenericFileException $e) { + $templatePath = $this->templateManager->initializeTemplateDirectory($templatePath, null, $copySystemTemplates); + return new DataResponse([ + 'template_path' => $templatePath, + 'templates' => $this->templateManager->listCreators() + ]); + } catch (\Exception $e) { throw new OCSForbiddenException($e->getMessage()); } } diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 846ec14c4a..aade5a5b44 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -294,7 +294,7 @@ class ViewController extends Controller { if (class_exists(LoadViewer::class)) { $this->eventDispatcher->dispatchTyped(new LoadViewer()); } - $this->initialState->provideInitialState('template_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : null); + $this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : null); $this->initialState->provideInitialState('templates', $this->templateManager->listCreators()); $params = []; diff --git a/apps/files/src/components/TemplatePreview.vue b/apps/files/src/components/TemplatePreview.vue index 538e1bcff7..89162ba4ef 100644 --- a/apps/files/src/components/TemplatePreview.vue +++ b/apps/files/src/components/TemplatePreview.vue @@ -30,9 +30,9 @@ @change="onCheck">