First step to add a new page

This commit is contained in:
Sébastien ANDRE
2023-05-05 11:02:52 +02:00
parent fe9cb202ba
commit 487b287924
6 changed files with 108 additions and 3 deletions

View File

@@ -1,4 +1,11 @@
import { Component } from '@angular/core';
import { Component, OnInit } from "@angular/core";
import { formatDate } from '@angular/common';
import { DateAdapter, MAT_DATE_FORMATS, NativeDateAdapter } from "@angular/material/core";
import { TranslateService } from '@ngx-translate/core';
import { DateService } from 'src/services/date.service';
import { ServiceComm } from 'src/services/service-comm.service';
import { StatsService } from 'src/services/stats.service';
@Component({
selector: 'app-new-tunnel-flight',
@@ -6,5 +13,73 @@ import { Component } from '@angular/core';
styleUrls: ['./new-tunnel-flight.component.css']
})
export class NewTunnelFlightComponent {
public beginDate: Date;
public endDate: Date;
public minutesOfFlight: number;
public selectedTunnel: TunnelResp;
public listOfTunnel: Array<TunnelResp>;
public resetForm: boolean;
public comments: string;
private countDatasLoaded: number;
private pendingAddRequest: boolean;
constructor(private serviceComm: ServiceComm,
private serviceTunnel: TunnelService,
private dateService: DateService,
private translateService: TranslateService,
private statsService : StatsService) {}
ngOnInit() {
this.serviceComm.forceTranslateTitle.subscribe((data)=> {
if (data === true){
this.updateTitle();
}
});
this.updateTitle();
this.pendingAddRequest = false;
this.initForm();
this.getListOfTunnels();
}
onFormSubmit() {
this.pendingAddRequest = true;
this.statsService.resetStats();
}
public isValidatedForm(): boolean {
return (this.selectedTunnel !== undefined &&
this.selectedTunnel.id !== undefined &&
this.minutesOfFlight !== undefined &&
typeof this.minutesOfFlight === "number");
}
private getListOfTunnels() {
this.serviceTunnel.getListOfTunnels(true).subscribe((data) => {
data.sort((a, b) => a.name.localeCompare(b.name));
this.listOfTunnel = data;
this.countDatasLoaded++;
});
}
public notLoadingToDisplay(): boolean {
return !(this.pendingAddRequest || this.countDatasLoaded !== 1);
}
private updateTitle() {
this.translateService.get("NewTunnelFlight_Title").subscribe(
data => { this.serviceComm.UpdatedComponentTitle(data); }
);
}
private initForm() {
this.endDate = new Date();
this.endDate.setHours(0, 0, 0, 0);
this.beginDate = this.dateService.AddDays(this.endDate, -1);
this.minutesOfFlight = 1;
this.selectedTunnel = undefined;
this.comments = undefined;
}
}