changeset 289:aee175e3f82c usermanagement

feat: Listing of users on management page Prototypical implementation of listing of all users on management page implemented. Data is fetched before route is entered. Unless the data isn't available the route is not changed. After data is available currently a simple unstyled table with data is rendered.
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 31 Jul 2018 12:02:48 +0200
parents 8e22d1f16f81
children dfd5a549ae95
files client/src/store.js client/src/stores/usermanagement.js client/src/views/Users.vue
diffstat 3 files changed, 83 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/store.js	Tue Jul 31 09:36:15 2018 +0200
+++ b/client/src/store.js	Tue Jul 31 12:02:48 2018 +0200
@@ -2,12 +2,14 @@
 import Vuex from "vuex";
 import Application from "./stores/application";
 import user from "./stores/user";
+import usermanagement from "./stores/usermanagement";
 
 Vue.use(Vuex);
 
 export default new Vuex.Store({
   modules: {
     application: Application,
-    user: user
+    user: user,
+    usermanagement: usermanagement
   }
 });
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/stores/usermanagement.js	Tue Jul 31 12:02:48 2018 +0200
@@ -0,0 +1,40 @@
+import { HTTP } from "../lib/http";
+
+const UserManagement = {
+  namespaced: true,
+  state: {
+    users: null
+  },
+  getters: {
+    users: state => {
+      return state.users;
+    },
+    getUserByName: state => name => {
+      return state.users[name];
+    }
+  },
+  mutations: {
+    usersLoaded: (state, data) => {
+      state.users = data.users;
+    }
+  },
+  actions: {
+    loadUsers({ commit }) {
+      return new Promise((resolve, reject) => {
+        HTTP.get("/users", {
+          headers: { "X-Gemma-Auth": localStorage.getItem("token") }
+        })
+          .then(response => {
+            commit("usersLoaded", response.data);
+            resolve(response);
+          })
+          .catch(error => {
+            console.log(error);
+            reject(error);
+          });
+      });
+    }
+  }
+};
+
+export default UserManagement;
--- a/client/src/views/Users.vue	Tue Jul 31 09:36:15 2018 +0200
+++ b/client/src/views/Users.vue	Tue Jul 31 12:02:48 2018 +0200
@@ -2,28 +2,65 @@
   <div class="main d-flex">
     <Sidebar v-bind:isOverlay="false"></Sidebar>
     <div class="d-flex flex-row content">
-      <h1>User Management</h1>
+      <div class="d-flex flex-column">
+        <div>
+          <h1>User Management</h1>
+        </div>
+        <div class="userlist">
+          <table class="table">
+            <thead>
+              <tr>
+                <th scope="col">Username</th>
+                <th scope="col">Country</th>
+                <th scope="col">Email</th>
+                <th scope="col">Role</th>
+              </tr>
+            </thead>
+            <tbody>
+             <tr v-for="user in users" :key="user.user">
+               <td>{{ user.user }}</td>
+               <td>{{ user.country }}</td>
+               <td>{{ user.role }}</td>
+               <td>{{ user.email }}</td>
+               </tr>
+            </tbody>
+          </table>
+        </div>
+      </div>
     </div>
   </div>
 </template>
 
 <style lang="scss">
+@import "../assets/application.scss";
 .main {
   height: 100vh;
 }
 
 .content {
-  width: 99%;
-  margin-left: 1%;
+  margin-left: $offset;
+}
+
+.userlist {
+  margin-top: $large-offset;
 }
 </style>
 
 <script>
 import Sidebar from "../components/Sidebar";
+import store from "../store";
+import { mapGetters } from "vuex";
+
 export default {
   name: "userview",
   components: {
     Sidebar
+  },
+  computed: {
+    ...mapGetters("usermanagement", ["users"])
+  },
+  beforeRouteEnter(to, from, next) {
+    store.dispatch("usermanagement/loadUsers").then(next);
   }
 };
 </script>