changeset 1980:c8e2f6838eaf

define stretches: mark stretches in review
author Thomas Junk <thomas.junk@intevation.de>
date Wed, 23 Jan 2019 14:17:14 +0100
parents 0bc0312105e4
children e89368aec538
files client/src/components/ImportStretches.vue client/src/store/imports.js
diffstat 2 files changed, 91 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/ImportStretches.vue	Wed Jan 23 12:26:09 2019 +0100
+++ b/client/src/components/ImportStretches.vue	Wed Jan 23 14:17:14 2019 +0100
@@ -18,7 +18,20 @@
         <tbody>
           <tr class="small" v-for="(stretch, index) in stretches" :key="index">
             <td class="">
-              <a @click="moveMapToStretch(index)" href="#">{{
+              <a
+                class="linkto text-info"
+                v-if="isInStaging(stretch.properties.name)"
+                @click="gotoStaging(getStagingLink(stretch.properties.name))"
+              >
+                {{ stretch.properties.name
+                }}<font-awesome-icon
+                  class="ml-1 text-danger"
+                  icon="exclamation-triangle"
+                  fixed-width
+                ></font-awesome-icon
+                ><small class="ml-1">review</small>
+              </a>
+              <a v-else @click="moveMapToStretch(index)" href="#">{{
                 stretch.properties.name
               }}</a>
             </td>
@@ -59,6 +72,7 @@
               placeholder="AT_Section_12"
               aria-label="id"
               v-model="id"
+              :disabled="!idEditable"
             />
             <span class="text-left text-danger">
               <small v-if="idError && !id">
@@ -261,6 +275,7 @@
   data() {
     return {
       edit: false,
+      idEditable: true,
       id: "",
       funktion: "",
       startrhm: "",
@@ -285,9 +300,48 @@
   },
   mounted() {
     this.edit = false;
-    this.loadStretches();
+    this.loadStretches().catch(error => {
+      const { status, data } = error.response;
+      displayError({
+        title: this.$gettext("Backend Error"),
+        message: `${status}: ${data.message || data}`
+      });
+    });
+    this.loadStagingData().catch(error => {
+      const { status, data } = error.response;
+      displayError({
+        title: this.$gettext("Backend Error"),
+        message: `${status}: ${data.message || data}`
+      });
+    });
   },
   methods: {
+    gotoStaging(id) {
+      this.$router.push("/?review=" + id);
+    },
+    isInStaging(stretchname) {
+      for (let s of this.stretchesInStaging) {
+        if (s.name == stretchname) return true;
+      }
+      return false;
+    },
+    getStagingLink(stretchname) {
+      for (let s of this.stretchesInStaging) {
+        if (s.name == stretchname) return s.id;
+      }
+    },
+    loadStagingData() {
+      return new Promise((resolve, reject) => {
+        this.$store
+          .dispatch("imports/getStaging")
+          .then(response => {
+            resolve(response);
+          })
+          .catch(error => {
+            reject(error);
+          });
+      });
+    },
     editStretch(index) {
       const properties = this.stretches[index].properties;
       this.date_info = properties.date_info.split("T")[0];
@@ -299,6 +353,7 @@
       this.edit = true;
       this.startrhm = this.sanitizeRHM(properties.lower);
       this.endrhm = this.sanitizeRHM(properties.upper);
+      this.idEditable = false;
     },
     deleteStretch(index) {
       displayInfo({
@@ -318,16 +373,21 @@
       return formatSurveyDate(d);
     },
     loadStretches() {
-      this.$store.dispatch("imports/loadStretches").catch(error => {
-        const { status, data } = error.response;
-        displayError({
-          title: this.$gettext("Backend Error"),
-          message: `${status}: ${data.message || data}`
-        });
+      return new Promise((resolve, reject) => {
+        this.$store
+          .dispatch("imports/loadStretches")
+          .then(response => {
+            resolve(response);
+          })
+          .catch(error => {
+            reject(error);
+          });
       });
     },
     clean() {
       this.id = "";
+      this.edit = false;
+      this.idEditable = true;
       this.funktion = "";
       this.startrhm = "";
       this.endrhm = "";
@@ -415,11 +475,11 @@
             message: this.$gettext("Starting import of stretch")
           });
           this.clean();
-          this.edit = false;
-          this.loadStretches();
+          this.loadStretches().then(() => {
+            this.edit = false;
+          });
         })
         .catch(error => {
-          console.log(error);
           const { status, data } = error.response;
           displayError({
             title: this.$gettext("Backend Error"),
@@ -436,7 +496,6 @@
       const filterDistanceMarks = x => {
         return /^distance_marks/.test(x["id_"]);
       };
-      console.log(this.identifiedFeatures);
       const distanceMark = this.identifiedFeatures.filter(filterDistanceMarks);
       if (distanceMark.length > 0) {
         const value = this.sanitizeRHM(distanceMark[0]["id_"].split(".")[1]);
@@ -450,7 +509,18 @@
   computed: {
     ...mapState("map", ["identifiedFeatures", "currentMeasurement"]),
     ...mapGetters("user", ["isSysAdmin"]),
-    ...mapState("imports", ["stretches"]),
+    ...mapState("imports", ["stretches", "staging"]),
+    stretchesInStaging() {
+      const result = [];
+      for (let stretch of this.stretches) {
+        for (let s of this.staging) {
+          if (s.kind == "st" && s.summary.stretch == stretch.properties.name) {
+            result.push({ name: s.summary.stretch, id: s.id });
+          }
+        }
+      }
+      return result;
+    },
     pointsValid() {
       if (!this.startrhm || !this.endrhm) return true;
       const start = this.startrhm.replace(/\D+/, "") * 1;
@@ -462,4 +532,8 @@
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="scss" scoped>
+.linkto {
+  cursor: pointer;
+}
+</style>
--- a/client/src/store/imports.js	Wed Jan 23 12:26:09 2019 +0100
+++ b/client/src/store/imports.js	Wed Jan 23 14:17:14 2019 +0100
@@ -15,6 +15,7 @@
 import { HTTP } from "@/lib/http";
 import Vue from "vue";
 import { WFS } from "ol/format.js";
+import { equalTo as equalToFilter } from "ol/format/filter.js";
 
 /* eslint-disable no-unused-vars */
 /* eslint-disable no-unreachable */
@@ -222,7 +223,8 @@
           featureNS: "gemma",
           featurePrefix: "gemma",
           featureTypes: ["stretches_geoserver"],
-          outputFormat: "application/json"
+          outputFormat: "application/json",
+          filter: equalToFilter("staging_done", true)
         });
         HTTP.post(
           "/internal/wfs",