New service and model for the tunnel flights

This commit is contained in:
Sébastien ANDRE
2023-05-05 17:59:11 +02:00
parent 487b287924
commit e41e7a1fe4
6 changed files with 163 additions and 53 deletions

View File

@@ -3,16 +3,38 @@ import { formatDate } from '@angular/common';
import { DateAdapter, MAT_DATE_FORMATS, NativeDateAdapter } from "@angular/material/core";
import { TranslateService } from '@ngx-translate/core';
import { TunnelResp } from "../../models/tunnel";
import { DateService } from 'src/services/date.service';
import { TunnelService } from 'src/services/tunnel.service';
import { ServiceComm } from 'src/services/service-comm.service';
import { StatsService } from 'src/services/stats.service';
export const PICK_FORMATS = {
parse: { dateInput: 'yy MM dd' },
display: {
dateInput: 'yyyy-MM-dd',
monthYearLabel: 'yyyy MMM',
dateA11yLabel: 'yyyy MM dd',
monthYearA11yLabel: 'yyyy MMMM',
}
};
class PickDateAdapter extends NativeDateAdapter {
format(date: Date, displayFormat: Object): string {
return formatDate(date, displayFormat.toString(), "en");
}
}
@Component({
selector: 'app-new-tunnel-flight',
templateUrl: './new-tunnel-flight.component.html',
styleUrls: ['./new-tunnel-flight.component.css']
styleUrls: ['./new-tunnel-flight.component.css'],
providers: [
{ provide: DateAdapter, useClass: PickDateAdapter },
{ provide: MAT_DATE_FORMATS, useValue: PICK_FORMATS }
]
})
export class NewTunnelFlightComponent {
export class NewTunnelFlightComponent implements OnInit {
public beginDate: Date;
public endDate: Date;
public minutesOfFlight: number;
@@ -24,19 +46,19 @@ export class NewTunnelFlightComponent {
private pendingAddRequest: boolean;
constructor(private serviceComm: ServiceComm,
private serviceTunnel: TunnelService,
private dateService: DateService,
private translateService: TranslateService,
private statsService : StatsService) {}
private serviceTunnel: TunnelService,
private dateService: DateService,
private translateService: TranslateService,
private statsService: StatsService) { }
ngOnInit() {
this.serviceComm.forceTranslateTitle.subscribe((data)=> {
if (data === true){
this.serviceComm.forceTranslateTitle.subscribe((data) => {
if (data === true) {
this.updateTitle();
}
});
this.updateTitle();
this.pendingAddRequest = false;
this.initForm();
this.getListOfTunnels();
@@ -45,7 +67,20 @@ export class NewTunnelFlightComponent {
onFormSubmit() {
this.pendingAddRequest = true;
this.statsService.resetStats();
this.serviceTunnel.AddFlight(this.selectedTunnel.id,
this.beginDate,
this.minutesOfFlight,
this.comments)
.subscribe(() => {
this.statsService.resetStats();
this.comments = undefined;
if (this.resetForm === true) {
this.initForm();
}
this.pendingAddRequest = false;
});
}
public isValidatedForm(): boolean {
@@ -56,7 +91,7 @@ export class NewTunnelFlightComponent {
}
private getListOfTunnels() {
this.serviceTunnel.getListOfTunnels(true).subscribe((data) => {
this.serviceTunnel.getListOfTunnels().subscribe((data) => {
data.sort((a, b) => a.name.localeCompare(b.name));
this.listOfTunnel = data;
this.countDatasLoaded++;