Mercurial > gemma
changeset 4498:8763da6bef4a
export imports
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 30 Sep 2019 15:28:15 +0200 |
parents | ca7f9c56697a |
children | df91a747872c |
files | client/src/components/Popup.vue client/src/components/importoverview/ImportOverview.vue |
diffstat | 2 files changed, 92 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/components/Popup.vue Mon Sep 30 13:41:39 2019 +0200 +++ b/client/src/components/Popup.vue Mon Sep 30 15:28:15 2019 +0200 @@ -14,6 +14,23 @@ :class="{ 'p-3': popup.padding !== false }" v-html="popup.content" ></div> + <div + v-if="popup.dateSelection" + class="dateselection d-flex flex-column mx-2" + > + <div class="d-flex flex-column text-left"> + <small class="my-auto text-muted"> + <translate>From</translate> + </small> + <input type="date" v-model="from" /> + </div> + <div class="text-left d-flex flex-column"> + <small class="my-auto text-muted"> + <translate>To</translate> + </small> + <input type="date" v-model="to" /> + </div> + </div> <div class="popup-footer" v-if="popup.cancel || popup.confirm"> <button class="btn btn-sm btn-warning" @@ -49,6 +66,8 @@ </template> <style lang="sass" scoped> +.dateselection + width: 250px .overlay position: fixed z-index: 9 @@ -111,16 +130,30 @@ */ import { mapState } from "vuex"; +import { format, subMonths } from "date-fns"; + +const isoFormat = date => { + return format(date, "YYYY-MM-DD"); +}; export default { name: "popup", + data() { + return { + from: isoFormat(subMonths(new Date(), 1)), + to: isoFormat(new Date()) + }; + }, computed: { ...mapState("application", ["popup"]) }, methods: { confirm() { if (this.popup.confirm && this.popup.confirm.callback) - this.popup.confirm.callback(); + this.popup.confirm.callback({ + from: this.from, + to: this.to + }); this.close(); }, cancel() {
--- a/client/src/components/importoverview/ImportOverview.vue Mon Sep 30 13:41:39 2019 +0200 +++ b/client/src/components/importoverview/ImportOverview.vue Mon Sep 30 15:28:15 2019 +0200 @@ -231,24 +231,64 @@ }, methods: { saveImportsView() { - let element = document.createElement("a"); - element.setAttribute("download", "log.txt"); - element.setAttribute("href", this.csvLink()); - element.click(); - }, - csvLink() { - return ( - "data:text/csv;charset=utf-8," + - encodeURIComponent( - this.imports - .map(el => { - return ` ${el.id}, ${el.kind}, ${el.enqueued}, ${el.user || - " "}, ${el.country || " "}, ${el.signer || " "}, ${el.state || - " "}, ${el.warnings || " "}`; - }) - .join("\n") - ) - ); + const content = ""; + this.$store.commit("application/popup", { + icon: "clipboard-check", + title: this.$gettext("Export logs"), + padding: false, + big: true, + content: content, + confirm: { + icon: "check", + callback: dates => { + const { from, to } = dates; + HTTP.get( + `/imports?from=${encodeURIComponent( + format(startOfDay(new Date(from)), "YYYY-MM-DDTHH:mm:ssZ") + )}&to=${encodeURIComponent( + format(endOfDay(new Date(to)), "YYYY-MM-DDTHH:mm:ssZ") + )}&query=`, + { + headers: { "X-Gemma-Auth": localStorage.getItem("token") } + } + ) + .then(response => { + const { imports } = response.data; + if (!imports) return; + const csvLink = + "data:text/csv;charset=utf-8," + + encodeURIComponent( + "id, kind, enqueued, user, country, signer, state, warnings\n" + + imports + .map(el => { + return ` ${el.id}, ${el.kind}, ${ + el.enqueued + }, ${el.user || " "}, ${el.country || + " "}, ${el.signer || " "}, ${el.state || + " "}, ${el.warnings || " "}`; + }) + .join("\n") + ); + let element = document.createElement("a"); + element.setAttribute("download", "log.txt"); + element.setAttribute("href", csvLink); + element.click(); + }) + .catch(error => { + const { status, data } = error.response; + displayError({ + title: this.$gettext("Backend Error"), + message: `${status}: ${data.message || data}` + }); + }); + } + }, + cancel: { + label: this.$gettext("Cancel"), + icon: "times" + }, + dateSelection: true + }); }, showSingleRessource(id) { id = id * 1;