Parcourir la source

User management access display individual and agent seperately and pagination

master
Lene Scholtz il y a 5 ans
Parent
révision
b99c18b0c7

+ 93
- 2
src/components/admin/status/agentsUserManagementPage.vue Voir le fichier

28
     <br />
28
     <br />
29
     <br />
29
     <br />
30
     <div class="container">
30
     <div class="container">
31
+      <div class="d-flex justify-content-between">
32
+        <div class="p-2">
33
+          <input v-model="searchItem" class="form-control" placeholder="Search ..." />
34
+        </div>
35
+      </div>
31
       <table class="table table-bordered">
36
       <table class="table table-bordered">
32
         <thead>
37
         <thead>
33
           <tr>
38
           <tr>
62
         <tbody>
67
         <tbody>
63
           <tr>
68
           <tr>
64
             <td colspan="10">
69
             <td colspan="10">
65
-              <h5>Agents</h5>
70
+              <div class="myWell">
71
+                <h4>Agents</h4>
72
+              </div>
66
             </td>
73
             </td>
67
           </tr>
74
           </tr>
68
           <tr v-for="(item, i) in agents" :key="i">
75
           <tr v-for="(item, i) in agents" :key="i">
93
           </tr>
100
           </tr>
94
         </tbody>
101
         </tbody>
95
       </table>
102
       </table>
103
+      <div class="d-flex justify-content-between">
104
+        <div class="p-1">{{ currentPage + ' / ' + PageCount }}</div>
105
+        <div class="p-1">
106
+          <BasePagination
107
+            :currentPage="currentPage"
108
+            :pageCount="PageCount"
109
+            @nextPage="pageChangeHandle('next')"
110
+            @previousPage="pageChangeHandle('previous')"
111
+            @loadPage="pageChangeHandle"
112
+          />
113
+        </div>
114
+      </div>
96
     </div>
115
     </div>
97
     <br />
116
     <br />
98
   </div>
117
   </div>
99
 </template>
118
 </template>
119
+
100
 <script>
120
 <script>
101
 import { mapState, mapActions } from 'vuex';
121
 import { mapState, mapActions } from 'vuex';
102
 import axios from 'axios';
122
 import axios from 'axios';
123
+import _ from 'lodash';
124
+import ItemsPerPageList from '../../../assets/staticData/itemsPerPage';
125
+import BasePagination from '../../shared/basePagination.vue';
103
 
126
 
