Skip to content

Commit

Permalink
Do not show HalfDays if corresponding PresenceType is inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
caebr committed May 4, 2020
1 parent d5a112a commit b7c70bd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { sortPresenceTypes } from 'src/app/shared/utils/presence-types';
import { EditAbsencesStateService } from '../../services/edit-absences-state.service';
import { PresenceTypesRestService } from '../../../shared/services/presence-types-rest.service';
import { parseQueryString } from 'src/app/shared/utils/url';
import { isHalfDay } from '../../../presence-control/utils/presence-types';

enum Category {
Absent = 'absent',
Expand Down Expand Up @@ -118,6 +119,21 @@ export class EditAbsencesEditComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.destroy$))
.subscribe(this.updateAbsenceTypeIdDisabled.bind(this));
}

// Remove Category HalfDay if the corresponding PresenceType is inactive
this.absenceTypes$
.pipe(
map((types) =>
types.filter((t) => isHalfDay(t, this.settings) && t.Active)
)
)
.subscribe((types) => {
if (types.length === 0) {
this.categories = this.categories.filter(
(c) => c !== Category.HalfDay
);
}
});
}

ngOnDestroy(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ import {
OnInit,
ChangeDetectionStrategy,
AfterViewInit,
Inject,
} from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Observable } from 'rxjs';
import { map, take } from 'rxjs/operators';
import { map, take, shareReplay } from 'rxjs/operators';

import {
EvaluateAbsencesStateService,
EvaluateAbsencesFilter,
} from '../../services/evaluate-absences-state.service';
import { LessonPresenceStatistic } from 'src/app/shared/models/lesson-presence-statistic';
import { ScrollPositionService } from 'src/app/shared/services/scroll-position.service';
import { PresenceTypesRestService } from '../../../shared/services/presence-types-rest.service';
import { SETTINGS, Settings } from '../../../settings';
import { isHalfDay } from '../../../presence-control/utils/presence-types';

interface Column {
key: keyof LessonPresenceStatistic;
Expand All @@ -27,6 +31,8 @@ interface Column {
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class EvaluateAbsencesListComponent implements OnInit, AfterViewInit {
presenceTypes$ = this.presenceTypesService.getList().pipe(shareReplay(1));

columns: ReadonlyArray<Column> = [
{ key: 'StudentFullName', label: 'student' },
{ key: 'TotalAbsences', label: 'total' },
Expand All @@ -43,13 +49,28 @@ export class EvaluateAbsencesListComponent implements OnInit, AfterViewInit {
constructor(
public state: EvaluateAbsencesStateService,
private scrollPosition: ScrollPositionService,
private route: ActivatedRoute
private route: ActivatedRoute,
private presenceTypesService: PresenceTypesRestService,
@Inject(SETTINGS) private settings: Settings
) {}

ngOnInit(): void {
this.filterFromParams$
.pipe(take(1))
.subscribe((filterValue) => this.state.setFilter(filterValue));

// Remove Column TotalHalfDays if the corresponding PresenceType is inactive
this.presenceTypes$
.pipe(
map((types) =>
types.filter((t) => isHalfDay(t, this.settings) && t.Active)
)
)
.subscribe((types) => {
if (types.length === 0) {
this.columns = this.columns.filter((c) => c.key !== 'TotalHalfDays');
}
});
}

ngAfterViewInit(): void {
Expand Down
11 changes: 11 additions & 0 deletions src/app/presence-control/utils/presence-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ export function isAbsent(presenceType: Option<PresenceType>): boolean {
);
}

export function isHalfDay(
presenceType: Option<PresenceType>,
settings: Settings
): boolean {
return Boolean(
presenceType &&
settings &&
presenceType.Id === settings.halfDayPresenceTypeId
);
}

export function isDefaultAbsence(
presenceType: Option<PresenceType>,
settings: Settings
Expand Down

0 comments on commit b7c70bd

Please sign in to comment.