Преглед изворни кода

RestaurantRoles Set up

master
George Williams пре 4 година
родитељ
комит
359340e1db

BIN
public/img/paymentLogos.png Прегледај датотеку


+ 27
- 9
src/components/accounts/login.vue Прегледај датотеку

@@ -53,9 +53,13 @@
53 53
 
54 54
 <script>
55 55
 import { mapState, mapActions } from "vuex";
56
+import alert from "../shared/alert";
56 57
 
57 58
 export default {
58 59
   name: "Login",
60
+  components: {
61
+    alert
62
+  },
59 63
   data() {
60 64
     return {
61 65
       isPasswordShown: "password",
@@ -65,16 +69,25 @@ export default {
65 69
     };
66 70
   },
67 71
   methods: {
68
-    ...mapActions("authentiaction", ["getAuthentication", "Login"]),
72
+    ...mapActions("authentiaction", [
73
+      "getAuthentication",
74
+      "checkAuthentication"
75
+    ]),
69 76
     Login() {
70
-      this.Login(this.auth).then(() => {
71
-        if (this.$store.state.auth.resault === "Access Granted") {
72
-          console.log(JSON.stringify(this.auth));
73
-          this.$router.push("/");
77
+      this.checkAuthentication(this.auth).then(() => {
78
+        //console.log(JSON.stringify(this.$store.state.authentiaction.result));
79
+        // if (this.$store.state.auth.result === "Access Granted") {
80
+        //   console.log(JSON.stringify(this.$store.state.auth));
81
+        //   this.$router.push("/");
82
+        // } else {
83
+        //   console.log(JSON.stringify(this.auth));
84
+        //   this.hasError = true;
85
+        //   this.errorMessage = this.$store.state.auth.result;
86
+        // }
87
+        if (this.auth.result === "Access Granted") {
88
+          alert("Yes");
74 89
         } else {
75
-          console.log(JSON.stringify(this.auth));
76
-          this.hasError = true;
77
-          this.errorMessage = this.$store.state.auth.resault;
90
+          alert("No");
78 91
         }
79 92
       });
80 93
     },
@@ -89,10 +102,15 @@ export default {
89 102
     }
90 103
   },
91 104
   computed: {
92
-    ...mapState("authentiaction", ["auth"])
105
+    ...mapState("authentiaction", ["auth", "result"])
93 106
   },
94 107
   mounted() {
95 108
     this.getAuthentication();
109
+  },
110
+  watch: {
111
+    auth(value) {
112
+      return value;
113
+    }
96 114
   }
97 115
 };
98 116
 </script>

+ 176
- 19
src/components/restaurants/restaurantRole.vue Прегледај датотеку

@@ -12,31 +12,94 @@
12 12
           <span class="input-group-text">
13 13
             <eva-icon name="credit-card-outline" fill="#24aae1"></eva-icon>
14 14
           </span>
15
-          <input class="form-control" type="text" name="description" />
15
+          <input class="form-control" type="text" name="description" v-model="role.roleName" />
16 16
         </div>
17 17
       </div>
18 18
     </div>
19
-    <div class="container">
20
-      <div class="form-group row">
21
-        <div class="col-md-12">
22
-          <ListView
23
-            :showColumnChooser="false"
24
-            :editable="true"
25
-            :hideSearch="true"
26
-            :deleteable="true"
27
-            @onEdit="Edit"
28
-            @onDelete="Delete"
29
-            @onNew="New"
30
-          />
19
+    <div class="row">
20
+      <div class="col-md-12">
21
+        <ul class="nav nav-pills-a nav-pills mb-3 section-t3" id="pills-tab" role="tablist">
22
+          <li class="nav-item">
23
+            <a
24
+              class="nav-link active"
25
+              id="pills-video-tab"
26
+              data-toggle="pill"
27
+              href="#pills-video"
28
+              role="tab"
29
+              aria-controls="pills-video"
30
+              aria-selected="true"
31
+            >Permissions</a>
32
+          </li>
33
+          <li class="nav-item">
34
+            <a
35
+              class="nav-link"
36
+              id="pills-plans-tab"
37
+              data-toggle="pill"
38
+              href="#pills-plans"
39
+              role="tab"
40
+              aria-controls="pills-plans"
41
+              aria-selected="false"
42
+            >Users</a>
43
+          </li>
44
+        </ul>
45
+        <div class="tab-content" id="pills-tabContent">
46
+          <div
47
+            class="tab-pane fade show active"
48
+            id="pills-video"
49
+            role="tabpanel"
50
+            aria-labelledby="pills-video-tab"
51
+          >
52
+            <div class="col-md-12">
53
+              <ListView
54
+                :items="role.permissions"
55
+                :showColumnChooser="false"
56
+                :editable="true"
57
+                :hideSearch="true"
58
+                :deleteable="true"
59
+                :displayColumns="colums"
60
+                @onEdit="Edit"
61
+                @onDelete="Delete"
62
+                @onNew="New"
63
+              />
64
+              <modal name="Prems" :width="600" :height="270">
65
+                <Premission @UpdatePrems="UpdatePrems" :role="CurrentPrem" />
66
+              </modal>
67
+            </div>
68
+          </div>
69
+          <div
70
+            class="tab-pane fade"
71
+            id="pills-plans"
72
+            role="tabpanel"
73
+            aria-labelledby="pills-plans-tab"
74
+          >
75
+            <ListView
76
+              :items="role.users"
77
+              :displayColumns="uCols"
78
+              :showColumnChooser="false"
79
+              :deleteable="true"
80
+              @onDelete="RemoveUser"
81
+              @onNew="FindUser"
82
+            />
83
+            <modal name="users" :width="600" :height="400">
84
+              <UserLookup @SelectedUser="SelectedUser" />
85
+            </modal>
86
+          </div>
31 87
         </div>
32 88
       </div>
89
+    </div>
90
+    <div class="container">
33 91
       <div v-if="wait" id="preloader"></div>
34 92
     </div>
35 93
     <div class="row"></div>
36 94
     <div class="row">
37
-      <div class="col-md-12" style="margin-bottom: 1em">
38
-        <div class="input-group-prepend">
39
-          <b-button class="btn btn-b-n" @click="Ok">Ok</b-button>
95
+      <div class="col-md-12" style="margin-bottomL 1em">
96
+        <div class="row offset-md-5">
97
+          <div class="col-md-2">
98
+            <button @click="Save()" class="btn btn-b-n" type="button" data-dismiss="modal">Save</button>
99
+          </div>
100
+          <div class="col-md-2">
101
+            <button @click="Close()" class="btn btn-b-n" type="button" data-dismiss="modal">Close</button>
102
+          </div>
40 103
         </div>
41 104
       </div>
42 105
     </div>
@@ -44,16 +107,110 @@
44 107
 </template>
45 108
 
46 109
 <script>
110
+import { mapState, mapActions } from "vuex";
47 111
 import ListView from "../shared/listView";
112
+import Premission from "./rolePremission";
113
+import UserLookup from "./userLookup";
114
+import Log from "../../assets/Log";
115
+
48 116
 export default {
49 117
   name: "Role",
50 118
   components: {
51
-    ListView
119
+    ListView,
120
+    Premission,
121
+    UserLookup,
52 122
   },
53 123
   data() {
54 124
     return {
55
-      wait: false
125
+      wait: false,
126
+      restaurantId: Log.restaurantId(),
127
+      colums: ["target", "navigate", "create", "read", "write"],
128
+      uCols: ["emailAddress", "firstName", "surname", "cellphone"],
129
+      prem: {},
56 130
     };
57
-  }
131
+  },
132
+  methods: {
133
+    ...mapActions("restaurantRoles", [
134
+      "getRole",
135
+      "getPremission",
136
+      "saveRole",
137
+      "updateRole",
138
+    ]),
139
+    FindUser() {
140
+      this.$modal.show("users");
141
+    },
142
+    SelectedUser(item) {
143
+      const user = this.role.users.find((u) => u.id === item[0].id);
144
+      if (user) {
145
+        Object.assign(user, item[0]);
146
+      } else {
147
+        this.role.users.push(item[0]);
148
+      }
149
+      this.$modal.hide("users");
150
+    },
151
+    RemoveUser(item) {
152
+      // const user = this.role.users.find((u) => u.id === item.id);
153
+      // if (user) {
154
+      //   this.role.users.pop(user);
155
+      // }
156
+      var index = 0;
157
+      for (let i = 0; i < this.role.users.length; i++) {
158
+        if (this.role.users[i].id == item.id) {
159
+          index = i;
160
+        }
161
+      }
162
+      this.role.users.splice(index, 1);
163
+    },
164
+    New() {
165
+      this.prem = {
166
+        target: "",
167
+        navigate: false,
168
+        create: false,
169
+        read: false,
170
+        write: false,
171
+        delete: false,
172
+      };
173
+      this.$modal.show("Prems");
174
+    },
175
+    Edit(item) {
176
+      this.prem = item;
177
+      this.$modal.show("Prems");
178
+    },
179
+    Delete(item) {
180
+      //Delete item
181
+    },
182
+    UpdatePrems(value) {
183
+      const premItem = this.role.permissions.find(
184
+        (p) => p.target === value.target
185
+      );
186
+      if (premItem) {
187
+        Object.assign(premItem, value);
188
+      } else {
189
+        this.role.permissions.push(value);
190
+      }
191
+      this.$modal.hide("Prems");
192
+    },
193
+    Save() {
194
+      this.role.restaurantId = this.restaurantId;
195
+      if (this.role.id === 0) {
196
+        this.saveRole(this.role);
197
+      } else {
198
+        this.updateRole(this.role);
199
+      }
200
+      this.$router.push("/RestaurantRoles");
201
+    },
202
+    Close() {
203
+      this.$router.push("/RestaurantRoles");
204
+    },
205
+  },
206
+  computed: {
207
+    ...mapState("restaurantRoles", ["role"]),
208
+    CurrentPrem() {
209
+      return this.prem;
210
+    },
211
+  },
212
+  mounted() {
213
+    this.getRole(this.$route.params.id);
214
+  },
58 215
 };
59 216
 </script>

+ 11
- 32
src/components/restaurants/restaurantRoles.vue Прегледај датотеку

@@ -16,10 +16,12 @@
16 16
       <div class="form-group row">
17 17
         <div class="col-md-12">
18 18
           <ListView
19
+            :items="roles"
19 20
             :showColumnChooser="false"
20 21
             :editable="true"
21 22
             :hideSearch="true"
22 23
             :deleteable="true"
24
+            :displayColumns="columns"
23 25
             @onEdit="Edit"
24 26
             @onDelete="Delete"
25 27
             @onNew="New"
@@ -44,52 +46,29 @@ export default {
44 46
   data() {
45 47
     return {
46 48
       wait: false,
47
-      restaurantId: Log.restaurantId()
49
+      restaurantId: Log.restaurantId(),
50
+      columns: ["roleName"]
48 51
     };
49 52
   },
50 53
   methods: {
51
-    // ...mapActions("restaurantUser", [
52
-    //   "getUsers",
53
-    //   "getUser",
54
-    //   "insertUser",
55
-    //   "updateUser",
56
-    //   "deleteUser"
57
-    // ]),
54
+    ...mapActions("restaurantRoles", ["getRoles", "removeRole"]),
58 55
     New() {
59
-      //   this.getUser(0);
60 56
       this.$router.push("/RestaurantRole/0");
61 57
     },
62 58
     Edit(item) {
63
-      //   this.getUser(item.id);
64
-      //   this.$modal.show("role");
59
+      this.$router.push(`/RestaurantRole/${item.id}`);
65 60
     },
66 61
     Delete(item) {
67
-      //   this.deleteUser(item);
62
+      this.removeRole(item);
68 63
     }
69
-    // UpdateUser(item) {
70
-    //   const restUser = {
71
-    //     restaurantId: this.restaurantId,
72
-    //     user: item
73
-    //   };
74
-
75
-    //   if (item.id == 0) {
76
-    //     this.insertUser(restUser);
77
-    //   } else {
78
-    //     this.updateUser(restUser);
79
-    //   }
80
-    //   this.$modal.hide("User");
81
-    // }
82 64
   },
83 65
   computed: {
84
-    //...mapState("restaurantUser", ["restaurantUsers", "restaurantUser"]),
85
-    // CurrentUser() {
86
-    //   return this.restaurantUser.user;
87
-    // }
66
+    ...mapState("restaurantRoles", ["roles"])
88 67
   },
89 68
   mounted() {
90
-    // this.getUsers(this.restaurantId).then(() => {
91
-    //   this.wait = false;
92
-    // });
69
+    this.getRoles(this.restaurantId).then(() => {
70
+      this.wait = false;
71
+    });
93 72
   }
94 73
 };
95 74
 </script>

+ 53
- 2
src/components/restaurants/rolePremission.vue Прегледај датотеку

@@ -12,8 +12,9 @@
12 12
           <span class="input-group-text">
13 13
             <eva-icon name="credit-card-outline" fill="#24aae1"></eva-icon>
14 14
           </span>
15
-          <select class="form-control">
16
-            <option value="Details">Restaurant Details</option>
15
+          <select class="form-control" v-model="role.target">
16
+            <option value="Select"></option>
17
+            <option value="Details">Details</option>
17 18
             <option value="MenuCategories">Menu Categories</option>
18 19
             <option value="MenuOptions">Menu Options</option>
19 20
             <option value="Menu">Menu</option>
@@ -24,6 +25,38 @@
24 25
         </div>
25 26
       </div>
26 27
     </div>
28
+    <div class="row" style="text-align:left">
29
+      <div class="col-md-2" style="margin-bottom: 1em">
30
+        <label>Navigation</label>
31
+        <div class="input-group-prepend">
32
+          <input style="margin-left: 1px" type="checkbox" v-model="role.navigate" />
33
+        </div>
34
+      </div>
35
+      <div class="col-md-2" style="margin-bottom: 1em">
36
+        <label>Create</label>
37
+        <div class="input-group-prepend">
38
+          <input style="margin-left: 1px" type="checkbox" v-model="role.create" />
39
+        </div>
40
+      </div>
41
+      <div class="col-md-2" style="margin-bottom: 1em">
42
+        <label>Read</label>
43
+        <div class="input-group-prepend">
44
+          <input style="margin-left: 1px" type="checkbox" v-model="role.read" />
45
+        </div>
46
+      </div>
47
+      <div class="col-md-2" style="margin-bottom: 1em">
48
+        <label>Write</label>
49
+        <div class="input-group-prepend">
50
+          <input style="margin-left: 1px" type="checkbox" v-model="role.write" />
51
+        </div>
52
+      </div>
53
+      <div class="col-md-2" style="margin-bottom: 1em">
54
+        <label>Delete</label>
55
+        <div class="input-group-prepend">
56
+          <input style="margin-left: 1px" type="checkbox" v-model="role.delete" />
57
+        </div>
58
+      </div>
59
+    </div>
27 60
 
28 61
     <div class="row"></div>
29 62
     <div class="row">
@@ -40,6 +73,9 @@
40 73
 import ListView from "../shared/listView";
41 74
 export default {
42 75
   name: "Role",
76
+  props: {
77
+    role: { default: {} }
78
+  },
43 79
   components: {
44 80
     ListView
45 81
   },
@@ -47,6 +83,21 @@ export default {
47 83
     return {
48 84
       wait: false
49 85
     };
86
+  },
87
+  methods: {
88
+    Ok() {
89
+      this.$emit("UpdatePrems", this.role);
90
+    }
91
+  },
92
+  watch: {
93
+    role: {
94
+      immediate: true,
95
+      handler(val, olVal) {
96
+        if (val) {
97
+          this.role = val;
98
+        }
99
+      }
100
+    }
50 101
   }
51 102
 };
52 103
 </script>

+ 59
- 0
src/components/restaurants/userLookup.vue Прегледај датотеку

@@ -0,0 +1,59 @@
1
+<template>
2
+  <div>
3
+    <div class="container">
4
+      <div class="row">
5
+        <div class="col-md-12" style="margin-bottom: 1em">
6
+          <h1>Users</h1>
7
+        </div>
8
+      </div>
9
+      <div class="form-group row">
10
+        <div class="col-md-12">
11
+          <ListView
12
+            :items="restaurantUsers"
13
+            :showColumnChooser="false"
14
+            :editable="false"
15
+            :deleteable="false"
16
+            :showNew="false"
17
+            :displayColumns="columns"
18
+            @onRowClick="SelectUser"
19
+          />
20
+        </div>
21
+      </div>
22
+      <div v-if="wait" id="preloader"></div>
23
+    </div>
24
+  </div>
25
+</template>
26
+
27
+<script>
28
+import ListView from "../shared/listView";
29
+import { mapState, mapActions } from "vuex";
30
+import Log from "../../assets/Log";
31
+
32
+export default {
33
+  name: "RestaurantUserLookup",
34
+  components: {
35
+    ListView,
36
+  },
37
+  data() {
38
+    return {
39
+      wait: true,
40
+      columns: ["emailAddress", "firstName", "surname", "cellphone"],
41
+      restaurantId: Log.restaurantId(),
42
+    };
43
+  },
44
+  methods: {
45
+    ...mapActions("restaurantUser", ["getUsers"]),
46
+    SelectUser(item) {
47
+      this.$emit("SelectedUser", item);
48
+    },
49
+  },
50
+  computed: {
51
+    ...mapState("restaurantUser", ["restaurantUsers"]),
52
+  },
53
+  mounted() {
54
+    this.getUsers(this.restaurantId).then(() => {
55
+      this.wait = false;
56
+    });
57
+  },
58
+};
59
+</script>

+ 6
- 2
src/components/shared/footerSection.vue Прегледај датотеку

@@ -4,6 +4,10 @@
4 4
       <div class="container">
5 5
         <div class="row">
6 6
           <div class="col-md-12">
7
+            <div class="credits">
8
+              <img src="img/paymentLogos.png" height="45px" />
9
+            </div>
10
+            <br />
7 11
             <div>
8 12
               <p class="copyright color-text-a">
9 13
                 &copy; Copyright
@@ -29,8 +33,8 @@ export default {
29 33
   methods: {
30 34
     routerGoTo(goTo) {
31 35
       this.$router.push(goTo);
32
-    }
33
-  }
36
+    },
37
+  },
34 38
 };
35 39
 </script>
36 40
 <style scoped>

+ 2
- 1
src/components/shared/listView.vue Прегледај датотеку

@@ -239,7 +239,8 @@ export default {
239 239
       default: true
240 240
     },
241 241
     displayColumns: {
242
-      default: []
242
+      type: Array,
243
+      default: () => []
243 244
     },
244 245
     displayFormats: {
245 246
       type: Array,

+ 3
- 1
src/store/index.js Прегледај датотеку

@@ -14,6 +14,7 @@ import Menu from './modules/restaurants/restaurantMenu';
14 14
 import HomeMenu from './modules/restaurants/menu';
15 15
 import Cart from './modules/orders/cart';
16 16
 import RestaurantUser from './modules/restaurants/restaurantUsers';
17
+import RestaurantRoles from './modules/restaurants/restaurantRoles';
17 18
 
18 19
 Vue.use(Vuex);
19 20
 /* eslint no-param-reassign: ["error", { "props": false }] */
@@ -31,6 +32,7 @@ export default new Vuex.Store({
31 32
     menu: Menu,
32 33
     homeMenu: HomeMenu,
33 34
     cart: Cart,
34
-    restaurantUser: RestaurantUser
35
+    restaurantUser: RestaurantUser,
36
+    restaurantRoles: RestaurantRoles
35 37
   },
36 38
 });

+ 24
- 18
src/store/modules/accounts/authentication.js Прегледај датотеку

@@ -1,6 +1,9 @@
1 1
 import Vue from 'vue';
2 2
 import Vuex from 'vuex';
3 3
 import axios from 'axios';
4
+import {
5
+  sha256
6
+} from 'js-sha256'
4 7
 
5 8
 Vue.use(Vuex);
6 9
 
@@ -10,8 +13,8 @@ export default {
10 13
     auth: {}
11 14
   },
12 15
   mutations: {
13
-    setAuthentication(state, auth) {
14
-      state.auth = auth;
16
+    setAuthentication(state, newAuth) {
17
+      state.auth = newAuth;
15 18
     }
16 19
   },
17 20
   getters: {},
@@ -20,25 +23,28 @@ export default {
20 23
       commit
21 24
     }) {
22 25
       axios
23
-        .get('api/Authentication')
26
+        .get('/api/Authentication')
24 27
         .then(result => commit('setAuthentication', result.data));
25 28
     },
26
-    Login({
29
+    checkAuthentication({
27 30
       commit
28
-    }, auth) {
29
-      //   axios
30
-      //     .post('api/Authentication', auth)
31
-      //     .then(result => commit('setAuthentication', result.data));
32
-      axios({
33
-        url: 'api/Authentication',
34
-        data: {
35
-          emailAddress: auth.emailAddress,
36
-          password: auth.password,
37
-        },
38
-        method: 'POST',
39
-      }).then((resp) => {
40
-        commit('setAuthentication', resp.data);
41
-      });
31
+    }, authObject) {
32
+      var sendObj = authObject;
33
+      sendObj.password = sha256(authObject.password + '≡∆≤≥√∞ProVision');
34
+
35
+      axios
36
+        .post('/api/Authentication/Authenticate', sendObj)
37
+        .then(result => commit('setAuthentication', result.data));
38
+      // axios({
39
+      //   url: '/api/Authentication/Authenticate',
40
+      //   data: {
41
+      //     emailAddress: authObject.emailAddress,
42
+      //     password: sha256(authObject.password + '≡∆≤≥√∞ProVision'),
43
+      //   },
44
+      //   method: 'POST',
45
+      // }).then((resp) => {
46
+      //   commit('setAuthentication', resp.data);
47
+      // });
42 48
     }
43 49
   }
44 50
 }

