Kaynağa Gözat

User management access display individual and agent seperately and pagination

master
Lene Scholtz 5 yıl önce
ebeveyn
işleme
b99c18b0c7

+ 93
- 2
src/components/admin/status/agentsUserManagementPage.vue Dosyayı Görüntüle

@@ -28,6 +28,11 @@
28 28
     <br />
29 29
     <br />
30 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 36
       <table class="table table-bordered">
32 37
         <thead>
33 38
           <tr>
@@ -62,7 +67,9 @@
62 67
         <tbody>
63 68
           <tr>
64 69
             <td colspan="10">
65
-              <h5>Agents</h5>
70
+              <div class="myWell">
71
+                <h4>Agents</h4>
72
+              </div>
66 73
             </td>
67 74
           </tr>
68 75
           <tr v-for="(item, i) in agents" :key="i">
@@ -93,21 +100,48 @@
93 100
           </tr>
94 101
         </tbody>
95 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 115
     </div>
97 116
     <br />
98 117
   </div>
99 118
 </template>
119
+
100 120
 <script>
101 121
 import { mapState, mapActions } from 'vuex';
102 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 127
 export default {
105 128
   name: 'agentManagementPage',
129
+  components: {
130
+    BasePagination,
131
+  },
106 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 142
   methods: {
110 143
     ...mapActions('registerIndividual', ['getAgents']),
144
+
111 145
     addNewAgent({ commit }) {
112 146
       axios
113 147
         .post('/api/agent')
@@ -117,12 +151,69 @@ export default {
117 151
     routerGoTo(goTo) {
118 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 177
   mounted() {
122 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 189
   computed: {
125 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 219
 </script>

+ 95
- 6
src/components/admin/status/userManagementPage.vue Dosyayı Görüntüle

@@ -22,9 +22,12 @@
22 22
         >Agents</button>
23 23
       </div>
24 24
     </div>
25
-    <br />
26
-    <br />
27 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 31
       <table class="table table-bordered">
29 32
         <thead>
30 33
           <tr>
@@ -59,10 +62,12 @@
59 62
         <tbody>
60 63
           <tr>
61 64
             <td colspan="10">
62
-              <h5>Private Users</h5>
65
+              <div class="myWell">
66
+                <h4>Private Users</h4>
67
+              </div>
63 68
             </td>
64 69
           </tr>
65
-          <tr v-for="(item, i) in individuals" :key="i">
70
+          <tr v-for="(item, i) in DisplayItems" :key="i">
66 71
             <td>{{ item.id }}</td>
67 72
             <td>{{ item.name }}</td>
68 73
             <td>{{ item.surname }}</td>
@@ -86,29 +91,113 @@
86 91
           </tr>
87 92
         </tbody>
88 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 107
     </div>
90
-    <br />
91 108
   </div>
92 109
 </template>
110
+
93 111
 <script>
94 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 117
 export default {
97 118
   name: 'userManagementPage',
119
+  components: {
120
+    BasePagination,
121
+  },
98 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 132
   methods: {
102 133
     ...mapActions('registerIndividual', ['getIndividuals']),
134
+
103 135
     routerGoTo(goTo) {
104 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 161
   mounted() {
108 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 173
   computed: {
111 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 203
 </script>

+ 0
- 11
src/components/shared/navBar.vue Dosyayı Görüntüle

@@ -192,17 +192,6 @@
192 192
               </span>
193 193
               <span v-else></span>
194 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 195
           </ul>
207 196
         </div>
208 197
       </div>

Loading…
İptal
Kaydet