changeset 975:3da707172772

refac: removed technical debt Cleaned up mapstore to adhere more to Single Repsonsibility Principle (SRP)
author Thomas Junk <thomas.junk@intevation.de>
date Thu, 18 Oct 2018 16:47:17 +0200
parents 7a89313f0ead
children c397fdd8c327
files client/src/identify/Identify.vue client/src/identify/store.js client/src/linetool/Linetool.vue client/src/map/Maplayer.vue client/src/map/store.js client/src/morphtool/Morphtool.vue client/src/morphtool/store.js client/src/store.js
diffstat 8 files changed, 69 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/identify/Identify.vue	Thu Oct 18 15:11:49 2018 +0200
+++ b/client/src/identify/Identify.vue	Thu Oct 18 16:47:17 2018 +0200
@@ -89,7 +89,7 @@
     };
   },
   computed: {
-    ...mapState("mapstore", ["identifiedFeatures"]),
+    ...mapState("identifystore", ["identifiedFeatures"]),
     identifyStyle() {
       return {
         "ui-element": true,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/identify/store.js	Thu Oct 18 16:47:17 2018 +0200
@@ -0,0 +1,28 @@
+// note that some identified features may not have an id
+// especially related to drawing in our own vector layer
+
+const IndentifyStore = {
+  namespaced: true,
+  state: {
+    identifiedFeatures: [],
+    currentMeasurement: null
+  },
+  getters: {
+    identifiedFeatures: state => {
+      return state.identifiedFeatures;
+    },
+    currentMeasurement: state => {
+      return state.currentMeasurement;
+    }
+  },
+  mutations: {
+    setIdentifiedFeatures: (state, identifiedFeatures) => {
+      state.identifiedFeatures = identifiedFeatures;
+    },
+    setCurrentMeasurement: (state, measurement) => {
+      state.currentMeasurement = measurement;
+    }
+  }
+};
+
+export default IndentifyStore;
--- a/client/src/linetool/Linetool.vue	Thu Oct 18 15:11:49 2018 +0200
+++ b/client/src/linetool/Linetool.vue	Thu Oct 18 16:47:17 2018 +0200
@@ -37,7 +37,8 @@
   },
   computed: {
     ...mapGetters("application", ["drawMode"]),
-    ...mapState("mapstore", ["identifiedFeatures", "selectedMorph"]),
+    ...mapState("identifystore", ["identifiedFeatures", "selectedMorph"]),
+    ...mapState("morphstore", ["selectedMorph"]),
     icon() {
       return {
         fa: true,
--- a/client/src/map/Maplayer.vue	Thu Oct 18 15:11:49 2018 +0200
+++ b/client/src/map/Maplayer.vue	Thu Oct 18 16:47:17 2018 +0200
@@ -29,9 +29,7 @@
 import "ol/ol.css";
 import { Map, View } from "ol";
 import Feature from "ol/Feature";
-// import { bbox as bboxFilter } from "ol/format/filter.js";
 import { WFS, GeoJSON } from "ol/format.js";
-// import GeometryType from "ol/geom/GeometryType.js";
 import LineString from "ol/geom/LineString.js";
 import Point from "ol/geom/Point.js";
 import Draw from "ol/interaction/Draw.js";
@@ -45,7 +43,6 @@
   lineString as turfLineString,
   polygon as turfPolygon
 } from "@turf/helpers";
-//import { lineIntersect as turfLineIntersect } from "@turf/line-intersect";
 import lineIntersect from "@turf/line-intersect";
 import { displayError } from "../application/lib/errors.js";
 
@@ -66,7 +63,8 @@
   },
   computed: {
     ...mapGetters("mapstore", ["layers", "getLayerByName"]),
-    ...mapState("mapstore", ["openLayersMap", "selectedMorph"]),
+    ...mapState("mapstore", ["openLayersMap"]),
+    ...mapState("morphstore", ["selectedMorph"]),
     mapStyle() {
       return {
         mapfull: !this.split,
@@ -142,7 +140,7 @@
       });
       draw.on("drawstart", event => {
         this.vectorSource.clear();
-        this.$store.commit("mapstore/setCurrentMeasurement", null);
+        this.$store.commit("identifystore/setCurrentMeasurement", null);
         event.feature.setId("drawn.1"); // unique id for new feature
       });
       draw.on("drawend", this.drawEnd);
@@ -150,7 +148,7 @@
     },
     drawEnd(event) {
       const length = getLength(event.feature.getGeometry());
-      this.$store.commit("mapstore/setCurrentMeasurement", length);
+      this.$store.commit("identifystore/setCurrentMeasurement", length);
       // also place the a rounded length in a property, so identify can show it
       event.feature.set("length", Math.round(length * 10) / 10);
 
@@ -256,10 +254,10 @@
       });
     },
     identify(coordinate, pixel) {
-      this.$store.commit("mapstore/setIdentifiedFeatures", []);
+      this.$store.commit("identifystore/setIdentifiedFeatures", []);
       // checking our WFS layers
       var features = this.openLayersMap.getFeaturesAtPixel(pixel);
-      this.$store.commit("mapstore/setIdentifiedFeatures", features);
+      this.$store.commit("identifystore/setIdentifiedFeatures", features);
 
       // DEBUG output and example how to remove the GeometryName
       /*
--- a/client/src/map/store.js	Thu Oct 18 15:11:49 2018 +0200
+++ b/client/src/map/store.js	Thu Oct 18 16:47:17 2018 +0200
@@ -6,12 +6,7 @@
   namespaced: true,
   state: {
     openLayersMap: null,
-    layers: layers,
-    // note that some identified features may not have an id
-    // especially related to drawing in our own vector layer
-    identifiedFeatures: [],
-    currentMeasurement: null,
-    selectedMorph: null
+    layers: layers
   },
   getters: {
     layers: state => {
@@ -26,17 +21,8 @@
       state.layers[layer].isVisible = !state.layers[layer].isVisible;
       state.layers[layer].data.setVisible(state.layers[layer].isVisible);
     },
-    setIdentifiedFeatures: (state, identifiedFeatures) => {
-      state.identifiedFeatures = identifiedFeatures;
-    },
     setOpenLayersMap: (state, map) => {
       state.openLayersMap = map;
-    },
-    setCurrentMeasurement: (state, measurement) => {
-      state.currentMeasurement = measurement;
-    },
-    setSelectedMorph: (state, selectedMorph) => {
-      state.selectedMorph = selectedMorph;
     }
   }
 };
--- a/client/src/morphtool/Morphtool.vue	Thu Oct 18 15:11:49 2018 +0200
+++ b/client/src/morphtool/Morphtool.vue	Thu Oct 18 16:47:17 2018 +0200
@@ -93,14 +93,15 @@
   },
   computed: {
     ...mapGetters("application", ["drawMode"]),
-    ...mapState("mapstore", ["identifiedFeatures", "selectedMorph"]),
+    ...mapState("identifystore", ["identifiedFeatures"]),
+    ...mapState("morphstore", ["selectedMorph"]),
     selectedBottleneck: function() {
       if (this.identifiedFeatures && !this.drawMode) {
         for (let feature of this.identifiedFeatures) {
           let id = feature.getId();
           // RegExp.prototype.test() works with number, str and undefined
           if (/^bottlenecks\./.test(id)) {
-            this.$store.commit("mapstore/setSelectedMorph", null);
+            this.$store.commit("morphstore/setSelectedMorph", null);
             return feature;
           }
         }
@@ -140,12 +141,12 @@
         });
     },
     selectSurvey(survey) {
-      this.$store.commit("mapstore/setSelectedMorph", survey);
+      this.$store.commit("morphstore/setSelectedMorph", survey);
       this.surveyList = null;
     },
     clearSelection() {
-      this.$store.commit("mapstore/setIdentifiedFeatures", []);
-      this.$store.commit("mapstore/setSelectedMorph", null);
+      this.$store.commit("identifystore/setIdentifiedFeatures", []);
+      this.$store.commit("morphstore/setSelectedMorph", null);
       this.surveyList = null;
       if (this.drawMode) {
         this.$store.commit("application/toggleDrawModeLine");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/morphtool/store.js	Thu Oct 18 16:47:17 2018 +0200
@@ -0,0 +1,18 @@
+const MorphStore = {
+  namespaced: true,
+  state: {
+    selectedMorph: null
+  },
+  getters: {
+    selectedMorph: state => {
+      return state.selectedMorph;
+    }
+  },
+  mutations: {
+    setSelectedMorph: (state, selectedMorph) => {
+      state.selectedMorph = selectedMorph;
+    }
+  }
+};
+
+export default MorphStore;
--- a/client/src/store.js	Thu Oct 18 15:11:49 2018 +0200
+++ b/client/src/store.js	Thu Oct 18 16:47:17 2018 +0200
@@ -5,15 +5,19 @@
 import usermanagement from "./usermanagement/store";
 import mapstore from "./map/store";
 import FairwayProfile from "./fairway/store";
+import IdentifyStore from "./identify/store";
+import MorphStore from "./morphtool/store";
 
 Vue.use(Vuex);
 
 export default new Vuex.Store({
   modules: {
     application: Application,
+    fairwayprofile: FairwayProfile,
+    identifystore: IdentifyStore,
+    mapstore: mapstore,
+    morphstore: MorphStore,
     user: user,
-    usermanagement: usermanagement,
-    mapstore: mapstore,
-    fairwayprofile: FairwayProfile
+    usermanagement: usermanagement
   }
 });