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; listOfAircraft: Array; listOfDropZone: Array; listOfGear: Array; 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; }); } }