From bd61eedfbb344826a8646b0d0f4fcd58e03950af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 13 Mar 2025 17:03:14 +0100 Subject: [PATCH] Migrate export generation flow from plain JS to Vue Replaced the old JavaScript-based export generation logic with a Vue.js implementation to improve maintainability and modularity. Introduced a new API endpoint to fetch export status, updated the Webpack config, and integrated translations and Twig templates for the new flow. The Vue-based solution enhances user feedback and error handling during the export process. --- .../public/page/export/download-export.js | 14 -- .../public/vuejs/DownloadExport/App.vue | 129 ++++++++++++++++++ .../public/vuejs/DownloadExport/api.ts | 14 ++ .../public/vuejs/DownloadExport/index.ts | 12 ++ .../views/ExportGeneration/wait.html.twig | 23 ++++ .../ChillMainBundle/chill.api.specs.yaml | 22 +++ .../ChillMainBundle/chill.webpack.config.js | 3 +- .../translations/messages.fr.yml | 6 + 8 files changed, 208 insertions(+), 15 deletions(-) delete mode 100644 src/Bundle/ChillMainBundle/Resources/public/page/export/download-export.js create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/App.vue create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/api.ts create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/index.ts create mode 100644 src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig diff --git a/src/Bundle/ChillMainBundle/Resources/public/page/export/download-export.js b/src/Bundle/ChillMainBundle/Resources/public/page/export/download-export.js deleted file mode 100644 index 164e8e97e..000000000 --- a/src/Bundle/ChillMainBundle/Resources/public/page/export/download-export.js +++ /dev/null @@ -1,14 +0,0 @@ -import { download_report } from "../../lib/download-report/download-report"; - -window.addEventListener("DOMContentLoaded", function (e) { - const export_generate_url = window.export_generate_url; - - if (typeof export_generate_url === "undefined") { - console.error("Alias not found!"); - throw new Error("Alias not found!"); - } - - const query = window.location.search, - container = document.querySelector("#download_container"); - download_report(export_generate_url + query.toString(), container); -}); diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/App.vue new file mode 100644 index 000000000..308717bf8 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/App.vue @@ -0,0 +1,129 @@ + + + + + diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/api.ts b/src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/api.ts new file mode 100644 index 000000000..368d8849b --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/api.ts @@ -0,0 +1,14 @@ +import { StoredObject, StoredObjectStatus } from "ChillDocStoreAssets/types"; +import { makeFetch } from "ChillMainAssets/lib/api/apiMethods"; + +export const fetchExportGenerationStatus = async ( + exportGenerationId: string, +): Promise< + | { status: "pending" } + | { status: StoredObjectStatus; stored_object: StoredObject } +> => { + return makeFetch( + "GET", + `/api/1.0/main/export-generation/${exportGenerationId}/object`, + ); +}; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/index.ts b/src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/index.ts new file mode 100644 index 000000000..5addad73d --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/DownloadExport/index.ts @@ -0,0 +1,12 @@ +import { createApp } from "vue"; +import App from "./App.vue"; + +const el = document.getElementById("app"); + +if (null === el) { + console.error("div element app was not found"); + throw new Error("div element app was not found"); +} + +const exportGenerationId = el?.dataset.exportGenerationId as string; +createApp(App, { exportGenerationId }).mount(el); diff --git a/src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig b/src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig new file mode 100644 index 000000000..b605c04a9 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig @@ -0,0 +1,23 @@ +{% extends '@ChillMain/layout.html.twig' %} + +{% block js %} + {{ parent() }} + {{ encore_entry_script_tags('page_download_exports') }} +{% endblock %} + +{% block css %} + {{ parent() }} + {{ encore_entry_link_tags('page_download_exports') }} +{% endblock %} + +{% block content %} +
+ + +{% endblock content %} diff --git a/src/Bundle/ChillMainBundle/chill.api.specs.yaml b/src/Bundle/ChillMainBundle/chill.api.specs.yaml index 6236ba206..7a9341beb 100644 --- a/src/Bundle/ChillMainBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillMainBundle/chill.api.specs.yaml @@ -1101,3 +1101,25 @@ paths: 204: description: "resource was deleted successfully" + /1.0/main/export-generation/{id}/object: + get: + tags: + - export + summary: get the object status and details of an export-generation + parameters: + - name: id + in: path + required: true + description: The entity export generation id + schema: + type: string + format: uuid + responses: + 403: + description: Access denied + 200: + description: "ok" + content: + application/json: + schema: + type: object diff --git a/src/Bundle/ChillMainBundle/chill.webpack.config.js b/src/Bundle/ChillMainBundle/chill.webpack.config.js index 88b537932..a132ac008 100644 --- a/src/Bundle/ChillMainBundle/chill.webpack.config.js +++ b/src/Bundle/ChillMainBundle/chill.webpack.config.js @@ -34,7 +34,7 @@ module.exports = function (encore, entries) { ); encore.addEntry( "page_download_exports", - __dirname + "/Resources/public/page/export/download-export.js", + __dirname + "/Resources/public/vuejs/DownloadExport/index.ts", ); // Modules entrypoints @@ -120,4 +120,5 @@ module.exports = function (encore, entries) { "vue_onthefly", __dirname + "/Resources/public/vuejs/OnTheFly/index.js", ); + }; diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index 6c52d962f..c7f969d57 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -716,6 +716,12 @@ notification: export: + generation: + Export generation is pending: La génération de l'export est en cours + Come back later: Retour à l'index + Too many retries: Le nombre de vérification de la disponibilité de l'export a échoué. Essayez de recharger la page. + Error while generating export: Erreur interne lors de la génération de l'export + Export ready: L'export est prêt à être téléchargé address_helper: id: Identifiant de l'adresse street: Voie