ソースを参照

Soring on Property Admin

master
George Williams 4年前
コミット
8b8cfde64d

+ 7921
- 7817
public/css/bootstrap.css
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 7921
- 7817
public/css/bootstrap.min.css
ファイル差分が大きすぎるため省略します
ファイルの表示


バイナリ
public/img/sort-down.png ファイルの表示


バイナリ
public/img/sort-up.png ファイルの表示


+ 6043
- 5694
public/lib/bootstrap/css/bootstrap.css
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 2
- 0
src/assets/staticData/itemsPerPageFive.js ファイルの表示

1
+const items = [5, 10, 15, 20, 25, 50, 100];
2
+export default items;

+ 154
- 7
src/components/admin/property/propertyList.vue ファイルの表示

17
           <table class="table table-striped table-responsive">
17
           <table class="table table-striped table-responsive">
18
             <thead>
18
             <thead>
19
               <tr>
19
               <tr>
20
-                <th scope="col">Owner</th>
21
-                <th scope="col">Reference</th>
22
-                <th scope="col">Property</th>
20
+                <th scope="col" v-for="(col, c) in displayColumns" :key="c">
21
+                  <div @click="sortBy(columns[c])" style="cursor: pointer;">
22
+                    <div class="d-flex bd-highlight">
23
+                      <div class="w-100 bd-highlight">{{ col }}</div>
24
+                      <div class="flex-shrink-1 bd-highlight">
25
+                        <img
26
+                          src="../../../../public/img/sort-up.png"
27
+                          height="8px;"
28
+                          v-if="sortKey === columns[c] && reverse"
29
+                        />
30
+                        <img
31
+                          src="../../../../public/img/sort-down.png"
32
+                          height="8px;"
33
+                          v-if="sortKey === columns[c] && !reverse"
34
+                        />
35
+                      </div>
36
+                    </div>
37
+                  </div>
38
+                </th>
39
+                <!-- <th scope="col">Property</th>
23
                 <th scope="col">Unit</th>
40
                 <th scope="col">Unit</th>
24
                 <th scope="col">Size</th>
41
                 <th scope="col">Size</th>
25
                 <th scope="col">Price Ex VAT</th>
42
                 <th scope="col">Price Ex VAT</th>
28
                 <th scope="col">Suburb</th>
45
                 <th scope="col">Suburb</th>
29
                 <th scope="col">Status</th>
46
                 <th scope="col">Status</th>
30
                 <th scope="col">Type</th>
47
                 <th scope="col">Type</th>
31
-                <th scope="col">Publish</th>
48
+                <th scope="col">Publish</th>-->
32
                 <th scope="col">Edit</th>
49
                 <th scope="col">Edit</th>
33
                 <th scope="col">Delete</th>
50
                 <th scope="col">Delete</th>
34
               </tr>
51
               </tr>
35
             </thead>
52
             </thead>
36
             <tbody>
53
             <tbody>
37
-              <tr v-for="(item, i) in FilteredProperties" :key="i">
54
+              <tr v-for="(item, i) in DisplayItems" :key="i">
38
                 <td>{{ item.owner }}</td>
55
                 <td>{{ item.owner }}</td>
39
                 <td>{{ item.reference }}</td>
56
                 <td>{{ item.reference }}</td>
40
                 <td>{{ item.property }}</td>
57
                 <td>{{ item.property }}</td>
73
               </tr>
90
               </tr>
74
             </tbody>
91
             </tbody>
75
           </table>
92
           </table>
93
+          <div class="d-flex justify-content-between" v-if="showPager">
94
+            <div class="p-1">
95
+              {{
96
+              currentPage +
97
+              " / " +
98
+              PageCount +
99
+              (" - (" + FilteredProperties.length + " items)")
100
+              }}
101
+            </div>
102
+            <div class="p-1">
103
+              <BasePagination
104
+                :currentPage="currentPage"
105
+                :pageCount="PageCount"
106
+                @nextPage="pageChangeHandle('next')"
107
+                @previousPage="pageChangeHandle('previous')"
108
+                @loadPage="pageChangeHandle"
109
+              />
110
+            </div>
111
+            <div class="p-2">
112
+              <div class="d-flex flex-row">
113
+                <div>
114
+                  <select
115
+                    class="form-control uniSelect"
116
+                    v-model="visibleItemsPerPageCount"
117
+                    @change="onChangeItemsPerPage()"
118
+                  >
119
+                    <option v-for="(item, i) in itemsPerPageList" :key="i">{{ item }}</option>
120
+                  </select>
121
+                </div>
122
+              </div>
123
+            </div>
124
+          </div>
125
+          <div class="p-2">
126
+            <div class="d-flex flex-row">
127
+              <div>
128
+                <button v-if="sortKey !== 'id'" class="btn-solid-blue" @click="ClearSort">Clear Sort</button>
129
+              </div>
130
+            </div>
131
+          </div>
76
         </div>
132
         </div>
77
       </div>
133
       </div>
78
       <div v-if="wait" id="preloader"></div>
