Skip to content
Snippets Groups Projects
Commit edb44694 authored by CaTasTrOOf's avatar CaTasTrOOf
Browse files

Add sort method to fatorize code

parent 2b142721
No related branches found
No related tags found
1 merge request!11Add possibility to use Favorites
......@@ -146,6 +146,11 @@ export default {
if (this.adhesion) return member.limitDate
if (this.certif) return member.received_certifications.limit
return Math.min(member.limitDate, member.received_certifications.limit)
},
sort(a, b, order) {
if (a < b) return -1 * order
if (a > b) return 1 * order
return 0
}
},
computed: {
......@@ -156,30 +161,18 @@ export default {
let modifier = this.currentSortDir === "desc" ? -1 : 1
if (this.currentSort == "uid") {
if (a["uid"].toLowerCase() < b["uid"].toLowerCase())
return -1 * modifier
if (a["uid"].toLowerCase() > b["uid"].toLowerCase())
return 1 * modifier
sort(a["uid"].toLowerCase(), b["uid"].toLowerCase(), modifier)
} else if (this.currentSort == "pubkey") {
if (a["pubkey"].toLowerCase() < b["pubkey"].toLowerCase())
return -1 * modifier
if (a["pubkey"].toLowerCase() > b["pubkey"].toLowerCase())
return 1 * modifier
sort(a["pubkey"].toLowerCase(), b["pubkey"].toLowerCase(), modifier)
} else if (this.currentSort == "date_sortie") {
if (this.adhesion) {
if (a["limitDate"] < b["limitDate"]) return -1 * modifier
if (a["limitDate"] > b["limitDate"]) return 1 * modifier
sort(a["limitDate"], b["limitDate"], modifier)
} else if (this.certif) {
if (
a["received_certifications"]["limit"] <
b["received_certifications"]["limit"]
sort(
a["received_certifications"]["limit"],
b["received_certifications"]["limit"],
modifier
)
return -1 * modifier
if (
a["received_certifications"]["limit"] >
b["received_certifications"]["limit"]
)
return 1 * modifier
} else {
let minA = Math.min(
a["limitDate"],
......@@ -189,11 +182,9 @@ export default {
b["limitDate"],
b["received_certifications"]["limit"]
)
if (minA < minB) return -1 * modifier
if (minA > minB) return 1 * modifier
sort(minA, minB, modifier)
}
}
return 0
})
.filter((row, index) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment