Prepared sorting of enrolled students list

This commit is contained in:
PMKuipers 2024-03-04 23:03:18 +01:00
parent d07e6170f3
commit f20a724c52
3 changed files with 32 additions and 8 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -796,6 +796,10 @@ export default {
text: strings.lineheader,
students: null,
can_unenrol: false,
sorting: {
asc: true,
field: 'enrolled'
}
};
},
created() {
@ -831,13 +835,33 @@ export default {
enrolldate() {
return format_datetime(this.value.enrol.enrolled_time);
},
enrolled_students() {
const list = [];
for (const s of this.students) {
if (s.enrolled) {
sorted_students() {
const self =this;
const list = Array.isArray(this.students)?this.students:[];
list.sort((a,b) => {
let d = a;
let e = b;
if (!self.sorting.asc) {
d = b;
e = a;
}
let df = d;
let ef = e;
const field = self.sorting.field;
if (d.user && d.user.hasOwnProperty(field)) {
df = d.user;
ef = e.user;
} else if (d.enrol && d.enrol.hasOwnProperty(field)) {
df = d.enrol;
ef = e.enrol;
}
}
if (field == 'enrolled') {
return ((df.enrolled)?1:0) - ((ef.enrolled)?1:0);
} else {
return String(d[this.sorting.header]).localeCompare(String(e[this.sorting.header]));
}
});
return list;
}
},