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>
<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-label>{{ 'NewTunnelFlight_ChooseTunnel' | translate }}</mat-label>
<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 { DateService } from '../../services/date.service';
import { JumpTypeResp } from "../../models/jumpType";
import { TunnelService } from '../../services/tunnel.service';
import { ServiceComm } from '../../services/service-comm.service';
import { StatsService } from '../../services/stats.service';
import { TunnelFlightService } from "../../services/tunnel-flight.service";
import { JumpTypeService } from "../../services/jump-type.service";
export const PICK_FORMATS = {
parse: { dateInput: 'yy MM dd' },
@@ -39,18 +40,20 @@ export class NewTunnelFlightComponent implements OnInit {
public flightDate: Date;
public minutesOfFlight: number;
public selectedTunnel: TunnelResp;
public selectedJumpType: JumpTypeResp;
public listOfTunnel: Array<TunnelResp>;
public listOfFilteredTunnel: Array<TunnelResp>;
public resetForm: boolean;
public comments: string;
private countDatasLoaded: number;
private pendingAddRequest: boolean;
public listOfJumpType: Array<JumpTypeResp>;
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,7 +96,8 @@ export class NewTunnelFlightComponent implements OnInit {
}
private getListOfTunnels() {
this.serviceTunnel.getListOfTunnels().subscribe((data) => {
this.serviceTunnel.getListOfTunnels()
.subscribe((data) => {
data.sort((a, b) => a.name.localeCompare(b.name));
this.listOfTunnel = data;
this.listOfFilteredTunnel = data;
@@ -99,9 +105,17 @@ export class NewTunnelFlightComponent implements OnInit {
});
}
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() {

View File

@@ -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",

View File

@@ -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",

View File

@@ -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;

View File

@@ -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<TunnelFlightResp>): Array<TunnelFlight> {
let allDropzones: Array<DropZoneResp>;
this.dropzoneService.getFromCache().subscribe(data => { allDropzones = data; });
let allJumpType: Array<JumpTypeResp>;
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;
});