[terms] sort by exact match first, all containing later

This commit is contained in:
Avris 2021-08-29 17:53:59 +02:00
parent 8efc9a88bf
commit 68893ef2ce
1 changed files with 9 additions and 1 deletions

View File

@ -177,7 +177,15 @@
// those must be methods, not computed, because when modified, they don't get updated in the view for some reason // those must be methods, not computed, because when modified, they don't get updated in the view for some reason
visibleEntries() { visibleEntries() {
return Object.values(this.entries).filter(n => n.matches(this.filter)); const values = Object.values(this.entries).filter(n => n.matches(this.filter));
if (this.filter) {
return values.sort((a, b) => {
if (a.key && a.key.toLowerCase() === this.filter.toLowerCase()) { return -1; }
if (b.key && b.key.toLowerCase() === this.filter.toLowerCase()) { return 1; }
return a.term[0].localeCompare(b.term[0]);
})
}
return values;
}, },
entriesCountApproved() { entriesCountApproved() {
return Object.values(this.entries).filter(n => n.approved).length; return Object.values(this.entries).filter(n => n.approved).length;