From 983825dafaceb6d02a01976083d5ab2bb8431136 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Sun, 11 Aug 2024 22:11:19 +0200 Subject: [PATCH 1/2] File upload: use preview options Fixes #5729 --- config/fields/mixins/upload.php | 6 +++++- config/sections/files.php | 1 + panel/src/components/Forms/Field/FilesField.vue | 1 + panel/src/components/Uploads/UploadItem.vue | 1 + .../components/Uploads/UploadItemPreview.vue | 17 +++++++++++++++-- panel/src/panel/upload.js | 8 ++++++-- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/config/fields/mixins/upload.php b/config/fields/mixins/upload.php index aad39338e4..a5b9962675 100644 --- a/config/fields/mixins/upload.php +++ b/config/fields/mixins/upload.php @@ -23,7 +23,11 @@ $uploads = []; } - $uploads['accept'] = '*'; + $uploads['accept'] = '*'; + + if ($preview = $this->image) { + $uploads['preview'] = $preview; + } if ($template = $uploads['template'] ?? null) { // get parent object for upload target diff --git a/config/sections/files.php b/config/sections/files.php index bb8532fb5d..35ff9e3eb9 100644 --- a/config/sections/files.php +++ b/config/sections/files.php @@ -194,6 +194,7 @@ 'multiple' => $multiple, 'max' => $max, 'api' => $this->parent->apiUrl(true) . '/files', + 'preview' => $this->image, 'attributes' => [ // TODO: an edge issue that needs to be solved: // if multiple users load the same section diff --git a/panel/src/components/Forms/Field/FilesField.vue b/panel/src/components/Forms/Field/FilesField.vue index fb03c6d3fb..76859ca22a 100644 --- a/panel/src/components/Forms/Field/FilesField.vue +++ b/panel/src/components/Forms/Field/FilesField.vue @@ -41,6 +41,7 @@ export default { accept: this.uploads.accept, max: this.max, multiple: this.multiple, + preview: this.uploads.preview, url: this.$panel.urls.api + "/" + this.endpoints.field + "/upload", on: { done: (files) => { diff --git a/panel/src/components/Uploads/UploadItem.vue b/panel/src/components/Uploads/UploadItem.vue index f2e66451c7..33dc827bc7 100644 --- a/panel/src/components/Uploads/UploadItem.vue +++ b/panel/src/components/Uploads/UploadItem.vue @@ -1,6 +1,7 @@