Skip to content

Commit 5afbdca

Browse files
committed
refactor
1 parent d41c89b commit 5afbdca

File tree

4 files changed

+328732
-328985
lines changed

4 files changed

+328732
-328985
lines changed

src/components/TicketsTable/SortFilterSearch.js

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,42 @@ export default {
4343
return match;
4444
});
4545
},
46+
performSort: function() {
47+
let field = this.serverParams.sort.field;
48+
let type = this.serverParams.sort.type;
49+
if (field === "" || type === "") {
50+
return;
51+
}
52+
let columnFieldType = this.columns.filter(function(entry) {
53+
return entry.field === field;
54+
})[0].type;
55+
this.filteredTickets.sort(function(a, b) {
56+
a = a[field];
57+
b = b[field];
58+
if (columnFieldType !== "number") {
59+
a = a
60+
.split("-")
61+
.pop()
62+
.trim();
63+
b = b
64+
.split("-")
65+
.pop()
66+
.trim();
67+
}
68+
if (type === "asc") {
69+
return a < b ? -1 : a > b ? 1 : 0;
70+
} else {
71+
// type = "desc"
72+
return a > b ? -1 : a < b ? 1 : 0;
73+
}
74+
});
75+
// reset page number on sort
76+
this.serverParams.page = 1;
77+
this.ticketsToShow = this.filteredTickets.slice(
78+
0,
79+
this.serverParams.perPage
80+
);
81+
},
4682
getChartsData: function() {
4783
let priority = {
4884
"0 - Unassigned": 0,
@@ -92,6 +128,7 @@ export default {
92128

93129
this.performFilter();
94130
this.performSearch();
131+
this.performSort();
95132
this.getChartsData();
96133

97134
this.ticketsToShow = this.filteredTickets.slice(
@@ -125,35 +162,7 @@ export default {
125162
field: field,
126163
type: type
127164
};
128-
let columnFieldType = this.columns.filter(function(entry) {
129-
return entry.field === field;
130-
})[0].type;
131-
this.filteredTickets.sort(function(a, b) {
132-
a = a[field];
133-
b = b[field];
134-
if (columnFieldType !== "number") {
135-
a = a
136-
.split("-")
137-
.pop()
138-
.trim();
139-
b = b
140-
.split("-")
141-
.pop()
142-
.trim();
143-
}
144-
if (type === "asc") {
145-
return a < b ? -1 : a > b ? 1 : 0;
146-
} else {
147-
// type = "dsc"
148-
return a > b ? -1 : a < b ? 1 : 0;
149-
}
150-
});
151-
// reset page number on sort
152-
this.serverParams.page = 1;
153-
this.ticketsToShow = this.filteredTickets.slice(
154-
0,
155-
this.serverParams.perPage
156-
);
165+
this.performSort();
157166
},
158167
onPageChange: function(params) {
159168
// event from vue-good-table

src/components/TicketsTable/TicketsTable.vue

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
type="text"
99
class="form-control"
1010
v-model="userSearchInput"
11-
placeholder="Search tickets"
11+
v-bind:placeholder="searchPlaceholder"
1212
/>
1313
</div>
1414
<!-- Modal Component -->
@@ -44,7 +44,7 @@
4444
perPageDropdown: [10],
4545
dropdownAllowAll: false
4646
}"
47-
:totalRows="filteredTickets.length"
47+
:totalRows="filteredTicketsLength"
4848
:columns="columns"
4949
:rows="ticketsToShow"
5050
@on-column-filter="onColumnFilter"
@@ -57,7 +57,7 @@
5757

5858
<script>
5959
import debounce from "lodash.debounce";
60-
import ticketsFromJSONFile from "@/data/sample-data-2.json";
60+
import ticketsFromJSONFile from "@/data/sample-data.json";
6161
import PieChart from "../PieChart.vue";
6262
import BarChart from "../BarChart.vue";
6363
import NewTicket from "../NewTicket.vue";
@@ -112,6 +112,9 @@ export default {
112112
};
113113
this.serverParams.page = 1;
114114
this.userSearchInput = "";
115+
116+
// render the tickets after reseting the params
117+
this.performFilterSearch();
115118
},
116119
closeModal: function() {
117120
this.$refs.myModalRef.hide();
@@ -143,6 +146,14 @@ export default {
143146
userSearchInput: function() {
144147
this.debounceSearch();
145148
}
149+
},
150+
computed: {
151+
searchPlaceholder() {
152+
return "Search in " + this.filteredTickets.length + " tickets";
153+
},
154+
filteredTicketsLength() {
155+
return this.filteredTickets.length;
156+
}
146157
}
147158
};
148159
</script>
@@ -165,7 +176,7 @@ export default {
165176
166177
input {
167178
display: inline-block;
168-
width: 250px;
179+
width: 300px;
169180
max-width: 50%;
170181
}
171182
}

0 commit comments

Comments
 (0)