+ 79
- 0
src/store/modules/restaurants/restaurantRoles.js Прегледај датотеку

@@ -0,0 +1,79 @@
1
+import axios from 'axios'
2
+
3
+export default {
4
+  namespaced: true,
5
+  state: {
6
+    role: {},
7
+    roles: [],
8
+    prem: {}
9
+  },
10
+  mutations: {
11
+    setRoles(state, roles) {
12
+      state.roles = roles;
13
+    },
14
+    setRole(state, role) {
15
+      state.role = role;
16
+    },
17
+    setPrem(state, prem) {
18
+      state.prem = prem
19
+    },
20
+    removeRole(state, role) {
21
+      state.roles.pop(role);
22
+    },
23
+    addRole(state, role) {
24
+      state.role = role;
25
+      state.roles.push(role);
26
+    },
27
+    updateRole(state, role) {
28
+      state.role = role;
29
+      const item = state.roles.find(r => r.id === role.id);
30
+      Object.assign(item, role);
31
+      //https://stackoverflow.com/questions/51149729/updating-state-of-vuex-array-when-one-item-has-some-changes/51153076
32
+    }
33
+  },
34
+  getters: {},
35
+  actions: {
36
+    getRoles({
37
+      commit
38
+    }, restaurantId) {
39
+      axios
40
+        .get(`/api/RestaurantRoles/GetRoles/${restaurantId}`)
41
+        .then(result => commit("setRoles", result.data));
42
+    },
43
+    getRole({
44
+      commit
45
+    }, id) {
46
+      axios
47
+        .get(`/api/RestaurantRoles/${id}`)
48
+        .then(result => commit("setRole", result.data));
49
+    },
50
+    getPremission({
51
+      commit
52
+    }, id) {
53
+      axios
54
+        .get(`/api/RestaurantRoles/GetPremission/${id}`)
55
+        .then(result => commit("setPrem", result.data));
56
+    },
57
+    saveRole({
58
+      commit
59
+    }, role) {
60
+      axios
61
+        .post('/api/RestaurantRoles', role)
62
+        .then(result => commit("addRole", result.data));
63
+    },
64
+    updateRole({
65
+      commit
66
+    }, role) {
67
+      axios
68
+        .put('/api/RestaurantRoles', role)
69
+        .then(result => commit("updateRole", result.data));
70
+    },
71
+    removeRole({
72
+      commit
73
+    }, role) {
74
+      axios
75
+        .delete(`/api/RestaurantRoles/${role.id}`)
76
+        .then(result => commit("removeRole", role));
77
+    }
78
+  }
79
+}

Loading…
Откажи
Сачувај