Add the jump type in the tunnel flight

This commit is contained in:
Sébastien ANDRE
2023-08-17 11:28:31 +02:00
parent fe7ffa9016
commit 06f569c4d4
6 changed files with 53 additions and 12 deletions

View File

@@ -4,6 +4,19 @@
</div> </div>
<form class="formNewJumps" (ngSubmit)="onFormSubmit()" *ngIf="notLoadingToDisplay() else loading"> <form class="formNewJumps" (ngSubmit)="onFormSubmit()" *ngIf="notLoadingToDisplay() else loading">
<mat-form-field>
<mat-label>{{ 'NewTunnelFlight_ChooseJumpType' | translate }}</mat-label>
<input type="text" matInput [matAutocomplete]="autoJumpType" [(ngModel)]="selectedJumpType" name="selectedJumpType">
<mat-autocomplete #autoJumpType="matAutocomplete" [displayWith]="displayNameFn">
<mat-option *ngFor="let jumpType of listOfJumpType" [value]="jumpType">
{{jumpType.name}}
</mat-option>
</mat-autocomplete>
<button *ngIf="selectedJumpType" matSuffix mat-icon-button aria-label="Clear" (click)="selectedJumpType=undefined">
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
<mat-form-field> <mat-form-field>
<mat-label>{{ 'NewTunnelFlight_ChooseTunnel' | translate }}</mat-label> <mat-label>{{ 'NewTunnelFlight_ChooseTunnel' | translate }}</mat-label>
<input type="text" matInput [matAutocomplete]="autoDropZone" [(ngModel)]="selectedTunnel" <input type="text" matInput [matAutocomplete]="autoDropZone" [(ngModel)]="selectedTunnel"

View File

