Skip to content

Commit

Permalink
Feature/253 checkable absences (#282)
Browse files Browse the repository at this point in the history
* Add checkable absences to my absences

* Add checkable absences to student profile

* Make checkable absences not editable
  • Loading branch information
caebr authored May 11, 2021
1 parent 4fb38ae commit 5489b61
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@
<ng-template ngbPanelContent></ng-template>
</ngb-panel>

<ngb-panel id="checkable-absences">
<ng-template ngbPanelHeader let-opened="opened">
<erz-student-profile-entry-header
[opened]="opened"
(click)="acc.toggle('checkable-absences')"
>
{{ 'shared.profile.checkable-absences' | translate }}
<ng-container *ngIf="data.absenceCounts.checkableAbsences != null"
>({{ data.absenceCounts.checkableAbsences }})</ng-container
>
</erz-student-profile-entry-header>
</ng-template>
<ng-template ngbPanelContent>
<erz-student-profile-absences
[absences$]="myAbsencesService.checkableAbsences$"
></erz-student-profile-absences>
</ng-template>
</ngb-panel>

<ngb-panel id="open-absences">
<ng-template ngbPanelHeader let-opened="opened">
<erz-student-profile-entry-header
Expand Down
25 changes: 18 additions & 7 deletions src/app/my-absences/services/my-absences.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class MyAbsencesService {
);
private lessonPresences$ = this.getLessonPresences();

checkableAbsences$ = this.getAbsences(this.settings.checkableAbsenceStateId);
openAbsences$ = this.getAbsences(this.settings.unconfirmedAbsenceStateId);
excusedAbsences$ = this.getAbsences(this.settings.excusedAbsenceStateId);
unexcusedAbsences$ = this.getAbsences(this.settings.unexcusedAbsenceStateId);
Expand Down Expand Up @@ -118,18 +119,28 @@ export class MyAbsencesService {

private getCounts(): Observable<StudentProfileAbsencesCounts> {
return combineLatest([
this.getCount(this.checkableAbsences$),
this.getCount(this.openAbsences$),
this.getCount(this.excusedAbsences$),
this.getCount(this.unexcusedAbsences$),
this.getCount(this.incidents$),
]).pipe(
map(([openAbsences, excusedAbsences, unexcusedAbsences, incidents]) => ({
openAbsences,
excusedAbsences,
unexcusedAbsences,
incidents,
halfDays: null,
}))
map(
([
checkableAbsences,
openAbsences,
excusedAbsences,
unexcusedAbsences,
incidents,
]) => ({
checkableAbsences,
openAbsences,
excusedAbsences,
unexcusedAbsences,
incidents,
halfDays: null,
})
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@
</ng-template>
</ngb-panel>

<ngb-panel id="checkable-absences">
<ng-template ngbPanelHeader let-opened="opened">
<erz-student-profile-entry-header
[opened]="opened"
(click)="acc.toggle('checkable-absences')"
>
{{ 'shared.profile.checkable-absences' | translate }}
<ng-container
*ngIf="data.absenceCounts.checkableAbsences != null"
>({{ data.absenceCounts.checkableAbsences }})</ng-container
>
</erz-student-profile-entry-header>
</ng-template>
<ng-template ngbPanelContent>
<erz-student-profile-absences
[absences$]="absencesService.checkableAbsences$"
></erz-student-profile-absences>
</ng-template>
</ngb-panel>

<ngb-panel id="open-absences">
<ng-template ngbPanelHeader let-opened="opened">
<erz-student-profile-entry-header
Expand Down
18 changes: 17 additions & 1 deletion src/app/shared/services/student-profile-absences.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface StudentProfileAbsencesCounts {
export class StudentProfileAbsencesService {
private studentId$ = new ReplaySubject<number>(1);

checkableAbsences$ = this.getAbsences(this.loadCheckableAbsences.bind(this));
openAbsences$ = this.getAbsences(this.loadOpenAbsences.bind(this));
excusedAbsences$ = this.getAbsences(this.loadExcusedAbsences.bind(this));
unexcusedAbsences$ = this.getAbsences(this.loadUnexcusedAbsences.bind(this));
Expand Down Expand Up @@ -64,10 +65,14 @@ export class StudentProfileAbsencesService {
return combineLatest([
this.loadStatistics(studentId).pipe(startWith(null)),
this.openAbsences$.pipe(map((absences) => absences?.length ?? null)),
this.checkableAbsences$.pipe(
map((absences) => absences?.length ?? null)
),
]);
}),
map(([statistics, openAbsencesCount]) => ({
map(([statistics, openAbsencesCount, checkableAbsencesCount]) => ({
openAbsences: openAbsencesCount,
checkableAbsences: checkableAbsencesCount,
excusedAbsences: statistics?.TotalAbsencesValidExcuse ?? null,
unexcusedAbsences: statistics?.TotalAbsencesWithoutExcuse ?? null,
incidents: statistics?.TotalIncidents ?? null,
Expand Down Expand Up @@ -107,6 +112,17 @@ export class StudentProfileAbsencesService {
);
}

private loadCheckableAbsences(
studentId: number
): Observable<ReadonlyArray<LessonPresence>> {
return this.lessonPresencesService.getList({
params: {
...this.getBaseParams(studentId),
'filter.ConfirmationStateId': `=${this.settings.checkableAbsenceStateId}`,
},
});
}

private loadExcusedAbsences(
studentId: number
): Observable<ReadonlyArray<LessonPresence>> {
Expand Down
1 change: 1 addition & 0 deletions src/assets/locales/de-CH.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
"apprenticeship-company": "Lehrbetrieb",
"apprenticeship-period": "Lehrzeit",
"job-trainer": "Berufsbildner/in",
"checkable-absences": "Gemeldete Absenzen",
"open-absences": "Offene Absenzen",
"excused-absences": "Entschuldigte Absenzen",
"unexcused-absences": "Unentschuldigte Absenzen",
Expand Down

0 comments on commit 5489b61

Please sign in to comment.