Mercurial > gemma
comparison client/src/components/importoverview/ImportOverview.vue @ 4498:8763da6bef4a
export imports
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 30 Sep 2019 15:28:15 +0200 |
parents | b4880e7d4082 |
children | df91a747872c |
comparison
equal
deleted
inserted
replaced
4497:ca7f9c56697a | 4498:8763da6bef4a |
---|---|
229 this.loadLogs(); | 229 this.loadLogs(); |
230 } | 230 } |
231 }, | 231 }, |
232 methods: { | 232 methods: { |
233 saveImportsView() { | 233 saveImportsView() { |
234 let element = document.createElement("a"); | 234 const content = ""; |
235 element.setAttribute("download", "log.txt"); | 235 this.$store.commit("application/popup", { |
236 element.setAttribute("href", this.csvLink()); | 236 icon: "clipboard-check", |
237 element.click(); | 237 title: this.$gettext("Export logs"), |
238 }, | 238 padding: false, |
239 csvLink() { | 239 big: true, |
240 return ( | 240 content: content, |
241 "data:text/csv;charset=utf-8," + | 241 confirm: { |
242 encodeURIComponent( | 242 icon: "check", |
243 this.imports | 243 callback: dates => { |
244 .map(el => { | 244 const { from, to } = dates; |
245 return ` ${el.id}, ${el.kind}, ${el.enqueued}, ${el.user || | 245 HTTP.get( |
246 " "}, ${el.country || " "}, ${el.signer || " "}, ${el.state || | 246 `/imports?from=${encodeURIComponent( |
247 " "}, ${el.warnings || " "}`; | 247 format(startOfDay(new Date(from)), "YYYY-MM-DDTHH:mm:ssZ") |
248 }) | 248 )}&to=${encodeURIComponent( |
249 .join("\n") | 249 format(endOfDay(new Date(to)), "YYYY-MM-DDTHH:mm:ssZ") |
250 ) | 250 )}&query=`, |
251 ); | 251 { |
252 headers: { "X-Gemma-Auth": localStorage.getItem("token") } | |
253 } | |
254 ) | |
255 .then(response => { | |
256 const { imports } = response.data; | |
257 if (!imports) return; | |
258 const csvLink = | |
259 "data:text/csv;charset=utf-8," + | |
260 encodeURIComponent( | |
261 "id, kind, enqueued, user, country, signer, state, warnings\n" + | |
262 imports | |
263 .map(el => { | |
264 return ` ${el.id}, ${el.kind}, ${ | |
265 el.enqueued | |
266 }, ${el.user || " "}, ${el.country || | |
267 " "}, ${el.signer || " "}, ${el.state || | |
268 " "}, ${el.warnings || " "}`; | |
269 }) | |
270 .join("\n") | |
271 ); | |
272 let element = document.createElement("a"); | |
273 element.setAttribute("download", "log.txt"); | |
274 element.setAttribute("href", csvLink); | |
275 element.click(); | |
276 }) | |
277 .catch(error => { | |
278 const { status, data } = error.response; | |
279 displayError({ | |
280 title: this.$gettext("Backend Error"), | |
281 message: `${status}: ${data.message || data}` | |
282 }); | |
283 }); | |
284 } | |
285 }, | |
286 cancel: { | |
287 label: this.$gettext("Cancel"), | |
288 icon: "times" | |
289 }, | |
290 dateSelection: true | |
291 }); | |
252 }, | 292 }, |
253 showSingleRessource(id) { | 293 showSingleRessource(id) { |
254 id = id * 1; | 294 id = id * 1; |
255 this.loadDetails(id) | 295 this.loadDetails(id) |
256 .then(response => { | 296 .then(response => { |