changeset 4384:b146d3c648f8

gauges: decouple date and title from store
author Thomas Junk <thomas.junk@intevation.de>
date Thu, 12 Sep 2019 13:48:19 +0200
parents 59a7b7ec56c4
children 610773d34e4f
files client/src/components/gauge/Waterlevel.vue
diffstat 1 files changed, 18 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/gauge/Waterlevel.vue	Thu Sep 12 11:49:46 2019 +0200
+++ b/client/src/components/gauge/Waterlevel.vue	Thu Sep 12 13:48:19 2019 +0200
@@ -134,6 +134,9 @@
   },
   data() {
     return {
+      dateFromD: null,
+      dateToD: null,
+      selectedGaugeD: null,
       containerId: "waterlevel-diagram-container",
       resizeListenerFunction: null,
       form: {
@@ -155,25 +158,17 @@
     ...mapState("application", ["paneSetup"]),
     ...mapState("gauges", [
       "dateFrom",
+      "dateTo",
       "waterlevels",
       "waterlevelsCSV",
       "nashSutcliffe"
     ]),
     ...mapGetters("gauges", ["selectedGauge"]),
     title() {
-      return `${this.selectedGauge.properties.objname}: ${this.$gettext(
+      if (!this.selectedGaugeD) return;
+      return `${this.selectedGaugeD.properties.objname}: ${this.$gettext(
         "Waterlevel"
-      )} (${this.dateFrom.toLocaleDateString()} - ${this.dateTo.toLocaleDateString()})`;
-    },
-    dateFrom: {
-      get() {
-        return this.$store.state.gauges.dateFrom;
-      }
-    },
-    dateTo: {
-      get() {
-        return this.$store.state.gauges.dateTo;
-      }
+      )} (${this.dateFromD.toLocaleDateString()} - ${this.dateToD.toLocaleDateString()})`;
     },
     csvLink() {
       return (
@@ -183,8 +178,8 @@
     csvFileName() {
       return `${this.$gettext("waterlevels")}-${
         this.selectedGauge.properties.objname
-      }-${this.dateFrom.toISOString().split("T")[0]}-${
-        this.dateTo.toISOString().split("T")[0]
+      }-${this.dateFromD.toISOString().split("T")[0]}-${
+        this.dateToD.toISOString().split("T")[0]
       }.csv`;
     },
     hasPredictions() {
@@ -199,10 +194,16 @@
       this.$nextTick(() => this.drawDiagram());
     },
     waterlevels() {
+      this.initialDiagramValues();
       this.drawDiagram();
     }
   },
   methods: {
+    initialDiagramValues() {
+      this.dateFromD = this.dateFrom;
+      this.dateToD = this.dateTo;
+      this.selectedGaugeD = this.selectedGauge;
+    },
     close() {
       this.$store.commit(
         "application/paneSetup",
@@ -223,9 +224,9 @@
       let diagramTitle =
         this.gaugeInfo(this.selectedGauge) +
         ": Waterlevel " +
-        this.dateFrom.toLocaleDateString() +
+        this.dateFromD.toLocaleDateString() +
         " - " +
-        this.dateTo.toLocaleDateString();
+        this.dateToD.toLocaleDateString();
       this.generatePDF({
         templateData: this.templateData,
         diagramTitle: diagramTitle
@@ -1180,7 +1181,7 @@
     // not guarantee that the DOM is not only updated but also re-painted on the
     // screen.
     setTimeout(this.drawDiagram, 150);
-
+    this.initialDiagramValues();
     this.templates[0] = this.defaultTemplate;
     this.form.template = this.templates[0];
     this.templateData = this.form.template;