Skip to content

Commit

Permalink
ARPA-757 Only load appointment participations if required.
Browse files Browse the repository at this point in the history
  • Loading branch information
VILLAN3LL3 committed Nov 30, 2023
1 parent 4eda74e commit e3f6c07
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppointmentStatus } from '@arpa/models';
import { AppointmentStatus, ProjectDto, VenueDto, AppointmentDto, SectionDto, DateRange, AppointmentListDto } from '@arpa/models';
import { TranslateService } from '@ngx-translate/core';
import { ActivatedRoute } from '@angular/router';
import { Component } from '@angular/core';
Expand All @@ -12,7 +12,6 @@ import { first, map } from 'rxjs/operators';
import { AppointmentService } from '../services/appointment.service';
import { SectionService, NotificationsService, EnumService } from '@arpa/services';
import { EditAppointmentComponent } from '../edit-appointment/edit-appointment.component';
import { ProjectDto, VenueDto, AppointmentDto, SectionDto, DateRange, AppointmentListDto } from '@arpa/models';
import { Unsubscribe } from '../../../../@arpa/decorators/unsubscribe.decorator';

export interface CalendarEvent {
Expand Down Expand Up @@ -68,9 +67,13 @@ export class AppointmentsComponent {
this.categoryOptions = data.categories || [];
});
this.sectionsSubscription = this.sectionService.sectionsAll$.subscribe((sections) => (this.sections = sections || []));
this.statusSubscription = this.enumService.getAppointmentStatusSelectItems().subscribe(items => this.statusOptions = items || []);
this.resultSubscription = this.enumService.getAppointmentParticipationResultSelectItems().subscribe(items => this.resultOptions = items || []);
this.predictionSubscription = this.enumService.getAppointmentParticipationPredictionSelectItems().subscribe(items => this.predictionOptions = items || []);
this.statusSubscription = this.enumService.getAppointmentStatusSelectItems().subscribe((items) => (this.statusOptions = items || []));
this.resultSubscription = this.enumService
.getAppointmentParticipationResultSelectItems()
.subscribe((items) => (this.resultOptions = items || []));
this.predictionSubscription = this.enumService
.getAppointmentParticipationPredictionSelectItems()
.subscribe((items) => (this.predictionOptions = items || []));
this.langChangeListener = this.translate.onLangChange.subscribe(() => this.setOptions());
this.setOptions();
}
Expand Down Expand Up @@ -262,7 +265,7 @@ export class AppointmentsComponent {
}