134
       <div v-if="wait" id="preloader"></div>
83
 <script>
139
 <script>
84
 import { mapState, mapActions } from "vuex";
140
 import { mapState, mapActions } from "vuex";
85
 import Log from "../../../assets/Log";
141
 import Log from "../../../assets/Log";
142
+import BasePagination from "../../shared/basePagination";
143
+import ItemsPerPageList from "../../../assets/staticData/itemsPerPageFive";
86
 import _ from "lodash";
144
 import _ from "lodash";
87
 
145
 
88
 export default {
146
 export default {
147
+  components: {
148
+    BasePagination,
149
+  },
89
   data() {
150
   data() {
90
     return {
151
     return {
152
+      hover: -1,
91
       filter: undefined,
153
       filter: undefined,
92
       userId: Log.getUser().id,
154
       userId: Log.getUser().id,
93
       wait: true,
155
       wait: true,
156
+      showPager: true,
157
+      visibleItemsPerPageCount: 10,
158
+      itemsPerPageList: ItemsPerPageList,
159
+      currentPage: 1,
160
+      reverse: true,
161
+      sortKey: "id",
162
+      displayColumns: [
163
+        "Owner",
164
+        "Reference",
165
+        "Property",
166
+        "Unit",
167
+        "Size",
168
+        "Price Ex VAT",
169
+        "Region",
170
+        "Town",
171
+        "Suburb",
172
+        "Status",
173
+        "Type",
174
+        "Publish",
175
+      ],
176
+      columns: [
177
+        "owner",
178
+        "reference",
179
+        "property",
180
+        "unit",
181
+        "size",
182
+        "price",
183
+        "region",
184
+        "town",
185
+        "suburb",
186
+        "status",
187
+        "type",
188
+        "isPublished",
189
+      ],
94
     };
190
     };
95
   },
191
   },
96
   methods: {
192
   methods: {
112
     Delete(item) {
208
     Delete(item) {
113
       this.deleteProperty(item.id);
209
       this.deleteProperty(item.id);
114
     },
210
     },
211
+    async pageChangeHandle(value) {
212
+      switch (value) {
213
+        case "next":
214
+          this.currentPage += 1;
215
+          break;
216
+        case "previous":
217
+          this.currentPage -= 1;
218
+          break;
219
+        default:
220
+          this.currentPage = value;
221
+      }
222
+    },
223
+    sortBy(sortKey) {
224
+      this.reverse = this.sortKey === sortKey ? !this.reverse : false;
225
+      this.sortKey = sortKey;
226
+    },
227
+    ClearSort() {
228
+      this.reverse = true;
229
+      this.sortKey = "id";
230
+    },
115
   },
231
   },
116
   computed: {
232
   computed: {
117
     ...mapState("propertyList", ["properties"]),
233
     ...mapState("propertyList", ["properties"]),
125
                 .indexOf(this.filter.toLowerCase()) > -1
241
                 .indexOf(this.filter.toLowerCase()) > -1
126
           )
242
           )
127
         );
243
         );
128
-        return list;
244
+        return _.orderBy(list, this.sortKey, this.SortDirection);
129
       } else {
245
       } else {
130
-        return this.properties;
246
+        return _.orderBy(this.properties, this.sortKey, this.SortDirection);
131
       }
247
       }
132
     },
248
     },
249
+    PageCount() {
250
+      return this.visibleItemsPerPageCount !== 0
251
+        ? Math.ceil(
252
+            this.FilteredProperties.length / this.visibleItemsPerPageCount
253
+          )
254
+        : 1;
255
+    },
256
+    DisplayItems() {
257
+      const list = this.FilteredProperties;
258
+      const startSlice = (this.currentPage - 1) * this.visibleItemsPerPageCount;
259
+      let endSlice = this.currentPage * this.visibleItemsPerPageCount;
260
+      if (endSlice > list.length) {
261
+        endSlice = list.length;
262
+      }
263
+      return list.slice(startSlice, endSlice);
264
+    },
265
+    SortDirection() {
266
+      return this.reverse ? "desc" : "asc";
267
+    },
133
   },
268
   },
134
   mounted() {
269
   mounted() {
135
     this.wait = true;
270
     this.wait = true;
136
     this.getAdminProperties(this.userId).then((fulfuilled) => {
271
     this.getAdminProperties(this.userId).then((fulfuilled) => {
137
       this.wait = false;
272
       this.wait = false;
273
+      if (this.itemsPerPageList && this.itemsPerPageList.length > 0) {
274
+        const [startItem] = this.itemsPerPageList;
275
+        this.visibleItemsPerPageCount = startItem;
276
+      }
138
     });
277
     });
139
   },
278
   },
279
+  // watch: {
280
+  //   sortKey: {
281
+  //     immediate: true,
282
+  //     handler(val, oldVal) {
283
+  //       return this.FilteredProperties;
284
+  //     },
285
+  //   },
286
+  // },
140
 };
287
 };
141
 </script>
288
 </script>
142
 
289
 

読み込み中…
キャンセル
保存