Mercurial > gemma
comparison 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 |
comparison
equal
deleted
inserted
replaced
4676:5b9ba358a4e7 | 4677:fa55e48bbca1 |
---|---|
17 import svg2pdf from "svg2pdf.js"; | 17 import svg2pdf from "svg2pdf.js"; |
18 import locale2 from "locale2"; | 18 import locale2 from "locale2"; |
19 import { mapState } from "vuex"; | 19 import { mapState } from "vuex"; |
20 import { HTTP } from "@/lib/http"; | 20 import { HTTP } from "@/lib/http"; |
21 import * as d3 from "d3"; | 21 import * as d3 from "d3"; |
22 import sanitize from "sanitize-filename"; | |
22 | 23 |
23 /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "[debugSVG|_]" }]*/ | 24 /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "[debugSVG|_]" }]*/ |
24 const debugSVG = ({ svg, svgWidth, svgHeight }) => { | 25 const debugSVG = ({ svg, svgWidth, svgHeight }) => { |
25 d3.select(svg) | 26 d3.select(svg) |
26 .append("rect") | 27 .append("rect") |
93 } | 94 } |
94 }; | 95 }; |
95 | 96 |
96 export const templateLoader = { | 97 export const templateLoader = { |
97 methods: { | 98 methods: { |
99 downloadFilename(type, name) { | |
100 return `${type}-${sanitize(name).replace( | |
101 / /g, | |
102 "-" | |
103 )}-${this.dateForPDF()}`; | |
104 }, | |
98 loadTemplates(url) { | 105 loadTemplates(url) { |
99 return new Promise((resolve, reject) => { | 106 return new Promise((resolve, reject) => { |
100 HTTP.get(url, { | 107 HTTP.get(url, { |
101 headers: { | 108 headers: { |
102 "X-Gemma-Auth": localStorage.getItem("token"), | 109 "X-Gemma-Auth": localStorage.getItem("token"), |