diff client/src/lib/mixins.js @ 4677:fa55e48bbca1

client: improve filename generation for downloads * unify filename for the generated csv files * move function to mixins.js * mark strings in filename for translations * replace whitespace with "-"
author Fadi Abbud <fadi.abbud@intevation.de>
date Tue, 15 Oct 2019 17:16:36 +0200
parents e58fc3a62118
children 9412bc2545e8
line wrap: on
line diff
--- a/client/src/lib/mixins.js	Tue Oct 15 16:28:46 2019 +0200
+++ b/client/src/lib/mixins.js	Tue Oct 15 17:16:36 2019 +0200
@@ -19,6 +19,7 @@
 import { mapState } from "vuex";
 import { HTTP } from "@/lib/http";
 import * as d3 from "d3";
+import sanitize from "sanitize-filename";
 
 /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "[debugSVG|_]" }]*/
 const debugSVG = ({ svg, svgWidth, svgHeight }) => {
@@ -95,6 +96,12 @@
 
 export const templateLoader = {
   methods: {
+    downloadFilename(type, name) {
+      return `${type}-${sanitize(name).replace(
+        / /g,
+        "-"
+      )}-${this.dateForPDF()}`;
+    },
     loadTemplates(url) {
       return new Promise((resolve, reject) => {
         HTTP.get(url, {