Sort call numbers alphabetically, handle Dewey specially (#2538)

This commit is contained in:
Abe Jellinek 2022-04-12 14:40:25 -07:00 committed by GitHub
parent 58a1efb165
commit ce39185fa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1352,6 +1352,28 @@ var ItemTree = class ItemTree extends LibraryTree {
if (sortField == 'hasAttachment') {
return fieldB - fieldA;
}
if (sortField == 'callNumber') {
let deweyRe = /^(\d{3})(?:\.(\d{1,4}))?(?:\/([a-zA-Z]{3}))?$/;
let splitA = fieldA.toLowerCase().replace(/\s/g, '').match(deweyRe);
let splitB = fieldB.toLowerCase().replace(/\s/g, '').match(deweyRe);
if (splitA && splitB) {
// Looks like Dewey Decimal, so we'll compare by parts
let i;
for (i = 1; i < splitA.length && i < splitB.length; i++) {
if (splitA[i] < splitB[i]) {
return -1;
}
else if (splitA[i] > splitB[i]) {
return 1;
}
}
return (i < splitA.length) ? 1 : (i < splitB.length) ? -1 : 0;
}
else {
return (fieldA > fieldB) ? 1 : (fieldA < fieldB) ? -1 : 0;
}
}
return collation.compareString(1, fieldA, fieldB);
}