private openEditDialog(appointmentId: string): void {
this.appointmentService.getById(appointmentId).subscribe((appointment) => {
this.appointmentService.getById(appointmentId, false).subscribe((appointment) => {
const ref = this.dialogService.open(EditAppointmentComponent, {
data: {
appointment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<h3 style="text-align: center" class="appointment-title">
{{ appointment.name }} - {{ appointment.startTime | date : 'dd.MM.yy' : 'locale(de)' }}
</h3>
<p-steps [(activeIndex)]="activeIndex" [model]="items" [readonly]="false"></p-steps>
<p-steps [(activeIndex)]="activeIndex" [model]="items" [readonly]="false" (activeIndexChange)="onActiveIndexChange($event)"></p-steps>
<div [ngSwitch]="activeIndex">
<ng-container *ngSwitchCase="0">
<form (submit)="onSubmit(false)" [formGroup]="formGroup" class="p-mt-5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
import { sortBy, uniq } from 'lodash-es';
import { EnumService, NotificationsService, ProjectService, SectionService, SelectValueService, VenueService } from '@arpa/services';
import { AppointmentService } from '../services/appointment.service';
import { first, map } from 'rxjs/operators';
import { first, map, tap } from 'rxjs/operators';
import { Observable, of, zip } from 'rxjs';
import { Table } from 'primeng/table';

Expand Down Expand Up @@ -66,8 +66,9 @@ export class EditAppointmentComponent implements OnInit {
formGroup: UntypedFormGroup;
ready = false;

appointment: AppointmentDto = this.config.data.appointment;
isAllDayEvent: boolean = this.config.data.isAllDayEvent;
appointment: AppointmentDto;
areParticipationsAlreadyLoaded = false;
isAllDayEvent: boolean;

// loaded in loadData()
sections: SectionsAllDto[];
Expand Down Expand Up @@ -124,105 +125,91 @@ export class EditAppointmentComponent implements OnInit {
{ field: 'sections', header: this.translate.instant('appointments.SECTIONS'), width: '20%' },
// { field: 'qualification', header: this.translate.instant('appointments.QUALIFICATION'), width: '20%' },
];

this.createStepperMenu();
}

private loadData() {
let getAppointmentById: Observable<AppointmentDto> = of(this.appointment);
if (this.appointment.id) {
getAppointmentById = this.appointmentService.getById(this.appointment.id);
}
console.log(this.config.data);

Check warning on line 132 in src/app/features/appointments/edit-appointment/edit-appointment.component.ts

View workflow job for this annotation

GitHub Actions / build (18.17.x)

Unexpected console statement
this.appointment = this.config.data.appointment;
this.isAllDayEvent = this.config.data.isAllDayEvent;
const sections$ = this.config.data.sections ? of(this.config.data.sections) : this.sectionService.sectionsAll$;
const projects$ = this.config.data.projects ? of(this.config.data.projects) : this.projectsService.load();
const venues$ = this.config.data.venues ? of(this.config.data.venues) : this.venuesService.load();
const salaries$ = this.config.data.salaryOptions
? of(this.config.data.salaryOptions)
: this.selectValueService.getAppointmentSalaries();
const salaryPatterns$ = this.config.data.salaryPatternOptions
? of(this.config.data.salaryPatternOptions)
: this.selectValueService.getAppointmentSalaryPatterns();
const expectations$ = this.config.data.expectationOptions
? of(this.config.data.expectationOptions)
: this.selectValueService.getAppointmentExpectations();
const categories$ = this.config.data.categoryOptions
? of(this.config.data.categoryOptions)
: this.selectValueService.getAppointmentCategories();
const results$ = this.config.data.resultOptions
? of(this.config.data.resultOptions)
: this.enumService.getAppointmentParticipationResultSelectItems();
const predictions$ = this.config.data.predictionOptions
? of(this.config.data.predictionOptions)
: this.enumService.getAppointmentParticipationPredictionSelectItems();
const status$ = this.config.data.statusOptions
? of(this.config.data.statusOptions)
: this.enumService.getAppointmentStatusSelectItems();
zip(
getAppointmentById.pipe(
map((result: AppointmentDto) => {
this.appointment = result;
})
),
this.enumService.getAppointmentStatusSelectItems().pipe(
status$.pipe(
map((result) => {
this.statusOptions = result;
})
),
this.enumService.getAppointmentParticipationResultSelectItems().pipe(
results$.pipe(
map((result) => {
this.resultOptions = result;
})
),
this.enumService.getAppointmentParticipationPredictionSelectItems().pipe(
predictions$.pipe(
map((result) => {
this.predictionOptions = result;
})
),

this.sectionService.sectionsAll$.pipe(
sections$.pipe(
map((result) => {
this.sections = result;
})
),

this.projectsService.load().pipe(
projects$.pipe(
map((result) => {
this.projects = result;
})
),

this.venuesService.load().pipe(
venues$.pipe(
map((result) => {
this.venues = result;
})
),

this.selectValueService.getAppointmentSalaries().pipe(
salaries$.pipe(
map((result) => {
this.salaryOptions = result;
})
),

this.selectValueService.getAppointmentSalaryPatterns().pipe(
salaryPatterns$.pipe(
map((result) => {
this.salaryPatternOptions = result;
})
),

this.selectValueService.getAppointmentExpectations().pipe(
expectations$.pipe(
map((result) => {
this.expectationOptions = result;
})
),

this.selectValueService.getAppointmentCategories().pipe(
categories$.pipe(
map((result) => {
this.categoryOptions = result;
})
)
).subscribe(() => {
this.fillForm();

if (this.appointment.participations) {
this.sectionSelectItems = sortBy(
uniq(
this.appointment.participations
.map((p: AppointmentParticipationListItemDto) => p.musicianProfiles || [])
.reduce((a, b) => a.concat(b), [])
.map((mp: ReducedMusicianProfileDto) => mp?.instrumentName || '')
).map((val) => ({ label: val, value: val })),
(selectItem) => selectItem.label
);

this.qualificationOptions = sortBy(
uniq(
this.appointment.participations
.map((p: AppointmentParticipationListItemDto) => p.musicianProfiles || [])
.reduce((a, b) => a.concat(b), [])
.map((mp: ReducedMusicianProfileDto) => mp?.qualification || '')
).map((val) => ({ label: val, value: val })),
(selectItem) => selectItem.label
);

this.mapParticipations();
}

this.venueOptions = this.venues?.map((v) => this.mapVenueToSelectItem(v));
this.setRooms(this.appointment.venueId);
this.ready = true;
Expand Down Expand Up @@ -256,6 +243,38 @@ export class EditAppointmentComponent implements OnInit {
}
}

onActiveIndexChange(event: number) {
if (event === 2 && !this.areParticipationsAlreadyLoaded) {
this.appointmentService.getById(this.appointment.id, true).subscribe((appointment) => {
this.appointment = appointment;
this.areParticipationsAlreadyLoaded = true;
if (this.appointment.participations) {
this.sectionSelectItems = sortBy(
uniq(
this.appointment.participations
.map((p: AppointmentParticipationListItemDto) => p.musicianProfiles ?? [])
.reduce((a, b) => a.concat(b), [])
.map((mp: ReducedMusicianProfileDto) => mp?.instrumentName ?? '')
).map((val) => ({ label: val, value: val })),
(selectItem) => selectItem.label
);

this.qualificationOptions = sortBy(
uniq(
this.appointment.participations
.map((p: AppointmentParticipationListItemDto) => p.musicianProfiles ?? [])
.reduce((a, b) => a.concat(b), [])
.map((mp: ReducedMusicianProfileDto) => mp?.qualification ?? '')
).map((val) => ({ label: val, value: val })),
(selectItem) => selectItem.label
);

this.mapParticipations();
}
});
}
}

mapVenueToSelectItem(venue: VenueDto): SelectItem {
return { label: `${venue?.address?.city} ${venue?.address?.urbanDistrict} | ${venue?.name}`, value: venue?.id };
}
Expand Down Expand Up @@ -508,11 +527,11 @@ export class EditAppointmentComponent implements OnInit {
this.appointment.participations.forEach((element: AppointmentParticipationListItemDto) => {
this.participationTableItems.push(
new ParticipationTableItem(
element.person?.id || '',
element.person?.givenName || '',
element.person?.surname || '',
this.getSectionNames(element.musicianProfiles || []),
element.musicianProfiles?.map((mp: any) => mp.qualification).join(', ') || '',
element.person?.id ?? '',
element.person?.givenName ?? '',
element.person?.surname ?? '',
this.getSectionNames(element.musicianProfiles ?? []),
element.musicianProfiles?.map((mp: any) => mp.qualification).join(', ') ?? '',
element.participation?.prediction,
element.participation?.result,
element.participation?.commentByPerformerInner
Expand Down
11 changes: 6 additions & 5 deletions src/app/features/appointments/services/appointment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {
AppointmentModifyBodyDto,
AppointmentParticipationPrediction,
AppointmentParticipationResult,
DateRange,
AppointmentDto,
AppointmentListDto,
} from '@arpa/models';
import { shareReplay } from 'rxjs/operators';
import { HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ApiService } from '@arpa/services';
import { AppointmentDto } from '@arpa/models';
import { DateRange } from '@arpa/models';
import { AppointmentListDto } from 'src/@arpa/models/appointmentListDto';

@Injectable({
providedIn: 'root',
Expand All @@ -29,8 +29,9 @@ export class AppointmentService {
return this.apiService.get<AppointmentListDto[]>(this.baseUrl, params).pipe(shareReplay());
}

getById(id: string): Observable<AppointmentDto> {
return this.apiService.get<AppointmentDto>(`${this.baseUrl}/${id}`).pipe(shareReplay());
getById(id: string, includeParticipations: boolean): Observable<AppointmentDto> {
const params = new HttpParams().set('includeParticipations', includeParticipations);
return this.apiService.get<AppointmentDto>(`${this.baseUrl}/${id}`, params).pipe(shareReplay());
}

create(appointment: AppointmentCreateDto): Observable<AppointmentDto> {
Expand Down

0 comments on commit e3f6c07

Please sign in to comment.