From 06f569c4d43e03029cdd18ff968d0d07a93f0044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20ANDRE?= Date: Thu, 17 Aug 2023 11:28:31 +0200 Subject: [PATCH] Add the jump type in the tunnel flight --- .../new-tunnel-flight.component.html | 13 +++++++ .../new-tunnel-flight.component.ts | 38 +++++++++++++------ Front/skydivelogs-app/src/assets/i18n/en.json | 1 + Front/skydivelogs-app/src/assets/i18n/fr.json | 1 + .../src/models/tunnel-flight.ts | 4 ++ .../src/services/tunnel-flight.service.ts | 8 ++++ 6 files changed, 53 insertions(+), 12 deletions(-) diff --git a/Front/skydivelogs-app/src/app/new-tunnel-flight/new-tunnel-flight.component.html b/Front/skydivelogs-app/src/app/new-tunnel-flight/new-tunnel-flight.component.html index 164f95e..646b7b0 100644 --- a/Front/skydivelogs-app/src/app/new-tunnel-flight/new-tunnel-flight.component.html +++ b/Front/skydivelogs-app/src/app/new-tunnel-flight/new-tunnel-flight.component.html @@ -4,6 +4,19 @@
+ + {{ 'NewTunnelFlight_ChooseJumpType' | translate }} + + + + {{jumpType.name}} + + + + + {{ 'NewTunnelFlight_ChooseTunnel' | translate }} ; public listOfFilteredTunnel: Array; public resetForm: boolean; public comments: string; private countDatasLoaded: number; private pendingAddRequest: boolean; + public listOfJumpType: Array; constructor(private serviceComm: ServiceComm, private serviceTunnel: TunnelService, private serviceTunnelFlight: TunnelFlightService, - private translateService: TranslateService, - private statsService: StatsService) { } + private serviceJumpType: JumpTypeService, + private translateService: TranslateService) { } ngOnInit() { this.serviceComm.forceTranslateTitle.subscribe((data) => { @@ -60,20 +63,22 @@ export class NewTunnelFlightComponent implements OnInit { }); this.updateTitle(); + this.countDatasLoaded = 0; this.pendingAddRequest = false; this.initForm(); this.getListOfTunnels(); + this.getListOfJumpTypes(); } public onFormSubmit() { this.pendingAddRequest = true; this.serviceTunnelFlight.addFlight(this.selectedTunnel.id, + this.selectedJumpType.id, this.flightDate, this.minutesOfFlight, this.comments) .subscribe(() => { - this.statsService.resetStats(); this.comments = undefined; if (this.resetForm === true) { @@ -91,17 +96,26 @@ export class NewTunnelFlightComponent implements OnInit { } private getListOfTunnels() { - this.serviceTunnel.getListOfTunnels().subscribe((data) => { - data.sort((a, b) => a.name.localeCompare(b.name)); - this.listOfTunnel = data; - this.listOfFilteredTunnel = data; - this.countDatasLoaded++; - }); + this.serviceTunnel.getListOfTunnels() + .subscribe((data) => { + data.sort((a, b) => a.name.localeCompare(b.name)); + this.listOfTunnel = data; + this.listOfFilteredTunnel = data; + this.countDatasLoaded++; + }); + } + + private getListOfJumpTypes() { + this.serviceJumpType.getListOfJumpTypes() + .subscribe((data) => { + data.sort((a, b) => a.name.localeCompare(b.name)); + this.listOfJumpType = data; + this.countDatasLoaded++; + }); } public notLoadingToDisplay(): boolean { - // return !(this.pendingAddRequest || this.countDatasLoaded > 1); - return true; + return !(this.pendingAddRequest || this.countDatasLoaded !== 2); } private updateTitle() { diff --git a/Front/skydivelogs-app/src/assets/i18n/en.json b/Front/skydivelogs-app/src/assets/i18n/en.json index 5df8871..8bb72b7 100644 --- a/Front/skydivelogs-app/src/assets/i18n/en.json +++ b/Front/skydivelogs-app/src/assets/i18n/en.json @@ -123,6 +123,7 @@ "NewTunnelFlight_Minutes_Lbl": "Time of flight (minutes)", "NewTunnelFlight_Date_Lbl": "Date of flight", "NewTunnelFlight_GoToJump": "View the tunnel flights", + "NewTunnelFlight_ChooseJumpType": "Choose the jump type", "ListTunnelFlight_CurrentYear": "On the current year", "ListTunnelFlight_12Months": "On 12 last months", diff --git a/Front/skydivelogs-app/src/assets/i18n/fr.json b/Front/skydivelogs-app/src/assets/i18n/fr.json index a467efe..ad36b94 100644 --- a/Front/skydivelogs-app/src/assets/i18n/fr.json +++ b/Front/skydivelogs-app/src/assets/i18n/fr.json @@ -123,6 +123,7 @@ "NewTunnelFlight_Minutes_Lbl": "Temps de vol(minutes)", "NewTunnelFlight_Date_Lbl": "Date des vols", "NewTunnelFlight_GoToJump": "Voir les temps de vol en soufflerie", + "NewTunnelFlight_ChooseJumpType": "Choisir le type de saut", "ListTunnelFlight_CurrentYear": "Dans l'année en cours", "ListTunnelFlight_12Months": "Sur 12 derniers mois", diff --git a/Front/skydivelogs-app/src/models/tunnel-flight.ts b/Front/skydivelogs-app/src/models/tunnel-flight.ts index 41c3946..ca2e1a8 100644 --- a/Front/skydivelogs-app/src/models/tunnel-flight.ts +++ b/Front/skydivelogs-app/src/models/tunnel-flight.ts @@ -1,5 +1,6 @@ import { formatDate } from '@angular/common'; import { DropZoneResp } from './dropzone'; +import { JumpTypeResp } from './jumpType'; export class TunnelFlightReq { constructor(data: any) { @@ -8,6 +9,7 @@ export class TunnelFlightReq { public id: number; public tunnelId: number; + public jumpTypeId: number; public nbMinutes: number; public notes: string; public flightDate: string; @@ -21,6 +23,7 @@ export class TunnelFlightResp { public id: number; public tunnelId: number; + public jumpTypeId: number; public nbMinutes: number; public notes: string; public flightDate: Date; @@ -35,6 +38,7 @@ export class TunnelFlight { public id: number; public tunnel: DropZoneResp; + public jumpType: JumpTypeResp; public nbMinutes: number; public notes: string; public flightDate: Date; diff --git a/Front/skydivelogs-app/src/services/tunnel-flight.service.ts b/Front/skydivelogs-app/src/services/tunnel-flight.service.ts index 2bb9c03..4485dd3 100644 --- a/Front/skydivelogs-app/src/services/tunnel-flight.service.ts +++ b/Front/skydivelogs-app/src/services/tunnel-flight.service.ts @@ -6,19 +6,23 @@ import { map } from "rxjs/operators"; import { TunnelFlightReq, TunnelFlightResp, TunnelFlight, TunnelFlightByMonthResp, TunnelFlightByMonth } from "../models/tunnel-flight"; import { DropZoneResp } from '../models/dropzone'; +import { JumpTypeResp } from '../models/jumpType'; import { BaseService } from "./base.service"; import { DropzoneService } from "./dropzone.service"; +import { JumpTypeService } from "./jump-type.service"; @Injectable() export class TunnelFlightService extends BaseService { constructor(private http: HttpClient, private datePipe: DatePipe, + private jumpTypeService: JumpTypeService, private dropzoneService: DropzoneService) { super(); } public addFlight(selectedTunnel: number, + selectedJumpType: number, flightDate: Date, nbMinutes: number, comment: string) { @@ -26,6 +30,7 @@ export class TunnelFlightService extends BaseService { const bodyNewFlight: TunnelFlightReq = { id: 0, tunnelId: selectedTunnel, + jumpTypeId: selectedJumpType, flightDate: this.datePipe.transform(flightDate, "yyyy-MM-dd"), notes: comment, nbMinutes: nbMinutes @@ -61,10 +66,13 @@ export class TunnelFlightService extends BaseService { private mapWithDataInCache(apiResp: Array): Array { let allDropzones: Array; this.dropzoneService.getFromCache().subscribe(data => { allDropzones = data; }); + let allJumpType: Array; + this.jumpTypeService.getFromCache().subscribe(data => { allJumpType = data; }); return apiResp.map((data) => { let tmp = new TunnelFlight(data); tmp.tunnel = allDropzones.find(d => d.id == data.tunnelId); + tmp.jumpType = allJumpType.find(d => d.id == data.jumpTypeId); return tmp; });