@@ -5,11 +5,12 @@ import { TranslateService } from '@ngx-translate/core';
import { TunnelResp } from "../../models/tunnel"; import { TunnelResp } from "../../models/tunnel";
import { DateService } from '../../services/date.service'; import { JumpTypeResp } from "../../models/jumpType";
import { TunnelService } from '../../services/tunnel.service'; import { TunnelService } from '../../services/tunnel.service';
import { ServiceComm } from '../../services/service-comm.service'; import { ServiceComm } from '../../services/service-comm.service';
import { StatsService } from '../../services/stats.service'; import { StatsService } from '../../services/stats.service';
import { TunnelFlightService } from "../../services/tunnel-flight.service"; import { TunnelFlightService } from "../../services/tunnel-flight.service";
import { JumpTypeService } from "../../services/jump-type.service";
export const PICK_FORMATS = { export const PICK_FORMATS = {
parse: { dateInput: 'yy MM dd' }, parse: { dateInput: 'yy MM dd' },
@@ -39,18 +40,20 @@ export class NewTunnelFlightComponent implements OnInit {
public flightDate: Date; public flightDate: Date;
public minutesOfFlight: number; public minutesOfFlight: number;
public selectedTunnel: TunnelResp; public selectedTunnel: TunnelResp;
public selectedJumpType: JumpTypeResp;
public listOfTunnel: Array<TunnelResp>; public listOfTunnel: Array<TunnelResp>;
public listOfFilteredTunnel: Array<TunnelResp>; public listOfFilteredTunnel: Array<TunnelResp>;
public resetForm: boolean; public resetForm: boolean;
public comments: string; public comments: string;
private countDatasLoaded: number; private countDatasLoaded: number;
private pendingAddRequest: boolean; private pendingAddRequest: boolean;
public listOfJumpType: Array<JumpTypeResp>;
constructor(private serviceComm: ServiceComm, constructor(private serviceComm: ServiceComm,
private serviceTunnel: TunnelService, private serviceTunnel: TunnelService,
private serviceTunnelFlight: TunnelFlightService, private serviceTunnelFlight: TunnelFlightService,
private translateService: TranslateService, private serviceJumpType: JumpTypeService,
private statsService: StatsService) { } private translateService: TranslateService) { }
ngOnInit() { ngOnInit() {
this.serviceComm.forceTranslateTitle.subscribe((data) => { this.serviceComm.forceTranslateTitle.subscribe((data) => {
@@ -60,20 +63,22 @@ export class NewTunnelFlightComponent implements OnInit {
}); });
this.updateTitle(); this.updateTitle();
this.countDatasLoaded = 0;
this.pendingAddRequest = false; this.pendingAddRequest = false;
this.initForm(); this.initForm();
this.getListOfTunnels(); this.getListOfTunnels();
this.getListOfJumpTypes();
} }
public onFormSubmit() { public onFormSubmit() {
this.pendingAddRequest = true; this.pendingAddRequest = true;
this.serviceTunnelFlight.addFlight(this.selectedTunnel.id, this.serviceTunnelFlight.addFlight(this.selectedTunnel.id,
this.selectedJumpType.id,
this.flightDate, this.flightDate,
this.minutesOfFlight, this.minutesOfFlight,
this.comments) this.comments)
.subscribe(() => { .subscribe(() => {
this.statsService.resetStats();
this.comments = undefined; this.comments = undefined;
if (this.resetForm === true) { if (this.resetForm === true) {
@@ -91,17 +96,26 @@ export class NewTunnelFlightComponent implements OnInit {
} }
private getListOfTunnels() { private getListOfTunnels() {
this.serviceTunnel.getListOfTunnels().subscribe((data) => { this.serviceTunnel.getListOfTunnels()
data.sort((a, b) => a.name.localeCompare(b.name)); .subscribe((data) => {
this.listOfTunnel = data; data.sort((a, b) => a.name.localeCompare(b.name));
this.listOfFilteredTunnel = data; this.listOfTunnel = data;
this.countDatasLoaded++; 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 { public notLoadingToDisplay(): boolean {
// return !(this.pendingAddRequest || this.countDatasLoaded > 1); return !(this.pendingAddRequest || this.countDatasLoaded !== 2);
return true;
} }
private updateTitle() { private updateTitle() {

View File

@@ -123,6 +123,7 @@
"NewTunnelFlight_Minutes_Lbl": "Time of flight (minutes)", "NewTunnelFlight_Minutes_Lbl": "Time of flight (minutes)",
"NewTunnelFlight_Date_Lbl": "Date of flight", "NewTunnelFlight_Date_Lbl": "Date of flight",
"NewTunnelFlight_GoToJump": "View the tunnel flights", "NewTunnelFlight_GoToJump": "View the tunnel flights",
"NewTunnelFlight_ChooseJumpType": "Choose the jump type",
"ListTunnelFlight_CurrentYear": "On the current year", "ListTunnelFlight_CurrentYear": "On the current year",
"ListTunnelFlight_12Months": "On 12 last months", "ListTunnelFlight_12Months": "On 12 last months",

View File

@@ -123,6 +123,7 @@
"NewTunnelFlight_Minutes_Lbl": "Temps de vol(minutes)", "NewTunnelFlight_Minutes_Lbl": "Temps de vol(minutes)",
"NewTunnelFlight_Date_Lbl": "Date des vols", "NewTunnelFlight_Date_Lbl": "Date des vols",
"NewTunnelFlight_GoToJump": "Voir les temps de vol en soufflerie", "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_CurrentYear": "Dans l'année en cours",
"ListTunnelFlight_12Months": "Sur 12 derniers mois", "ListTunnelFlight_12Months": "Sur 12 derniers mois",

View File

@@ -1,5 +1,6 @@
import { formatDate } from '@angular/common'; import { formatDate } from '@angular/common';
import { DropZoneResp } from './dropzone'; import { DropZoneResp } from './dropzone';
import { JumpTypeResp } from './jumpType';
export class TunnelFlightReq { export class TunnelFlightReq {
constructor(data: any) { constructor(data: any) {
@@ -8,6 +9,7 @@ export class TunnelFlightReq {
public id: number; public id: number;
public tunnelId: number; public tunnelId: number;
public jumpTypeId: number;
public nbMinutes: number; public nbMinutes: number;
public notes: string; public notes: string;
public flightDate: string; public flightDate: string;
@@ -21,6 +23,7 @@ export class TunnelFlightResp {
public id: number; public id: number;
public tunnelId: number; public tunnelId: number;
public jumpTypeId: number;
public nbMinutes: number; public nbMinutes: number;
public notes: string; public notes: string;
public flightDate: Date; public flightDate: Date;
@@ -35,6 +38,7 @@ export class TunnelFlight {
public id: number; public id: number;
public tunnel: DropZoneResp; public tunnel: DropZoneResp;
public jumpType: JumpTypeResp;
public nbMinutes: number; public nbMinutes: number;
public notes: string; public notes: string;
public flightDate: Date; public flightDate: Date;

View File

@@ -6,19 +6,23 @@ import { map } from "rxjs/operators";
import { TunnelFlightReq, TunnelFlightResp, TunnelFlight, TunnelFlightByMonthResp, TunnelFlightByMonth } from "../models/tunnel-flight"; import { TunnelFlightReq, TunnelFlightResp, TunnelFlight, TunnelFlightByMonthResp, TunnelFlightByMonth } from "../models/tunnel-flight";
import { DropZoneResp } from '../models/dropzone'; import { DropZoneResp } from '../models/dropzone';
import { JumpTypeResp } from '../models/jumpType';
import { BaseService } from "./base.service"; import { BaseService } from "./base.service";
import { DropzoneService } from "./dropzone.service"; import { DropzoneService } from "./dropzone.service";
import { JumpTypeService } from "./jump-type.service";
@Injectable() @Injectable()
export class TunnelFlightService extends BaseService { export class TunnelFlightService extends BaseService {
constructor(private http: HttpClient, constructor(private http: HttpClient,
private datePipe: DatePipe, private datePipe: DatePipe,
private jumpTypeService: JumpTypeService,
private dropzoneService: DropzoneService) { private dropzoneService: DropzoneService) {
super(); super();
} }
public addFlight(selectedTunnel: number, public addFlight(selectedTunnel: number,
selectedJumpType: number,
flightDate: Date, flightDate: Date,
nbMinutes: number, nbMinutes: number,
comment: string) { comment: string) {
@@ -26,6 +30,7 @@ export class TunnelFlightService extends BaseService {
const bodyNewFlight: TunnelFlightReq = { const bodyNewFlight: TunnelFlightReq = {
id: 0, id: 0,
tunnelId: selectedTunnel, tunnelId: selectedTunnel,
jumpTypeId: selectedJumpType,
flightDate: this.datePipe.transform(flightDate, "yyyy-MM-dd"), flightDate: this.datePipe.transform(flightDate, "yyyy-MM-dd"),
notes: comment, notes: comment,
nbMinutes: nbMinutes nbMinutes: nbMinutes
@@ -61,10 +66,13 @@ export class TunnelFlightService extends BaseService {
private mapWithDataInCache(apiResp: Array<TunnelFlightResp>): Array<TunnelFlight> { private mapWithDataInCache(apiResp: Array<TunnelFlightResp>): Array<TunnelFlight> {
let allDropzones: Array<DropZoneResp>; let allDropzones: Array<DropZoneResp>;
this.dropzoneService.getFromCache().subscribe(data => { allDropzones = data; }); this.dropzoneService.getFromCache().subscribe(data => { allDropzones = data; });
let allJumpType: Array<JumpTypeResp>;
this.jumpTypeService.getFromCache().subscribe(data => { allJumpType = data; });
return apiResp.map((data) => { return apiResp.map((data) => {
let tmp = new TunnelFlight(data); let tmp = new TunnelFlight(data);
tmp.tunnel = allDropzones.find(d => d.id == data.tunnelId); tmp.tunnel = allDropzones.find(d => d.id == data.tunnelId);
tmp.jumpType = allJumpType.find(d => d.id == data.jumpTypeId);
return tmp; return tmp;
}); });