Skip to content
Snippets Groups Projects
Commit aba69291 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Jan-Hendrik Willms
Browse files

fixes #4226

Closes #4226

Merge request studip/studip!3057
parent 2c6e90f9
No related branches found
No related tags found
No related merge requests found
...@@ -221,22 +221,28 @@ export default { ...@@ -221,22 +221,28 @@ export default {
}); });
}, },
sortArray (array) { sortArray (array) {
const mappedFields = {
last_activity: 'last_activity_raw',
semester: 'semester_sort',
};
if (!array.length) { if (!array.length) {
return []; return [];
} }
let sortby = this.sort.by; if (!this.activatedFields.includes(this.sort.by) && this.sort.by !== 'completion') {
if (!this.activatedFields.includes(sortby) && sortby !== 'completion') {
return array; return array;
} }
const striptags = function (text) { const striptags = function (text) {
if (typeof text === "string") { if (typeof text === 'string') {
return text.replace(/(<([^>]+)>)/gi, ""); return text.replace(/(<([^>]+)>)/gi, "");
} else { } else {
return text; return text;
} }
}; };
let sortby = mappedFields[this.sort.by] ?? this.sort.by;
// Define sort direction by this factor // Define sort direction by this factor
const directionFactor = this.sort.direction === 'ASC' ? 1 : -1; const directionFactor = this.sort.direction === 'ASC' ? 1 : -1;
...@@ -246,35 +252,28 @@ export default { ...@@ -246,35 +252,28 @@ export default {
sensitivity: 'base' sensitivity: 'base'
}); });
let sortFunction = function (a, b) { let sortFunction = function (a, b) {
return collator.compare(striptags(a[sortby]), striptags(b[sortby])); return collator.compare(striptags(a[sortby]), striptags(b[sortby]))
|| collator.compare(striptags(a.number), striptags(b.number));
}; };
if (sortby === 'last_activity') { if (sortby === 'number') {
sortFunction = (a, b) => a.last_activity_raw - b.last_activity_raw;
} else if (sortby === 'name') {
sortFunction = (a, b) => {
return collator.compare(striptags(a.name), striptags(b.name))
|| collator.compare(striptags(a.number), striptags(b.number));
};
} else if (sortby === 'number') {
sortFunction = (a, b) => { sortFunction = (a, b) => {
return collator.compare(striptags(a.number), striptags(b.number)) return collator.compare(striptags(a.number), striptags(b.number))
|| collator.compare(striptags(a.name), striptags(b.name)); || collator.compare(striptags(a.name), striptags(b.name));
}; };
} else if (sortby === 'semester') {
sortFunction = (a, b) => a.semester_sort - b.semester_sort;
} else { } else {
let is_numeric = true; let is_numeric = !array.some(i => {
for (let i in array) { const value = striptags(i[sortby]);
if (striptags(array[i][sortby]) && isNaN(striptags(array[i][sortby]))) { return value && isNaN(parseInt(value, 10));
is_numeric = false; });
break;
}
}
if (is_numeric) { if (is_numeric) {
sortFunction = function (a, b) { sortFunction = function (a, b) {
return (striptags(a[sortby]) ? parseInt(striptags(a[sortby]), 10) : 0) const aValue = (striptags(a[sortby]) ? parseInt(striptags(a[sortby]), 10) : 0);
- (striptags(b[sortby]) ? parseInt(striptags(b[sortby]), 10) : 0); const bValue = (striptags(b[sortby]) ? parseInt(striptags(b[sortby]), 10) : 0);
return aValue - bValue
|| collator.compare(striptags(a.number), striptags(b.number));
}; };
} }
} }
......
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