Import "TranslateModule"
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
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 { formatDate } from "@angular/common";
|
||||
import {
|
||||
DateAdapter,
|
||||
MAT_DATE_FORMATS,
|
||||
NativeDateAdapter,
|
||||
} from "@angular/material/core";
|
||||
import { TranslateModule, TranslateService } from "@ngx-translate/core";
|
||||
|
||||
import { JumpTypeResp } from "../../models/jumpType";
|
||||
import { AircraftResp } from "../../models/aircraft";
|
||||
@@ -17,31 +21,30 @@ import { JumpTypeService } from "../../services/jump-type.service";
|
||||
import { GearService } from "../../services/gear.service";
|
||||
import { StatsService } from "../../services/stats.service";
|
||||
|
||||
|
||||
export const PICK_FORMATS = {
|
||||
parse: { dateInput: 'yy MM dd' },
|
||||
parse: { dateInput: "yy MM dd" },
|
||||
display: {
|
||||
dateInput: 'yyyy-MM-dd',
|
||||
monthYearLabel: 'yyyy MMM',
|
||||
dateA11yLabel: 'yyyy MM dd',
|
||||
monthYearA11yLabel: 'yyyy MMMM',
|
||||
}
|
||||
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");
|
||||
override format(date: Date, displayFormat: Object): string {
|
||||
return formatDate(date, displayFormat.toString(), "en");
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: "app-new-jump",
|
||||
templateUrl: "./new-jump.component.html",
|
||||
styleUrls: ["./new-jump.component.css"],
|
||||
providers: [
|
||||
{ provide: DateAdapter, useClass: PickDateAdapter },
|
||||
{ provide: MAT_DATE_FORMATS, useValue: PICK_FORMATS }
|
||||
],
|
||||
standalone: false
|
||||
selector: "app-new-jump",
|
||||
templateUrl: "./new-jump.component.html",
|
||||
styleUrls: ["./new-jump.component.css"],
|
||||
providers: [
|
||||
{ provide: DateAdapter, useClass: PickDateAdapter },
|
||||
{ provide: MAT_DATE_FORMATS, useValue: PICK_FORMATS },
|
||||
],
|
||||
imports: [TranslateModule],
|
||||
})
|
||||
export class NewJumpComponent implements OnInit {
|
||||
public beginDate: Date;
|
||||
@@ -66,26 +69,28 @@ export class NewJumpComponent implements OnInit {
|
||||
private listOfDropZone: Array<DropZoneResp>;
|
||||
public maxDate: Date;
|
||||
|
||||
constructor(private serviceComm: ServiceComm,
|
||||
private serviceJump: JumpService,
|
||||
private serviceJumpType: JumpTypeService,
|
||||
private serviceAircraft: AircraftService,
|
||||
private serviceDropzone: DropzoneService,
|
||||
private serviceGear: GearService,
|
||||
private dateService: DateService,
|
||||
private translateService: TranslateService,
|
||||
private statsService : StatsService) {}
|
||||
constructor(
|
||||
private serviceComm: ServiceComm,
|
||||
private serviceJump: JumpService,
|
||||
private serviceJumpType: JumpTypeService,
|
||||
private serviceAircraft: AircraftService,
|
||||
private serviceDropzone: DropzoneService,
|
||||
private serviceGear: GearService,
|
||||
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.maxDate = this.dateService.addDays(new Date(), 1);
|
||||
|
||||
|
||||
this.pendingAddRequest = false;
|
||||
this.initForm();
|
||||
this.getListOfJumpTypes();
|
||||
@@ -94,87 +99,92 @@ export class NewJumpComponent implements OnInit {
|
||||
onFormSubmit() {
|
||||
this.pendingAddRequest = true;
|
||||
|
||||
this.serviceJump.addListOfJump(this.selectedJumpType.id,
|
||||
this.selectedAircraft.id,
|
||||
this.selectedDz.id,
|
||||
this.selectedGear.id,
|
||||
this.withCutaway === undefined ? false : this.withCutaway,
|
||||
this.beginDate,
|
||||
this.endDate,
|
||||
this.exitAltitude,
|
||||
this.deployAltitude,
|
||||
this.countOfJumps,
|
||||
this.comments,
|
||||
this.isSpecial === undefined ? false : this.isSpecial)
|
||||
.subscribe(() => {
|
||||
this.statsService.resetStats();
|
||||
this.comments = undefined;
|
||||
this.withCutaway = false;
|
||||
this.isSpecial = false;
|
||||
this.serviceJump
|
||||
.addListOfJump(
|
||||
this.selectedJumpType.id,
|
||||
this.selectedAircraft.id,
|
||||
this.selectedDz.id,
|
||||
this.selectedGear.id,
|
||||
this.withCutaway === undefined ? false : this.withCutaway,
|
||||
this.beginDate,
|
||||
this.endDate,
|
||||
this.exitAltitude,
|
||||
this.deployAltitude,
|
||||
this.countOfJumps,
|
||||
this.comments,
|
||||
this.isSpecial === undefined ? false : this.isSpecial
|
||||
)
|
||||
.subscribe(() => {
|
||||
this.statsService.resetStats();
|
||||
this.comments = undefined;
|
||||
this.withCutaway = false;
|
||||
this.isSpecial = false;
|
||||
|
||||
if (this.resetForm === true) {
|
||||
this.initForm();
|
||||
}
|
||||
this.pendingAddRequest = false;
|
||||
});
|
||||
if (this.resetForm === true) {
|
||||
this.initForm();
|
||||
}
|
||||
this.pendingAddRequest = false;
|
||||
});
|
||||
}
|
||||
|
||||
public isValidatedForm(): boolean {
|
||||
return (this.selectedDz !== undefined &&
|
||||
this.selectedDz.id !== undefined &&
|
||||
this.selectedGear !== undefined &&
|
||||
this.selectedGear.id !== undefined &&
|
||||
this.selectedAircraft !== undefined &&
|
||||
this.selectedAircraft.id !== undefined &&
|
||||
this.selectedJumpType !== undefined &&
|
||||
this.selectedJumpType.id !== undefined &&
|
||||
this.exitAltitude !== undefined &&
|
||||
typeof this.exitAltitude === "number" &&
|
||||
this.deployAltitude !== undefined &&
|
||||
typeof this.deployAltitude === "number" &&
|
||||
this.countOfJumps !== undefined &&
|
||||
typeof this.countOfJumps === "number");
|
||||
return (
|
||||
this.selectedDz !== undefined &&
|
||||
this.selectedDz.id !== undefined &&
|
||||
this.selectedGear !== undefined &&
|
||||
this.selectedGear.id !== undefined &&
|
||||
this.selectedAircraft !== undefined &&
|
||||
this.selectedAircraft.id !== undefined &&
|
||||
this.selectedJumpType !== undefined &&
|
||||
this.selectedJumpType.id !== undefined &&
|
||||
this.exitAltitude !== undefined &&
|
||||
typeof this.exitAltitude === "number" &&
|
||||
this.deployAltitude !== undefined &&
|
||||
typeof this.deployAltitude === "number" &&
|
||||
this.countOfJumps !== undefined &&
|
||||
typeof this.countOfJumps === "number"
|
||||
);
|
||||
}
|
||||
|
||||
private getListOfJumpTypes() {
|
||||
this.serviceJumpType.getListOfJumpTypes()
|
||||
.subscribe((data) => {
|
||||
data.sort((a, b) => a.name.localeCompare(b.name));
|
||||
this.listOfJumpType = data;
|
||||
this.countDatasLoaded = 1;
|
||||
this.serviceJumpType.getListOfJumpTypes().subscribe((data) => {
|
||||
data.sort((a, b) => a.name.localeCompare(b.name));
|
||||
this.listOfJumpType = data;
|
||||
this.countDatasLoaded = 1;
|
||||
|
||||
this.getListOfAircrafts();
|
||||
this.getListOfDropZones();
|
||||
this.getListOfGears();
|
||||
});
|
||||
this.getListOfAircrafts();
|
||||
this.getListOfDropZones();
|
||||
this.getListOfGears();
|
||||
});
|
||||
}
|
||||
|
||||
private getListOfAircrafts() {
|
||||
this.serviceAircraft.getListOfAircrafts(true)
|
||||
.subscribe((data) => {
|
||||
data.sort((a, b) => a.name.localeCompare(b.name));
|
||||
this.listOfAircraft = data;
|
||||
this.countDatasLoaded++;
|
||||
});
|
||||
this.serviceAircraft.getListOfAircrafts(true).subscribe((data) => {
|
||||
data.sort((a, b) => a.name.localeCompare(b.name));
|
||||
this.listOfAircraft = data;
|
||||
this.countDatasLoaded++;
|
||||
});
|
||||
}
|
||||
|
||||
private getListOfDropZones() {
|
||||
this.serviceDropzone.getListOfDropZones(true)
|
||||
.subscribe((data) => {
|
||||
data.sort((a, b) => (b.isFavorite ? 1 : 0) - (a.isFavorite ? 1 : 0) || a.name.localeCompare(b.name));
|
||||
this.listOfDropZone = data;
|
||||
this.listOfFilteredDropZone = data;
|
||||
this.countDatasLoaded++;
|
||||
});
|
||||
this.serviceDropzone.getListOfDropZones(true).subscribe((data) => {
|
||||
data.sort(
|
||||
(a, b) =>
|
||||
(b.isFavorite ? 1 : 0) - (a.isFavorite ? 1 : 0) ||
|
||||
a.name.localeCompare(b.name)
|
||||
);
|
||||
this.listOfDropZone = data;
|
||||
this.listOfFilteredDropZone = data;
|
||||
this.countDatasLoaded++;
|
||||
});
|
||||
}
|
||||
|
||||
private getListOfGears() {
|
||||
this.serviceGear.getListOfGears()
|
||||
.subscribe((data) => {
|
||||
data.sort((a, b) => b.id - a.id);
|
||||
this.listOfGear = data;
|
||||
this.countDatasLoaded++;
|
||||
});
|
||||
this.serviceGear.getListOfGears().subscribe((data) => {
|
||||
data.sort((a, b) => b.id - a.id);
|
||||
this.listOfGear = data;
|
||||
this.countDatasLoaded++;
|
||||
});
|
||||
}
|
||||
|
||||
private initForm() {
|
||||
@@ -212,8 +222,8 @@ export class NewJumpComponent implements OnInit {
|
||||
filterValue = event.toLowerCase();
|
||||
|
||||
this.listOfFilteredDropZone = this.listOfDropZone;
|
||||
this.listOfFilteredDropZone = this.listOfFilteredDropZone.filter((option) =>
|
||||
option.name.toLowerCase().includes(filterValue)
|
||||
this.listOfFilteredDropZone = this.listOfFilteredDropZone.filter(
|
||||
(option) => option.name.toLowerCase().includes(filterValue)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -228,12 +238,12 @@ export class NewJumpComponent implements OnInit {
|
||||
|
||||
public resetDz() {
|
||||
this.selectedDz = undefined;
|
||||
this.onChangeDz('');
|
||||
this.onChangeDz("");
|
||||
}
|
||||
|
||||
private updateTitle() {
|
||||
this.translateService.get("NewJump_Title").subscribe(
|
||||
data => { this.serviceComm.updatedComponentTitle(data); }
|
||||
);
|
||||
this.translateService.get("NewJump_Title").subscribe((data) => {
|
||||
this.serviceComm.updatedComponentTitle(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user