changeset 2654:3c04c8e46bd4

importoverview: reload reloads current selection
author Thomas Junk <thomas.junk@intevation.de>
date Thu, 14 Mar 2019 15:37:10 +0100
parents 7fd47d9641ac
children 501967471981 0d2650dd8f62
files client/src/components/importoverview/Filters.vue client/src/components/importoverview/ImportOverview.vue client/src/store/imports.js
diffstat 3 files changed, 60 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/importoverview/Filters.vue	Thu Mar 14 15:03:49 2019 +0100
+++ b/client/src/components/importoverview/Filters.vue	Thu Mar 14 15:37:10 2019 +0100
@@ -19,47 +19,37 @@
 </template>
 
 <script>
+/* This is Free Software under GNU Affero General Public License v >= 3.0
+ * without warranty, see README.md and license for details.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ * License-Filename: LICENSES/AGPL-3.0.txt
+ *
+ * Copyright (C) 2018 by via donau
+ *   – Österreichische Wasserstraßen-Gesellschaft mbH
+ * Software engineering by Intevation GmbH
+ *
+ * Author(s):
+ * Thomas Junk <thomas.junk@intevation.de>
+ */
+import { mapState } from "vuex";
+
 export default {
   name: "importfilters",
-  data() {
-    return {
-      failed: false,
-      pending: false,
-      accepted: false,
-      declined: false,
-      warning: false
-    };
-  },
   methods: {
     setFilter(name) {
       if (this.loading) return;
-      this[name] = !this[name];
-      const allSet =
-        this.failed &&
-        this.pending &&
-        this.accepted &&
-        this.declined &&
-        this.warning;
-      if (allSet) {
-        this.warning = false;
-        this.successful = false;
-        this.failed = false;
-        this.pending = false;
-        this.accepted = false;
-        this.declined = false;
-        this.$store.commit("imports/clearFilers");
-      }
-      const filters = [
-        "failed",
-        "pending",
-        "accepted",
-        "declined",
-        "warning"
-      ].filter(x => this[x]);
-      this.$store.commit("imports/setFilters", filters);
+      this.$store.commit("imports/toggleFilter", name);
     }
   },
   computed: {
+    ...mapState("imports", [
+      "pending",
+      "failed",
+      "accepted",
+      "warning",
+      "declined"
+    ]),
     pendingStyle() {
       return {
         btn: true,
--- a/client/src/components/importoverview/ImportOverview.vue	Thu Mar 14 15:03:49 2019 +0100
+++ b/client/src/components/importoverview/ImportOverview.vue	Thu Mar 14 15:37:10 2019 +0100
@@ -63,7 +63,7 @@
  * Thomas Junk <thomas.junk@intevation.de>
  */
 
-import { mapState } from "vuex";
+import { mapState, mapGetters } from "vuex";
 import { displayError, displayInfo } from "@/lib/errors.js";
 import { STATES } from "@/store/imports.js";
 
@@ -79,13 +79,14 @@
     };
   },
   computed: {
-    ...mapState("imports", ["imports", "filters", "reviewed"])
+    ...mapState("imports", ["imports", "reviewed"]),
+    ...mapGetters("imports", ["filters"])
   },
   methods: {
     loadLogs() {
       this.loading = true;
       this.$store
-        .dispatch("imports/getImports")
+        .dispatch("imports/getImports", this.filters)
         .then(() => {
           this.loading = false;
         })
--- a/client/src/store/imports.js	Thu Mar 14 15:03:49 2019 +0100
+++ b/client/src/store/imports.js	Thu Mar 14 15:37:10 2019 +0100
@@ -29,7 +29,11 @@
 // initial state
 const init = () => {
   return {
-    filters: [],
+    failed: false,
+    pending: false,
+    accepted: false,
+    declined: false,
+    warning: false,
     stretches: [],
     imports: [],
     reviewed: [],
@@ -68,16 +72,41 @@
   });
 };
 
+const clearFilterCriteria = state => {
+  state.warning = false;
+  state.successful = false;
+  state.failed = false;
+  state.pending = false;
+  state.accepted = false;
+  state.declined = false;
+};
+
 const imports = {
   init,
   namespaced: true,
   state: init(),
+  getters: {
+    filters: state => {
+      return ["failed", "pending", "accepted", "declined", "warning"].filter(
+        x => state[x]
+      );
+    }
+  },
   mutations: {
-    setFilters: (state, filters) => {
-      state.filters = filters;
+    toggleFilter: (state, name) => {
+      state[name] = !state[name];
+      const allSet =
+        state.failed &&
+        state.pending &&
+        state.accepted &&
+        state.declined &&
+        state.warning;
+      if (allSet) {
+        clearFilterCriteria(state);
+      }
     },
     clearFilters: state => {
-      state.filters = [];
+      clearFilterCriteria(state);
     },
     setStretches: (state, stretches) => {
       state.stretches = stretches;
@@ -200,20 +229,6 @@
           });
       });
     },
-    getStaging({ commit }) {
-      return new Promise((resolve, reject) => {
-        HTTP.get("/imports?states=pending", {
-          headers: { "X-Gemma-Auth": localStorage.getItem("token") }
-        })
-          .then(response => {
-            commit("setStaging", response.data.imports);
-            resolve(response);
-          })
-          .catch(error => {
-            reject(error);
-          });
-      });
-    },
     confirmReview({ state }, reviewResults) {
       return new Promise((resolve, reject) => {
         HTTP.patch("/imports", reviewResults, {