Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display absences and allow to edit open absences in profile #151 #148 #176

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"prefix": "erz",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import { DropDownItem } from 'src/app/shared/models/drop-down-item.model';
import { DropDownItemsRestService } from 'src/app/shared/services/drop-down-items-rest.service';
import { LessonPresencesUpdateRestService } from 'src/app/shared/services/lesson-presences-update-rest.service';
import { getValidationErrors } from 'src/app/shared/utils/form';
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';
import { PresenceTypesService } from 'src/app/shared/services/presence-types.service';

enum Category {
Absent = 'absent',
Expand Down Expand Up @@ -80,17 +78,12 @@ export class EditAbsencesEditComponent implements OnInit, OnDestroy {
.getAbsenceConfirmationStates()
.pipe(map(this.sortAbsenceConfirmationStates.bind(this)), shareReplay(1));

absenceTypes$ = this.presenceTypesService
.getConfirmationTypes()
.pipe(map(sortPresenceTypes), shareReplay(1));
absenceTypes$ = this.presenceTypesService.confirmationTypes$;

// 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
activeCategories$ = this.presenceTypesService.halfDayActive$.pipe(
map((halfDayActive) =>
halfDayActive
? this.availableCategories
: this.availableCategories.filter((c) => c !== Category.HalfDay)
)
Expand All @@ -106,7 +99,7 @@ export class EditAbsencesEditComponent implements OnInit, OnDestroy {
private translate: TranslateService,
private state: EditAbsencesStateService,
private dropDownItemsService: DropDownItemsRestService,
private presenceTypesService: PresenceTypesRestService,
private presenceTypesService: PresenceTypesService,
private updateService: LessonPresencesUpdateRestService,
@Inject(SETTINGS) private settings: Settings
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}}
</div>
<a
class="edit btn btn-link pr-1"
class="edit btn btn-primary mt-1 mb-2"
[class.disabled]="data.selection.length === 0"
routerLink="/edit-absences/edit"
[queryParams]="{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
@import "../../../../bootstrap-variables";

.edit {
line-height: 1;
font-size: $icon-size;
}

.presence-category {
text-align: center;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { EditAbsencesStateService } from '../../services/edit-absences-state.service';
import { CONFIRM_ABSENCES_SERVICE } from 'src/app/shared/tokens/confirm-absences-service';

@Component({
selector: 'erz-edit-absences',
templateUrl: './edit-absences.component.html',
styleUrls: ['./edit-absences.component.scss'],
providers: [EditAbsencesStateService],
providers: [
EditAbsencesStateService,
{
provide: CONFIRM_ABSENCES_SERVICE,
useExisting: EditAbsencesStateService,
},
],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class EditAbsencesComponent implements OnInit {
Expand Down
12 changes: 11 additions & 1 deletion src/app/edit-absences/edit-absences-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EditAbsencesComponent } from './components/edit-absences/edit-absences.
import { EditAbsencesListComponent } from './components/edit-absences-list/edit-absences-list.component';
import { EditAbsencesEditComponent } from './components/edit-absences-edit/edit-absences-edit.component';
import { StudentProfileComponent } from '../shared/components/student-profile/student-profile.component';
import { ConfirmAbsencesComponent } from '../shared/components/confirm-absences/confirm-absences.component';

const routes: Routes = [
{
Expand All @@ -26,7 +27,16 @@ const routes: Routes = [
},
{
path: 'student/:id',
component: StudentProfileComponent,
children: [
{
path: '',
component: StudentProfileComponent,
},
{
path: 'edit',
component: ConfirmAbsencesComponent,
},
],
},
],
},
Expand Down
40 changes: 20 additions & 20 deletions src/app/edit-absences/services/edit-absences-state.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Injectable, Inject } from '@angular/core';
import { Location } from '@angular/common';
import { HttpParams } from '@angular/common/http';
import { Params } from '@angular/router';
import { combineLatest, Observable } from 'rxjs';
import { map, shareReplay } from 'rxjs/operators';
import { map, shareReplay, takeUntil } from 'rxjs/operators';

import { PresenceControlEntry } from 'src/app/presence-control/models/presence-control-entry.model';
import { DropDownItem } from 'src/app/shared/models/drop-down-item.model';
Expand All @@ -11,17 +12,17 @@ import { PresenceType } from 'src/app/shared/models/presence-type.model';
import { DropDownItemsRestService } from 'src/app/shared/services/drop-down-items-rest.service';
import { LessonPresencesRestService } from 'src/app/shared/services/lesson-presences-rest.service';
import { LoadingService } from 'src/app/shared/services/loading-service';
import { PresenceTypesRestService } from 'src/app/shared/services/presence-types-rest.service';
import { PresenceTypesService } from 'src/app/shared/services/presence-types.service';
import { sortDropDownItemsByValue } from 'src/app/shared/utils/drop-down-items';
import { spreadTriplet } from 'src/app/shared/utils/function';
import { sortPresenceTypes } from 'src/app/shared/utils/presence-types';
import { buildHttpParamsFromAbsenceFilter } from 'src/app/shared/utils/absences-filter';
import {
PaginatedEntriesService,
PAGE_LOADING_CONTEXT,
} from 'src/app/shared/services/paginated-entries.service';
import { Paginated } from 'src/app/shared/utils/pagination';
import { SETTINGS, Settings } from 'src/app/settings';
import { IConfirmAbsencesService } from 'src/app/shared/tokens/confirm-absences-service';

export interface EditAbsencesFilter {
student: Option<number>;
Expand All @@ -34,15 +35,12 @@ export interface EditAbsencesFilter {
}

@Injectable()
export class EditAbsencesStateService extends PaginatedEntriesService<
LessonPresence,
EditAbsencesFilter
> {
presenceTypes$ = this.loadPresenceTypes().pipe(
map(this.filterAbsenceTypes.bind(this)),
map(sortPresenceTypes),
shareReplay(1)
);
export class EditAbsencesStateService
extends PaginatedEntriesService<LessonPresence, EditAbsencesFilter>
implements IConfirmAbsencesService {
editBackLinkParams?: Params;

presenceTypes$ = this.loadPresenceTypes().pipe(shareReplay(1));
absenceConfirmationStates$ = this.loadAbsenceConfirmationStates().pipe(
map(sortDropDownItemsByValue),
shareReplay(1)
Expand All @@ -64,10 +62,16 @@ export class EditAbsencesStateService extends PaginatedEntriesService<
loadingService: LoadingService,
@Inject(SETTINGS) settings: Settings,
private lessonPresencesService: LessonPresencesRestService,
private presenceTypesService: PresenceTypesRestService,
private presenceTypesService: PresenceTypesService,
private dropDownItemsService: DropDownItemsRestService
) {
super(location, loadingService, settings, '/edit-absences');

this.queryParams$
.pipe(takeUntil(this.destroy$))
.subscribe(
(returnparams) => (this.editBackLinkParams = { returnparams })
);
}

/**
Expand Down Expand Up @@ -123,7 +127,9 @@ export class EditAbsencesStateService extends PaginatedEntriesService<
}

private loadPresenceTypes(): Observable<ReadonlyArray<PresenceType>> {
return this.loadingService.load(this.presenceTypesService.getList());
return this.loadingService.load(
this.presenceTypesService.activePresenceTypes$
);
}

private loadAbsenceConfirmationStates(): Observable<
Expand All @@ -133,12 +139,6 @@ export class EditAbsencesStateService extends PaginatedEntriesService<
this.dropDownItemsService.getAbsenceConfirmationStates()
);
}

private filterAbsenceTypes(
types: ReadonlyArray<PresenceType>
): ReadonlyArray<PresenceType> {
return types.filter((t) => t.Active);
}
}

function getPresenceControlEntries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ import {
OnInit,
ChangeDetectionStrategy,
AfterViewInit,
Inject,
} from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Observable } from 'rxjs';
import { map, take, shareReplay } from 'rxjs/operators';
import { map, take } 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';
import { PresenceTypesService } from '../../../shared/services/presence-types.service';

interface Column {
key: keyof LessonPresenceStatistic;
Expand All @@ -31,8 +28,6 @@ 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 @@ -49,8 +44,7 @@ export class EvaluateAbsencesListComponent implements OnInit, AfterViewInit {
public state: EvaluateAbsencesStateService,
private scrollPosition: ScrollPositionService,
private route: ActivatedRoute,
private presenceTypesService: PresenceTypesRestService,
@Inject(SETTINGS) private settings: Settings
private presenceTypesService: PresenceTypesService
) {}

ngOnInit(): void {
Expand All @@ -59,20 +53,14 @@ export class EvaluateAbsencesListComponent implements OnInit, AfterViewInit {
.subscribe((filterValue) => this.state.setFilter(filterValue));

// Add Column TotalHalfDays 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.columns = [
...this.columns,
{ key: 'TotalHalfDays', label: 'halfday' },
];
}
});
this.presenceTypesService.halfDayActive$.subscribe((halfDayActive) => {
if (halfDayActive) {
this.columns = [
...this.columns,
{ key: 'TotalHalfDays', label: 'halfday' },
];
}
});
}

ngAfterViewInit(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';

import { EvaluateAbsencesStateService } from '../../services/evaluate-absences-state.service';
import { CONFIRM_ABSENCES_SERVICE } from 'src/app/shared/tokens/confirm-absences-service';

@Component({
selector: 'erz-evaluate-absences',
templateUrl: './evaluate-absences.component.html',
styleUrls: ['./evaluate-absences.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [EvaluateAbsencesStateService],
providers: [
EvaluateAbsencesStateService,
{
provide: CONFIRM_ABSENCES_SERVICE,
useExisting: EvaluateAbsencesStateService,
},
],
})
export class EvaluateAbsencesComponent implements OnInit {
constructor(public state: EvaluateAbsencesStateService) {}
Expand Down
12 changes: 11 additions & 1 deletion src/app/evaluate-absences/evaluate-absences-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Routes, RouterModule } from '@angular/router';
import { EvaluateAbsencesComponent } from './components/evaluate-absences/evaluate-absences.component';
import { EvaluateAbsencesListComponent } from './components/evaluate-absences-list/evaluate-absences-list.component';
import { StudentProfileComponent } from '../shared/components/student-profile/student-profile.component';
import { ConfirmAbsencesComponent } from '../shared/components/confirm-absences/confirm-absences.component';

const routes: Routes = [
{
Expand All @@ -18,7 +19,16 @@ const routes: Routes = [
},
{
path: 'student/:id',
component: StudentProfileComponent,
children: [
{
path: '',
component: StudentProfileComponent,
},
{
path: 'edit',
component: ConfirmAbsencesComponent,
},
],
},
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Injectable, Inject } from '@angular/core';
import { Location } from '@angular/common';
import { HttpParams } from '@angular/common/http';
import { Params } from '@angular/router';
import { Observable } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

import { LessonPresencesRestService } from 'src/app/shared/services/lesson-presences-rest.service';
import { LoadingService } from 'src/app/shared/services/loading-service';
Expand All @@ -14,6 +16,7 @@ import {
Sorting,
} from 'src/app/shared/services/paginated-entries.service';
import { SETTINGS, Settings } from 'src/app/settings';
import { IConfirmAbsencesService } from 'src/app/shared/tokens/confirm-absences-service';

export interface EvaluateAbsencesFilter {
student: Option<number>;
Expand All @@ -22,17 +25,27 @@ export interface EvaluateAbsencesFilter {
}

@Injectable()
export class EvaluateAbsencesStateService extends PaginatedEntriesService<
LessonPresenceStatistic,
EvaluateAbsencesFilter
> {
export class EvaluateAbsencesStateService
extends PaginatedEntriesService<
LessonPresenceStatistic,
EvaluateAbsencesFilter
>
implements IConfirmAbsencesService {
editBackLinkParams?: Params;

constructor(
location: Location,
loadingService: LoadingService,
@Inject(SETTINGS) settings: Settings,
private lessonPresenceService: LessonPresencesRestService
) {
super(location, loadingService, settings, '/evaluate-absences');

this.queryParams$
.pipe(takeUntil(this.destroy$))
.subscribe(
(returnparams) => (this.editBackLinkParams = { returnparams })
);
}

protected getInitialFilter(): EvaluateAbsencesFilter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
</button>
<a
class="edit btn btn-link"
class="edit btn btn-primary mt-1 mb-2 mr-3"
[class.disabled]="selection.length === 0"
routerLink="/open-absences/edit"
>
Expand Down
Loading