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, text: strings.lineheader,
students: null, students: null,
can_unenrol: false, can_unenrol: false,
sorting: {
asc: true,
field: 'enrolled'
}
}; };
}, },
created() { created() {
@ -831,13 +835,33 @@ export default {
enrolldate() { enrolldate() {
return format_datetime(this.value.enrol.enrolled_time); return format_datetime(this.value.enrol.enrolled_time);
}, },
enrolled_students() { sorted_students() {
const list = []; const self =this;
for (const s of this.students) { const list = Array.isArray(this.students)?this.students:[];
if (s.enrolled) { 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; return list;
} }
}, },