104
 export default {
127
 export default {
105
   name: 'agentManagementPage',
128
   name: 'agentManagementPage',
129
+  components: {
130
+    BasePagination,
131
+  },
106
   data() {
132
   data() {
107
-    return {};
133
+    return {
134
+      sortKey: '',
135
+      reverse: false,
136
+      searchItem: '',
137
+      itemsPerPageList: ItemsPerPageList,
138
+      visibleItemsPerPageCount: 0,
139
+      currentPage: 1,
140
+    };
108
   },
141
   },
109
   methods: {
142
   methods: {
110
     ...mapActions('registerIndividual', ['getAgents']),
143
     ...mapActions('registerIndividual', ['getAgents']),
144
+
111
     addNewAgent({ commit }) {
145
     addNewAgent({ commit }) {
112
       axios
146
       axios
113
         .post('/api/agent')
147
         .post('/api/agent')
117
     routerGoTo(goTo) {
151
     routerGoTo(goTo) {
118
       this.$router.push(goTo);
152
       this.$router.push(goTo);
119
     },
153
     },
154
+    sortBy(sortKey) {
155
+      this.reverse = this.sortKey === sortKey ? !this.reverse : false;
156
+      this.sortKey = sortKey;
157
+    },
158
+    async pageChangeHandle(value) {
159
+      console.log(value);
160
+      switch (value) {
161
+        case 'next':
162
+          this.currentPage += 1;
163
+          break;
164
+        case 'previous':
165
+          this.currentPage -= 1;
166
+          break;
167
+        default:
168
+          this.currentPage = value;
169
+      }
170
+    },
171
+    onChangeItemsPerPage() {
172
+      if (this.currentPage !== 1) {
173
+        this.currentPage = 1;
174
+      }
175
+    },
120
   },
176
   },
121
   mounted() {
177
   mounted() {
122
     this.getAgents();
178
     this.getAgents();
179
+    try {
180
+      // to assign initial value to itemsPerPage
181
+      if (this.itemsPerPageList && this.itemsPerPageList.length > 0) {
182
+        const [startItem] = this.itemsPerPageList;
183
+        this.visibleItemsPerPageCount = startItem;
184
+      }
185
+    } catch (error) {
186
+      throw error;
187
+    }
123
   },
188
   },
124
   computed: {
189
   computed: {
125
     ...mapState('registerIndividual', ['agents']),
190
     ...mapState('registerIndividual', ['agents']),
191
+
192
+    SortDirection() {
193
+      return this.reverse ? 'desc' : 'asc';
194
+    },
195
+    PageCount() {
196
+      return this.visibleItemsPerPageCount !== 0
197
+        ? Math.ceil(this.FilteredItems.length / this.visibleItemsPerPageCount)
198
+        : 1;
199
+    },
200
+    FilteredItems() {
201
+      const list = _.filter(this.individuals, item => Object.values(item).some(
202
+          i => JSON.stringify(i)
203
+              .toLowerCase()
204
+              .indexOf(this.searchItem) > -1,
205
+        ),);
206
+      return _.orderBy(list, this.sortKey, this.SortDirection);
207
+    },
208
+    DisplayItems() {
209
+      const list = this.FilteredItems;
210
+      const startSlice = (this.currentPage - 1) * this.visibleItemsPerPageCount;
211
+      let endSlice = this.currentPage * this.visibleItemsPerPageCount;
212
+      if (endSlice > list.length) {
213
+        endSlice = list.length;
214
+      }
215
+      return list.slice(startSlice, endSlice);
216
+    },
126
   },
217
   },
127
 };
218
 };
128
 </script>
219
 </script>

+ 95
- 6
src/components/admin/status/userManagementPage.vue Voir le fichier

22
         >Agents</button>
22
         >Agents</button>
23
       </div>
23
       </div>
24
     </div>
24
     </div>
25
-    <br />
26
-    <br />
27
     <div class="container">
25
     <div class="container">
26
+      <div class="d-flex justify-content-between">
27
+        <div class="p-2">
28
+          <input v-model="searchItem" class="form-control" placeholder="Search ..." />
29
+        </div>
30
+      </div>
28
       <table class="table table-bordered">
31
       <table class="table table-bordered">
29
         <thead>
32
         <thead>
30
           <tr>
33
           <tr>
59
         <tbody>
62
         <tbody>
60
           <tr>
63
           <tr>
61
             <td colspan="10">
64
             <td colspan="10">
62
-              <h5>Private Users</h5>
65
+              <div class="myWell">
66
+                <h4>Private Users</h4>
67
+              </div>
63
             </td>
68
             </td>
64
           </tr>
69
           </tr>
65
-          <tr v-for="(item, i) in individuals" :key="i">
70
+          <tr v-for="(item, i) in DisplayItems" :key="i">
66
             <td>{{ item.id }}</td>
71
             <td>{{ item.id }}</td>
67
             <td>{{ item.name }}</td>
72
             <td>{{ item.name }}</td>
68
             <td>{{ item.surname }}</td>
73
             <td>{{ item.surname }}</td>
86
           </tr>
91
           </tr>
87
         </tbody>
92
         </tbody>
88
       </table>
93
       </table>
94
+      <div class="d-flex justify-content-between">
95
+        <div class="p-1">{{ currentPage + ' / ' + PageCount }}</div>
96
+        <div class="p-1">
97
+          <BasePagination
98
+            :currentPage="currentPage"
99
+            :pageCount="PageCount"
100
+            @nextPage="pageChangeHandle('next')"
101
+            @previousPage="pageChangeHandle('previous')"
102
+            @loadPage="pageChangeHandle"
103
+          />
104
+        </div>
105
+      </div>
106
+      <br />
89
     </div>
107
     </div>
90
-    <br />
91
   </div>
108
   </div>
92
 </template>
109
 </template>
110
+
93
 <script>
111
 <script>
94
 import { mapState, mapActions } from 'vuex';
112
 import { mapState, mapActions } from 'vuex';
113
+import _ from 'lodash';
114
+import ItemsPerPageList from '../../../assets/staticData/itemsPerPage';
115
+import BasePagination from '../../shared/basePagination.vue';
95
 
116
 
96
 export default {
117
 export default {
97
   name: 'userManagementPage',
118
   name: 'userManagementPage',
119
+  components: {
120
+    BasePagination,
121
+  },
98
   data() {
122
   data() {
99
-    return {};
123
+    return {
124
+      sortKey: '',
125
+      reverse: false,
126
+      searchItem: '',
127
+      itemsPerPageList: ItemsPerPageList,
128
+      visibleItemsPerPageCount: 0,
129
+      currentPage: 1,
130
+    };
100
   },
131
   },
101
   methods: {
132
   methods: {
102
     ...mapActions('registerIndividual', ['getIndividuals']),
133
     ...mapActions('registerIndividual', ['getIndividuals']),
134
+
103
     routerGoTo(goTo) {
135
     routerGoTo(goTo) {
104
       this.$router.push(goTo);
136
       this.$router.push(goTo);
105
     },
137
     },
138
+    sortBy(sortKey) {
139
+      this.reverse = this.sortKey === sortKey ? !this.reverse : false;
140
+      this.sortKey = sortKey;
141
+    },
142
+    async pageChangeHandle(value) {
143
+      console.log(value);
144
+      switch (value) {
145
+        case 'next':
146
+          this.currentPage += 1;
147
+          break;
148
+        case 'previous':
149
+          this.currentPage -= 1;
150
+          break;
151
+        default:
152
+          this.currentPage = value;
153
+      }
154
+    },
155
+    onChangeItemsPerPage() {
156
+      if (this.currentPage !== 1) {
157
+        this.currentPage = 1;
158
+      }
159
+    },
106
   },
160
   },
107
   mounted() {
161
   mounted() {
108
     this.getIndividuals();
162
     this.getIndividuals();
163
+    try {
164
+      // to assign initial value to itemsPerPage
165
+      if (this.itemsPerPageList && this.itemsPerPageList.length > 0) {
166
+        const [startItem] = this.itemsPerPageList;
167
+        this.visibleItemsPerPageCount = startItem;
168
+      }
169
+    } catch (error) {
170
+      throw error;
171
+    }
109
   },
172
   },
110
   computed: {
173
   computed: {
111
     ...mapState('registerIndividual', ['individuals']),
174
     ...mapState('registerIndividual', ['individuals']),
175
+
176
+    SortDirection() {
177
+      return this.reverse ? 'desc' : 'asc';
178
+    },
179
+    PageCount() {
180
+      return this.visibleItemsPerPageCount !== 0
181
+        ? Math.ceil(this.FilteredItems.length / this.visibleItemsPerPageCount)
182
+        : 1;
183
+    },
184
+    FilteredItems() {
185
+      const list = _.filter(this.individuals, item => Object.values(item).some(
186
+          i => JSON.stringify(i)
187
+              .toLowerCase()
188
+              .indexOf(this.searchItem) > -1,
189
+        ),);
190
+      return _.orderBy(list, this.sortKey, this.SortDirection);
191
+    },
192
+    DisplayItems() {
193
+      const list = this.FilteredItems;
194
+      const startSlice = (this.currentPage - 1) * this.visibleItemsPerPageCount;
195
+      let endSlice = this.currentPage * this.visibleItemsPerPageCount;
196
+      if (endSlice > list.length) {
197
+        endSlice = list.length;
198
+      }
199
+      return list.slice(startSlice, endSlice);
200
+    },
112
   },
201
   },
113
 };
202
 };
114
 </script>
203
 </script>

+ 0
- 11
src/components/shared/navBar.vue Voir le fichier

192
               </span>
192
               </span>
193
               <span v-else></span>
193
               <span v-else></span>
194
             </li>
194
             </li>
195
-            <li class="nav-item dropdown" v-if="!isLoggedIn">
196
-              <a
197
-                class="nav-link"
198
-                @click="routerGoTo('/status/agentUserManagementPage')"
199
-                id="navbarDropdown"
200
-                role="button"
201
-                data-toggle="dropdown"
202
-                aria-haspopup="true"
203
-                aria-expanded="false"
204
-              >Test</a>
205
-            </li>
206
           </ul>
195
           </ul>
207
         </div>
196
         </div>
208
       </div>
197
       </div>

Chargement…
Annuler
Enregistrer