Skip to content
Snippets Groups Projects
Commit 47e166a6 authored by Julian's avatar Julian
Browse files

Explain and simplify computed properties of the LessonNotes.vue component

parent ba737f63
No related branches found
No related tags found
1 merge request!362Resolve "Add personal note management dialog in course book"
...@@ -103,13 +103,18 @@ export default { ...@@ -103,13 +103,18 @@ export default {
total() { total() {
return this.documentation.participations.length; return this.documentation.participations.length;
}, },
/**
* Return the number of present people.
*/
present() { present() {
return this.documentation.participations.filter( return this.documentation.participations.filter(
(p) => p.absenceReason === null, (p) => p.absenceReason === null,
).length; ).length;
}, },
/**
* Get all course attendants who have an absence reason, grouped by that reason.
*/
absences() { absences() {
// Get all course attendants who have an absence reason
return Object.groupBy( return Object.groupBy(
this.documentation.participations.filter( this.documentation.participations.filter(
(p) => p.absenceReason !== null, (p) => p.absenceReason !== null,
...@@ -117,23 +122,39 @@ export default { ...@@ -117,23 +122,39 @@ export default {
({ absenceReason }) => absenceReason.id, ({ absenceReason }) => absenceReason.id,
); );
}, },
/**
* Parse and combine all extraMark notes.
*
* Notes with extraMarks are grouped by ExtraMark. ExtraMarks with the showInCoursebook property set to false are ignored.
* @return An object where the keys are extraMark IDs and the values have the structure [extraMark, note1, note2, ..., noteN]
*/
extraMarkChips() { extraMarkChips() {
// Apply the inner function to each participation, with value being the resulting object
return this.documentation.participations.reduce((value, p) => { return this.documentation.participations.reduce((value, p) => {
p.notesWithExtraMark.forEach(({ extraMark }) => { // Go through every extra mark of this participation
if (extraMark.showInCoursebook) { for (const { extraMark } of p.notesWithExtraMark) {
if (value[extraMark.id]) { // Only proceed if the extraMark should be displayed here
value[extraMark.id].push(p); if (!extraMark.showInCoursebook) {
} else { continue;
value[extraMark.id] = [
this.extraMarks.find((e) => e.id === extraMark.id),
p,
];
}
} }
});
// value[extraMark.id] is an Array with the structure [extraMark, note1, note2, ..., noteN]
if (value[extraMark.id]) {
value[extraMark.id].push(p);
} else {
value[extraMark.id] = [
this.extraMarks.find((e) => e.id === extraMark.id),
p,
];
}
}
return value; return value;
}, {}); }, {});
}, },
/**
* Return a list Participations with a set tardiness
*/
tardyParticipations() { tardyParticipations() {
return this.documentation.participations.filter( return this.documentation.participations.filter(
(p) => p.noteWithTardiness != null && p.noteWithTardiness.tardiness > 0, (p) => p.noteWithTardiness != null && p.noteWithTardiness.tardiness > 0,
......
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