changeset 3143:8fdbc524e7b5

client: make the default template available to use even if backend provided templates
author Fadi Abbud <fadi.abbud@intevation.de>
date Fri, 03 May 2019 10:22:58 +0200
parents 2ea307abf80b
children 7d33eff62dc6
files client/src/components/gauge/Waterlevel.vue
diffstat 1 files changed, 40 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/gauge/Waterlevel.vue	Thu May 02 16:18:23 2019 +0200
+++ b/client/src/components/gauge/Waterlevel.vue	Fri May 03 10:22:58 2019 +0200
@@ -94,41 +94,41 @@
       scale: null,
       axes: null,
       form: {
-        template: null
+        template: null,
+        form: null
       },
-      templates: [
-        {
-          name: "Default",
-          properties: {
-            paperSize: "a4",
-            resolution: "80"
+      templates: [],
+      defaultTemplate: {
+        name: "Default",
+        properties: {
+          paperSize: "a4",
+          resolution: "80"
+        },
+        elements: [
+          {
+            type: "diagramlegend",
+            position: "topleft",
+            offset: { x: 30, y: 150 },
+            color: "black"
           },
-          elements: [
-            {
-              type: "diagramlegend",
-              position: "topleft",
-              offset: { x: 30, y: 150 },
-              color: "black"
-            },
-            {
-              type: "diagramtitle",
-              position: "topleft",
-              offset: { x: 50, y: 26 },
-              fontsize: 22,
-              color: "steelblue"
-            },
-            {
-              type: "text",
-              position: "topleft",
-              offset: { x: 3, y: 3 },
-              fontsize: 8,
-              width: 90,
-              color: "gray",
-              text: this.$gettext("Generated by") + " " + "{user}, {date}"
-            }
-          ]
-        }
-      ],
+          {
+            type: "diagramtitle",
+            position: "topleft",
+            offset: { x: 50, y: 26 },
+            fontsize: 22,
+            color: "steelblue"
+          },
+          {
+            type: "text",
+            position: "topleft",
+            offset: { x: 3, y: 3 },
+            fontsize: 8,
+            width: 90,
+            color: "gray",
+            text: this.$gettext("Generated by") + " " + "{user}, {date}"
+          }
+        ]
+      },
       pdf: {
         doc: null,
         width: 420,
@@ -252,6 +252,11 @@
       );
     },
     applyChange() {
+      if (this.form.template.hasOwnProperty("properties")) {
+        this.templateData = this.defaultTemplate;
+        this.form.paperSize = this.defaultTemplate.properties.paperSize;
+        return;
+      }
       if (this.form.template) {
         HTTP.get("/templates/print/" + this.form.template.name, {
           headers: {
@@ -1087,6 +1092,7 @@
   },
   mounted() {
     this.drawDiagram();
+    this.templates[0] = this.defaultTemplate;
     this.form.template = this.templates[0];
     this.templateData = this.form.template;
     HTTP.get("/templates/print", {
@@ -1099,6 +1105,7 @@
         if (response.data.length) {
           this.templates = response.data;
           this.form.template = this.templates[0];
+          this.templates[this.templates.length] = this.defaultTemplate;
           this.applyChange();
         }
       })