changeset 2265:940ae7c20326

client: pdf-gen: use default template when backend does not provide any
author Markus Kottlaender <markus@intevation.de>
date Thu, 14 Feb 2019 14:38:50 +0100
parents 627bfcbbf631
children 153c77e529dc
files client/src/components/Pdftool.vue client/src/components/fairway/Fairwayprofile.vue client/src/lib/geo.js client/src/store/fairway.js
diffstat 4 files changed, 51 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/Pdftool.vue	Thu Feb 14 13:53:54 2019 +0100
+++ b/client/src/components/Pdftool.vue	Thu Feb 14 14:38:50 2019 +0100
@@ -117,7 +117,37 @@
         downloadType: "download",
         resolution: "80"
       },
-      templates: [],
+      templates: [
+        {
+          name: "Default",
+          properties: {
+            format: "landscape",
+            paperSize: "a4",
+            resolution: "80"
+          },
+          elements: [
+            {
+              type: "scalebar",
+              position: "bottomright",
+              offset: { x: 2, y: 2 }
+            },
+            {
+              type: "textbox",
+              position: "bottomleft",
+              offset: { x: 2, y: 2 },
+              width: 60,
+              fontSize: 8,
+              text: "Generated by {user}, {date}"
+            },
+            {
+              type: "northarrow",
+              position: "topright",
+              offset: { x: 6, y: 4 },
+              size: 2
+            }
+          ]
+        }
+      ],
       templateData: null,
       pdf: {
         doc: null,
@@ -336,6 +366,7 @@
 
           this.pdf.doc.save("map.pdf");
         }
+
         // reset to original size
         map.setSize(mapSize);
         map.getView().fit(mapExtent, { size: mapSize });
@@ -794,6 +825,8 @@
     }
   },
   mounted() {
+    this.form.template = this.templates[0];
+    this.templateData = this.form.template;
     HTTP.get("/templates/print", {
       headers: {
         "X-Gemma-Auth": localStorage.getItem("token"),
@@ -801,9 +834,11 @@
       }
     })
       .then(response => {
-        this.templates = response.data;
-        this.form.template = this.templates[0];
-        this.applyTemplateToForm();
+        if (response.data.length) {
+          this.templates = response.data;
+          this.form.template = this.templates[0];
+          this.applyTemplateToForm();
+        }
       })
       .catch(e => {
         const { status, data } = e.response;
--- a/client/src/components/fairway/Fairwayprofile.vue	Thu Feb 14 13:53:54 2019 +0100
+++ b/client/src/components/fairway/Fairwayprofile.vue	Thu Feb 14 14:38:50 2019 +0100
@@ -243,7 +243,7 @@
     },
     drawFairway({ graph, xScale, yScaleRight }) {
       if (this.fairwayData === undefined) {
-        return
+        return;
       }
       for (let data of this.fairwayData) {
         const [startPoint, endPoint, depth] = data.coordinates[0];
--- a/client/src/lib/geo.js	Thu Feb 14 13:53:54 2019 +0100
+++ b/client/src/lib/geo.js	Thu Feb 14 14:38:50 2019 +0100
@@ -189,10 +189,14 @@
   var polygon = turfPolygon(fairwayGeometry.getCoordinates());
   var intersects = lineIntersect(line, polygon);
 
-  var startPoint, endPoint
+  var startPoint, endPoint;
 
   if (intersects.features.length == 2) {
-    let line1 = lineSlice(intersects.features[0].geometry, intersects.features[1].geometry, line);
+    let line1 = lineSlice(
+      intersects.features[0].geometry,
+      intersects.features[1].geometry,
+      line
+    );
     startPoint = line1.geometry.coordinates[0];
     endPoint = line1.geometry.coordinates[1];
   } else if (booleanWithin(line, polygon)) {
@@ -201,11 +205,11 @@
   } else {
     let split = lineSplit(line, polygon);
     for (let feature of split.features) {
-      if (booleanWithin(feature, polygon)){
+      if (booleanWithin(feature, polygon)) {
         startPoint = feature.geometry.coordinates[0];
         endPoint = feature.geometry.coordinates[1];
       }
-      if (booleanContains(polygon, feature)){
+      if (booleanContains(polygon, feature)) {
         startPoint = feature.geometry.coordinates[0];
         endPoint = feature.geometry.coordinates[1];
       }
--- a/client/src/store/fairway.js	Thu Feb 14 13:53:54 2019 +0100
+++ b/client/src/store/fairway.js	Thu Feb 14 14:38:50 2019 +0100
@@ -175,7 +175,7 @@
           },
           { root: true }
         );
-        commit("clearFairwayData")
+        commit("clearFairwayData");
         // if a survey has been selected, request a profile
         // TODO an improvement could be to check if the line intersects
         // with the bottleneck area's polygon before trying the server request
@@ -299,6 +299,6 @@
           })
           .sort((a, b) => (a.timestamp < b.timestamp ? 1 : -1))
       );
-    },
-  },
+    }
+  }
 };