Refactor export download script to use ES6 and webpack

The export download script was refactored to use ES6 syntax and webpack's modular system. This included separating out the download script into its own file for better organization, removing globally-scoped JavaScript, and adding the new download script as a webpack entry point. Also, the import method for the 'mime' library was adjusted to use ES6 syntax.
This commit is contained in:
Julien Fastré 2024-06-04 21:51:42 +02:00
parent 84ce8a93f3
commit 59f721934e
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
4 changed files with 26 additions and 12 deletions

View File

@ -15,9 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
var mime = require('mime') import mime from 'mime';
var download_report = (url, container) => { export const download_report = (url, container) => {
var download_text = container.dataset.downloadText, var download_text = container.dataset.downloadText,
alias = container.dataset.alias; alias = container.dataset.alias;
@ -63,5 +63,3 @@ var download_report = (url, container) => {
.replaceChild(problem_text, container.firstChild); .replaceChild(problem_text, container.firstChild);
}); });
}; };
module.exports = download_report;

View File

@ -0,0 +1,16 @@
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);
});

View File

@ -22,15 +22,13 @@
{% block js %} {% block js %}
<script type="text/javascript"> <script type="text/javascript">
window.addEventListener("DOMContentLoaded", function(e) { window.export_generate_url = "{{ path('chill_main_export_generate', { 'alias' : alias } ) }}";
var url = "{{ path('chill_main_export_generate', { 'alias' : alias } ) }}",
query = window.location.search,
container = document.querySelector("#download_container")
;
chill.download_report(url+query, container);
});
</script> </script>
{{ encore_entry_link_tags('page_download_exports') }}
{% endblock %}
{% block css %}
{{ encore_entry_script_tags('page_download_exports') }}
{% endblock %} {% endblock %}
{% block content %} {% block content %}

View File

@ -52,12 +52,14 @@ module.exports = function(encore, entries)
Tabs: __dirname + '/Resources/public/lib/tabs' Tabs: __dirname + '/Resources/public/lib/tabs'
}); });
// Page entrypoints // Page entrypoints
encore.addEntry('page_login', __dirname + '/Resources/public/page/login/index.js'); encore.addEntry('page_login', __dirname + '/Resources/public/page/login/index.js');
encore.addEntry('page_location', __dirname + '/Resources/public/page/location/index.js'); encore.addEntry('page_location', __dirname + '/Resources/public/page/location/index.js');
encore.addEntry('page_workflow_show', __dirname + '/Resources/public/page/workflow-show/index.js'); encore.addEntry('page_workflow_show', __dirname + '/Resources/public/page/workflow-show/index.js');
encore.addEntry('page_homepage_widget', __dirname + '/Resources/public/page/homepage_widget/index.js'); encore.addEntry('page_homepage_widget', __dirname + '/Resources/public/page/homepage_widget/index.js');
encore.addEntry('page_export', __dirname + '/Resources/public/page/export/index.js'); encore.addEntry('page_export', __dirname + '/Resources/public/page/export/index.js');
encore.addEntry('page_download_exports', __dirname + '/Resources/public/page/export/download-export.js');
buildCKEditor(encore); buildCKEditor(encore);