changeset 3605:d02d4e31491b

sidebar: move staging notifications to store and update notifications after finishing review
author Thomas Junk <thomas.junk@intevation.de>
date Wed, 05 Jun 2019 11:48:15 +0200
parents 6248a4bc10c7
children a8190a570b71
files client/src/components/Sidebar.vue client/src/components/importoverview/ImportOverview.vue client/src/store/imports.js
diffstat 3 files changed, 23 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/Sidebar.vue	Wed Jun 05 11:39:25 2019 +0200
+++ b/client/src/components/Sidebar.vue	Wed Jun 05 11:48:15 2019 +0200
@@ -100,18 +100,13 @@
 import { mapGetters, mapState } from "vuex";
 import { logOff } from "@/lib/session";
 import { displayError } from "@/lib/errors";
-import { HTTP } from "@/lib/http";
 
 export default {
   name: "sidebar",
-  data() {
-    return {
-      stagingNotifications: null
-    };
-  },
   computed: {
     ...mapGetters("user", ["isSysAdmin", "isWaterwayAdmin"]),
     ...mapState("user", ["user", "roles", "isAuthenticated"]),
+    ...mapState("imports", ["stagingNotifications"]),
     ...mapState("application", [
       "showSidebar",
       "showSearchbarLastState",
@@ -150,12 +145,9 @@
   mounted() {
     const updateIndicators = () => {
       if (this.isWaterwayAdmin) {
-        this.$store;
-        HTTP.get("/imports?states=pending&count=true", {
-          headers: { "X-Gemma-Auth": localStorage.getItem("token") }
-        })
-          .then(response => {
-            this.stagingNotifications = response.data;
+        this.$store
+          .dispatch("imports/loadStagingNotifications")
+          .then(() => {
             if (this.isAuthenticated) {
               setTimeout(updateIndicators, 15000);
             }
--- a/client/src/components/importoverview/ImportOverview.vue	Wed Jun 05 11:39:25 2019 +0200
+++ b/client/src/components/importoverview/ImportOverview.vue	Wed Jun 05 11:48:15 2019 +0200
@@ -409,6 +409,7 @@
                 this.loadLogs();
                 this.$store.commit("imports/setReviewed", []);
                 this.$store.dispatch("map/refreshLayers");
+                this.$store.dispatch("imports/loadStagingNotifications");
                 const messages = response.data
                   .map(x => {
                     if (x.message) return x.message;
--- a/client/src/store/imports.js	Wed Jun 05 11:39:25 2019 +0200
+++ b/client/src/store/imports.js	Wed Jun 05 11:48:15 2019 +0200
@@ -43,6 +43,7 @@
     details: [],
     startDate: startOfHour(new Date()),
     endDate: endOfHour(new Date()),
+    stagingNotifications: null,
     prev: null,
     next: null
   };
@@ -98,6 +99,9 @@
     }
   },
   mutations: {
+    setStagingNotifications: (state, stagingNotifications) => {
+      state.stagingNotifications = stagingNotifications;
+    },
     setPrev: (state, prev) => {
       state.prev = prev;
     },
@@ -200,6 +204,20 @@
     }
   },
   actions: {
+    loadStagingNotifications({ commit }) {
+      return new Promise((resolve, reject) => {
+        HTTP.get("/imports?states=pending&count=true", {
+          headers: { "X-Gemma-Auth": localStorage.getItem("token") }
+        })
+          .then(response => {
+            commit("setStagingNotifications", response.data);
+            resolve(response);
+          })
+          .catch(error => {
+            reject(error);
+          });
+      });
+    },
     loadStretch(context, name) {
       return new Promise((resolve, reject) => {
         getFromWFS("stretches_geoserver", equalToFilter("name", name))