changeset 3140:91556825d95c

client: implement geting templates from backend for waterlevel diagram
author Fadi Abbud <fadi.abbud@intevation.de>
date Thu, 02 May 2019 12:59:52 +0200
parents 5daaabc2e7fc
children 42324626f9e2
files client/src/components/gauge/Waterlevel.vue
diffstat 1 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/gauge/Waterlevel.vue	Thu May 02 11:35:23 2019 +0200
+++ b/client/src/components/gauge/Waterlevel.vue	Thu May 02 12:59:52 2019 +0200
@@ -16,6 +16,7 @@
       </div>
       <div>
         <select
+          @change="applyChange"
           v-model="form.template"
           class="form-control d-block custom-select-sm w-100"
         >
@@ -71,6 +72,8 @@
 import jsPDF from "jspdf";
 import canvg from "canvg";
 import { pdfgen } from "@/lib/mixins";
+import { HTTP } from "@/lib/http";
+import { displayError } from "@/lib/errors";
 // we should load only d3 modules we need but for now we'll go with the lazy way
 // https://www.giacomodebidda.com/how-to-import-d3-plugins-with-webpack/
 // d3-line-chunked plugin: https://github.com/pbeshai/d3-line-chunked
@@ -220,6 +223,26 @@
         this.selectedGauge.properties.objname + " Waterlevel-Diagram.pdf"
       );
     },
+    applyChange() {
+      if (this.form.template) {
+        HTTP.get("/templates/print/" + this.form.template.name, {
+          headers: {
+            "X-Gemma-Auth": localStorage.getItem("token"),
+            "Content-type": "text/xml; charset=UTF-8"
+          }
+        })
+          .then(response => {
+            this.templateData = response.data.template_data;
+          })
+          .catch(e => {
+            const { status, data } = e.response;
+            displayError({
+              title: this.$gettext("Backend Error"),
+              message: `${status}: ${data.message || data}`
+            });
+          });
+      }
+    },
     // Gauge info as a title for pdf
     addDiagramTitle(position, offset, size, color) {
       let gaugeInfo =
@@ -1037,6 +1060,26 @@
     this.drawDiagram();
     this.form.template = this.templates[0];
     this.templateData = this.form.template;
+    HTTP.get("/templates/print", {
+      headers: {
+        "X-Gemma-Auth": localStorage.getItem("token"),
+        "Content-type": "text/xml; charset=UTF-8"
+      }
+    })
+      .then(response => {
+        if (response.data.length) {
+          this.templates = response.data;
+          this.form.template = this.templates[0];
+          this.applyChange();
+        }
+      })
+      .catch(e => {
+        const { status, data } = e.response;
+        displayError({
+          title: this.$gettext("Backend Error"),
+          message: `${status}: ${data.message || data}`
+        });
+      });
   },
   updated() {
     this.drawDiagram();