From 118ae291e2721b40fd1a42950f73a5d7e68b0c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 8 Oct 2024 15:15:15 +0200 Subject: [PATCH] Add direct download link feature with new button implementation Introduce a new feature that allows for direct download links by integrating TempUrlGeneratorInterface. Added new DOWNLOAD_LINK_ONLY group and corresponding logic to generate download links in StoredObjectNormalizer. Implement a new Twig filter and Vue component for rendering the download button. Updated tests to cover the new functionality. --- .../public/module/button_download/index.ts | 27 ++++++++++ .../Resources/public/types.ts | 2 + .../StoredObjectButton/DownloadButton.vue | 41 +++++++++++---- .../vuejs/StoredObjectButton/helpers.ts | 9 +++- .../views/Button/button_download.html.twig | 1 + .../Normalizer/StoredObjectNormalizer.php | 26 ++++++++++ .../Templating/WopiEditTwigExtension.php | 4 ++ .../WopiEditTwigExtensionRuntime.php | 12 +++++ .../Normalizer/StoredObjectNormalizerTest.php | 50 ++++++++++++++++++- .../chill.webpack.config.js | 3 +- 10 files changed, 162 insertions(+), 13 deletions(-) create mode 100644 src/Bundle/ChillDocStoreBundle/Resources/public/module/button_download/index.ts create mode 100644 src/Bundle/ChillDocStoreBundle/Resources/views/Button/button_download.html.twig diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/module/button_download/index.ts b/src/Bundle/ChillDocStoreBundle/Resources/public/module/button_download/index.ts new file mode 100644 index 000000000..9ffe696c7 --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/module/button_download/index.ts @@ -0,0 +1,27 @@ +import {_createI18n} from "../../../../../ChillMainBundle/Resources/public/vuejs/_js/i18n"; +import {createApp} from "vue"; +import DocumentActionButtonsGroup from "../../vuejs/DocumentActionButtonsGroup.vue"; +import {StoredObject, StoredObjectStatusChange} from "../../types"; +import {defineComponent} from "vue"; +import DownloadButton from "../../vuejs/StoredObjectButton/DownloadButton.vue"; +import ToastPlugin from "vue-toast-notification"; + + + +const i18n = _createI18n({}); + +window.addEventListener('DOMContentLoaded', function (e) { + document.querySelectorAll('div[data-download-button-single]').forEach((el) => { + const storedObject = JSON.parse(el.dataset.storedObject as string) as StoredObject; + const title = el.dataset.title as string; + const app = createApp({ + components: {DownloadButton}, + data() { + return {storedObject, title, classes: {btn: true, "btn-outline-primary": true}}; + }, + template: '', + }); + + app.use(i18n).use(ToastPlugin).mount(el); + }); +}); diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/types.ts b/src/Bundle/ChillDocStoreBundle/Resources/public/types.ts index f93e9c5b7..2a998fb63 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/public/types.ts +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/types.ts @@ -2,6 +2,7 @@ import { DateTime, User, } from "../../../ChillMainBundle/Resources/public/types"; +import {SignedUrlGet} from "./vuejs/StoredObjectButton/helpers"; export type StoredObjectStatus = "empty" | "ready" | "failure" | "pending"; @@ -30,6 +31,7 @@ export interface StoredObject { href: string; expiration: number; }; + downloadLink?: SignedUrlGet; }; } diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/DownloadButton.vue b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/DownloadButton.vue index d1efabcee..ecf9055af 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/DownloadButton.vue +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/DownloadButton.vue @@ -1,5 +1,5 @@