update song sorting function
This commit is contained in:
parent
a9feb88dba
commit
e3a6a0cca0
1 changed files with 21 additions and 38 deletions
|
@ -767,54 +767,37 @@ const app = new Vue({
|
||||||
let self = this
|
let self = this
|
||||||
|
|
||||||
function sortSongs() {
|
function sortSongs() {
|
||||||
if (self.library.songs.sortOrder == "asc") {
|
// sort this.library.songs.displayListing by song.attributes[self.library.songs.sorting] in descending or ascending order based on alphabetical order and numeric order
|
||||||
// sort this.library.songs.displayListing by song.attributes[self.library.songs.sorting] in ascending order based on alphabetical order and numeric order
|
// check if song.attributes[self.library.songs.sorting] is a number and if so, sort by number if not, sort by alphabetical order ignoring case
|
||||||
// check if song.attributes[self.library.songs.sorting] is a number and if so, sort by number if not, sort by alphabetical order ignoring case
|
self.library.songs.displayListing.sort((a, b) => {
|
||||||
self.library.songs.displayListing.sort((a, b) => {
|
let aa = null;
|
||||||
let aa = null;
|
let bb = null;
|
||||||
let bb = null;
|
if (self.library.songs.sorting == "genre") {
|
||||||
if (self.library.songs.sorting == "genre") {
|
aa = a.attributes.genreNames[0]
|
||||||
aa = a.attributes.genreNames[0]
|
bb = b.attributes.genreNames[0]
|
||||||
bb = b.attributes.genreNames[0]
|
}
|
||||||
}
|
aa = a.attributes[self.library.songs.sorting]
|
||||||
aa = a.attributes[self.library.songs.sorting]
|
bb = b.attributes[self.library.songs.sorting]
|
||||||
bb = b.attributes[self.library.songs.sorting]
|
if (aa == null) {
|
||||||
if (aa == null) {
|
aa = ""
|
||||||
aa = ""
|
}
|
||||||
}
|
if (bb == null) {
|
||||||
if (bb == null) {
|
bb = ""
|
||||||
bb = ""
|
}
|
||||||
}
|
if (self.library.songs.sortOrder == "asc") {
|
||||||
if (aa.toString().match(/^\d+$/) && bb.toString().match(/^\d+$/)) {
|
if (aa.toString().match(/^\d+$/) && bb.toString().match(/^\d+$/)) {
|
||||||
return aa - bb
|
return aa - bb
|
||||||
} else {
|
} else {
|
||||||
return aa.toString().toLowerCase().localeCompare(bb.toString().toLowerCase())
|
return aa.toString().toLowerCase().localeCompare(bb.toString().toLowerCase())
|
||||||
}
|
}
|
||||||
})
|
} else if (self.library.songs.sortOrder == "desc") {
|
||||||
}
|
|
||||||
if (self.library.songs.sortOrder == "desc") {
|
|
||||||
// sort this.library.songs.displayListing by song.attributes[self.library.songs.sorting] in descending order based on alphabetical order and numeric order
|
|
||||||
// check if song.attributes[self.library.songs.sorting] is a number and if so, sort by number if not, sort by alphabetical order ignoring case
|
|
||||||
self.library.songs.displayListing.sort((a, b) => {
|
|
||||||
if (self.library.songs.sorting == "genre") {
|
|
||||||
aa = a.attributes.genreNames[0]
|
|
||||||
bb = b.attributes.genreNames[0]
|
|
||||||
}
|
|
||||||
let aa = a.attributes[self.library.songs.sorting]
|
|
||||||
let bb = b.attributes[self.library.songs.sorting]
|
|
||||||
if (aa == null) {
|
|
||||||
aa = ""
|
|
||||||
}
|
|
||||||
if (bb == null) {
|
|
||||||
bb = ""
|
|
||||||
}
|
|
||||||
if (aa.toString().match(/^\d+$/) && bb.toString().match(/^\d+$/)) {
|
if (aa.toString().match(/^\d+$/) && bb.toString().match(/^\d+$/)) {
|
||||||
return bb - aa
|
return bb - aa
|
||||||
} else {
|
} else {
|
||||||
return bb.toString().toLowerCase().localeCompare(aa.toString().toLowerCase())
|
return bb.toString().toLowerCase().localeCompare(aa.toString().toLowerCase())
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.library.songs.search == "") {
|
if (this.library.songs.search == "") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue