Files
SkydiveLogs/Front/skydivelogs-app/src/app/new-jump/new-jump.component.ts
2019-11-24 18:39:18 +01:00

101 lines
2.7 KiB
TypeScript

import { Component, OnInit } from "@angular/core";
import { ServiceComm } from "../../services/service-comm.service";
import { ServiceApiGet } from "../../services/service-api-get.service";
import { ServiceApiPost } from "../../services/service-api-post.service";
import { JumpTypeResp } from "../../models/jumpType";
import { AircraftResp } from "../../models/aircraft";
import { DropZoneResp } from "../../models/dropzone";
import { DateService } from "../../services/date.service";
import { GearResp } from "../../models/gear";
@Component({
selector: "app-new-jump",
templateUrl: "./new-jump.component.html",
styleUrls: ["./new-jump.component.css"]
})
export class NewJumpComponent implements OnInit {
beginDate: Date;
endDate: Date;
defaultExitAltitude: number;
defaultDeployAltitude: number;
countOfJumps: number;
selectedDz: number;
selectedGear: number;
selectedAircraft: number;
selectedJumpType: number;
withCutaway: boolean;
listOfJumpType: Array<JumpTypeResp>;
listOfAircraft: Array<AircraftResp>;
listOfDropZone: Array<DropZoneResp>;
listOfGear: Array<GearResp>;
constructor(
private serviceComm: ServiceComm,
private serviceApiGet: ServiceApiGet,
private serviceApiPost: ServiceApiPost,
private dateService: DateService
) {}
ngOnInit() {
this.serviceComm.updatedComponentTitle("Add a new jump");
this.endDate = new Date();
this.beginDate = this.dateService.AddDays(new Date(), -1);
this.defaultExitAltitude = 4000;
this.defaultDeployAltitude = 1000;
this.countOfJumps = 1;
this.getListOfJumpTypes();
}
onFormSubmit() {
this.serviceApiPost.AddListOfJump(
this.selectedJumpType,
this.selectedAircraft,
this.selectedDz,
this.selectedGear,
this.withCutaway,
this.beginDate,
this.endDate,
this.defaultExitAltitude,
this.defaultDeployAltitude,
this.countOfJumps
);
}
public isValidatedForm: boolean =
this.selectedDz != undefined &&
this.selectedGear != undefined &&
this.selectedAircraft != undefined &&
this.selectedJumpType != undefined;
private getListOfJumpTypes() {
this.serviceApiGet.getListOfJumpTypes().subscribe(data => {
this.listOfJumpType = data;
this.getListOfAircrafts();
this.getListOfDropZones();
this.getListOfGears();
});
}
private getListOfAircrafts() {
this.serviceApiGet.getListOfAircrafts().subscribe(data => {
this.listOfAircraft = data;
});
}
private getListOfDropZones() {
this.serviceApiGet.getListOfDropZones().subscribe(data => {
this.listOfDropZone = data;
});
}
private getListOfGears() {
this.serviceApiGet.getListOfGears().subscribe(data => {
this.listOfGear = data;
});
}
}