diff --git a/src/app/child-dev-project/attendance/dashboard-widgets/attendance-week-dashboard/attendance-week-dashboard.component.spec.ts b/src/app/child-dev-project/attendance/dashboard-widgets/attendance-week-dashboard/attendance-week-dashboard.component.spec.ts index fbdc025c03..f6808cbe2c 100644 --- a/src/app/child-dev-project/attendance/dashboard-widgets/attendance-week-dashboard/attendance-week-dashboard.component.spec.ts +++ b/src/app/child-dev-project/attendance/dashboard-widgets/attendance-week-dashboard/attendance-week-dashboard.component.spec.ts @@ -90,6 +90,47 @@ describe("AttendanceWeekDashboardComponent", () => { ]); }); + it("should display children also if added via activity group or manually", async () => { + const absentChild = new TestEntity(); + const mondayLastWeek = moment().startOf("isoWeek").subtract(7, "days"); + const e1 = EventNote.create(mondayLastWeek.toDate()); + const e2 = EventNote.create(moment(e1.date).add(1, "day").toDate()); + const absentStatus = defaultAttendanceStatusTypes.find( + (s) => s.countAs === AttendanceLogicalStatus.ABSENT, + ); + [e1, e2].forEach((e) => { + e.addChild(absentChild); + e.getAttendance(absentChild).status = absentStatus; + }); + const activity = new RecurringActivity(); + delete activity.participants; // no participants set directly on RecurringActivity + const attendance = ActivityAttendance.create(new Date(), [e1, e2]); + attendance.activity = activity; + mockAttendanceService.getAllActivityAttendancesForPeriod.and.resolveTo([ + attendance, + ]); + + await component.ngOnInit(); + + expect(component.entries).toEqual([ + [ + { + childId: absentChild.getId(), + activity: activity, + attendanceDays: [ + // sundays are excluded + e1.getAttendance(absentChild), + e2.getAttendance(absentChild), + undefined, + undefined, + undefined, + undefined, + ], + }, + ], + ]); + }); + function expectTimePeriodCalled(from: moment.Moment, to: moment.Moment) { mockAttendanceService.getAllActivityAttendancesForPeriod.calls.reset(); diff --git a/src/app/child-dev-project/attendance/dashboard-widgets/attendance-week-dashboard/attendance-week-dashboard.component.ts b/src/app/child-dev-project/attendance/dashboard-widgets/attendance-week-dashboard/attendance-week-dashboard.component.ts index 0e4a8dc371..f56b2d130a 100644 --- a/src/app/child-dev-project/attendance/dashboard-widgets/attendance-week-dashboard/attendance-week-dashboard.component.ts +++ b/src/app/child-dev-project/attendance/dashboard-widgets/attendance-week-dashboard/attendance-week-dashboard.component.ts @@ -140,7 +140,7 @@ export class AttendanceWeekDashboardComponent } const results: AttendanceWeekRow[] = []; - for (const participant of att.activity.participants) { + for (const participant of att.participants) { const eventAttendances = []; let day = moment(from); diff --git a/src/app/child-dev-project/attendance/model/activity-attendance.ts b/src/app/child-dev-project/attendance/model/activity-attendance.ts index 8dd2744181..05a9744acc 100644 --- a/src/app/child-dev-project/attendance/model/activity-attendance.ts +++ b/src/app/child-dev-project/attendance/model/activity-attendance.ts @@ -53,6 +53,13 @@ export class ActivityAttendance extends Entity { */ activity: RecurringActivity; + /** + * List of (actual, recorded in at least one event) participants. + */ + get participants(): string[] { + return Array.from(new Set(this.events.flatMap((event) => event.children))); + } + /** * Mapping child ids to a map with all *logical* status as object keys and their counts as values. */