Skip to content

Commit

Permalink
Filter available categories to get active categories
Browse files Browse the repository at this point in the history
  • Loading branch information
caebr committed May 5, 2020
1 parent 0846fa5 commit 82def49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div
class="erz-container erz-container-padding-y"
*erzLet="{
confirmationStates: confirmationStates$ | async
confirmationStates: confirmationStates$ | async,
categories: activeCategories$ | async
} as data"
>
<form
Expand All @@ -14,7 +15,10 @@
</div>

<div class="form-group pb-4">
<div *ngFor="let category of categories" class="form-check mt-2 mb-3">
<div
*ngFor="let category of data.categories"
class="form-check mt-2 mb-3"
>
<input
type="radio"
class="form-check-input"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ export class EditAbsencesEditComponent implements OnInit, OnDestroy {
startWith([])
);

categories = [
availableCategories = [
Category.Absent,
Category.Dispensation,
Category.HalfDay,
Category.Late,
Category.Present,
];
Expand All @@ -83,7 +84,17 @@ export class EditAbsencesEditComponent implements OnInit, OnDestroy {
.getConfirmationTypes()
.pipe(map(sortPresenceTypes), shareReplay(1));

presenceTypes$ = this.presenceTypesService.getList().pipe(shareReplay(1));
// Remove Category HalfDay if the corresponding PresenceType is inactive
activeCategories$ = this.presenceTypesService.getList().pipe(
map((types) =>
Boolean(types.find((t) => isHalfDay(t, this.settings))?.Active)
),
map((isActive) =>
isActive
? this.availableCategories
: this.availableCategories.filter((c) => c !== Category.HalfDay)
)
);

private destroy$ = new Subject<void>();

Expand Down Expand Up @@ -120,19 +131,6 @@ export class EditAbsencesEditComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.destroy$))
.subscribe(this.updateAbsenceTypeIdDisabled.bind(this));
}

// Add Category HalfDay if the corresponding PresenceType is active
this.presenceTypes$
.pipe(
map((types) =>
Boolean(types.find((t) => isHalfDay(t, this.settings))?.Active)
)
)
.subscribe((activeHalfDay) => {
if (activeHalfDay) {
this.categories.push(Category.HalfDay);
}
});
}

ngOnDestroy(): void {
Expand Down

0 comments on commit 82def49

Please sign in to comment.