Amélioration du formulaire d'ajout pour appeler

l'API X fois
This commit is contained in:
Sébastien André
2019-10-31 16:41:22 +01:00
parent cd95b2c9b1
commit 30b7f33bdf
5 changed files with 81 additions and 32 deletions

View File

@@ -1 +1 @@
[{"Id":1,"JumpTypeId":1,"AircraftId":5,"DropZoneId":6,"GearId":8,"ExitAltitude":40001,"DeployAltitude":10002,"WithCutaway":true,"Notes":"","JumpDate":"0001-01-01T00:00:00"},{"Id":2,"JumpTypeId":1,"AircraftId":5,"DropZoneId":6,"GearId":8,"ExitAltitude":40001,"DeployAltitude":10002,"WithCutaway":true,"Notes":"","JumpDate":"0001-01-01T00:00:00"}]
[{"Id":1,"JumpTypeId":1,"AircraftId":5,"DropZoneId":6,"GearId":8,"ExitAltitude":40001,"DeployAltitude":10002,"WithCutaway":true,"Notes":"","JumpDate":"0001-01-01T00:00:00"},{"Id":2,"JumpTypeId":1,"AircraftId":5,"DropZoneId":6,"GearId":8,"ExitAltitude":40001,"DeployAltitude":10002,"WithCutaway":true,"Notes":"","JumpDate":"0001-01-01T00:00:00"},{"Id":3,"JumpTypeId":1,"AircraftId":4,"DropZoneId":6,"GearId":8,"ExitAltitude":4000,"DeployAltitude":1000,"WithCutaway":false,"Notes":"","JumpDate":"2019-10-31T23:00:00Z"},{"Id":4,"JumpTypeId":1,"AircraftId":4,"DropZoneId":6,"GearId":8,"ExitAltitude":4000,"DeployAltitude":1000,"WithCutaway":false,"Notes":"","JumpDate":"2019-10-29T23:00:00Z"}]

View File

@@ -34,11 +34,18 @@
<mat-checkbox [(ngModel)]="withCutaway" name="withCutaway">With a cutaway ?</mat-checkbox>
<!-- <mat-form-field>
<input matInput [matDatepicker]="beginDateDp" [(ngModel)]="beginDate2" name="beginDate2" disabled>
<mat-datepicker-toggle matSuffix [for]="beginDateDp"></mat-datepicker-toggle>
<mat-datepicker #beginDateDp disabled="false"></mat-datepicker>
</mat-form-field> -->
<mat-form-field>
<input matInput [matDatepicker]="beginDateDp" [(ngModel)]="beginDate" name="beginDate" disabled>
<mat-datepicker-toggle matSuffix [for]="beginDateDp"></mat-datepicker-toggle>
<mat-datepicker #beginDateDp disabled="false"></mat-datepicker>
</mat-form-field>
<mat-form-field>
<input matInput [matDatepicker]="endDateDp" [(ngModel)]="endDate" name="endDate" disabled>
<mat-datepicker-toggle matSuffix [for]="endDateDp"></mat-datepicker-toggle>

View File

@@ -24,6 +24,11 @@ export class NewJumpComponent implements OnInit {
constructor(private serviceComm: ServiceComm,
private serviceApiGet: ServiceApiGet,
private serviceApiPost: ServiceApiPost) {
}
ngOnInit() {
this.serviceComm.updatedComponentTitle('Add a new jump');
this.beginDate = new Date();
this.endDate = new Date();
@@ -32,12 +37,8 @@ export class NewJumpComponent implements OnInit {
this.countOfJumps = 0;
}
ngOnInit() {
this.serviceComm.updatedComponentTitle('Add a new jump');
}
onFormSubmit() {
this.serviceApiPost.AddJump(
this.serviceApiPost.AddListOfJump(
this.selectedJumpType,
this.selectedAircraft,
this.selectedDz,

View File

@@ -12,6 +12,7 @@ export class JumpReq {
public deployAltitude: number;
public withCutaway: boolean;
public notes: string;
public jumpDate: Date;
}
export class JumpResp {
@@ -28,4 +29,5 @@ export class JumpResp {
public deployAltitude: number;
public withCutaway: boolean;
public notes: string;
public jumpDate: Date;
}

View File

@@ -1,13 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { DropZoneResp } from '../models/dropzone';
import { JumpResp, JumpReq } from '../models/jump';
import { AircraftResp } from '../models/aircraft';
import { JumpTypeResp } from '../models/jumpType';
import { StatsResp, StatsByDzResp, StatsByAircraftResp, StatsByJumpTypeResp, StatsByRigResp, StatsByYearResp } from '../models/statsresp';
import { JumpReq } from '../models/jump';
@Injectable()
@@ -17,9 +11,39 @@ export class ServiceApiPost {
});
constructor(private http: HttpClient) { }
public AddJumps(selectedJumpType: number,
selectedAircraft: number,
selectedDz: number,
selectedRig: number,
withCutaway: boolean,
jumpDate: Date,
defaultExitAltitude: number,
defaultDeployAltitude: number,
countOfJumps: number) {
for (let i = 0; i < countOfJumps; i++) {
const bodyNewjump: JumpReq = {
jumpTypeId: selectedJumpType,
aircraftId: selectedAircraft,
dropZoneId: selectedDz,
withCutaway: withCutaway,
exitAltitude: defaultExitAltitude,
deployAltitude: defaultDeployAltitude,
gearId: selectedRig,
notes: '',
id: 0,
jumpDate: jumpDate
};
public AddJump(selectedJumpType: number,
console.log(bodyNewjump.jumpDate);
// this.http.post('http://localhost:5000/api/Jump',
// bodyNewjump,
// { headers: this.headers })
// .subscribe(data => console.log(data));
}
}
public AddListOfJump(selectedJumpType: number,
selectedAircraft: number,
selectedDz: number,
selectedRig: number,
@@ -30,24 +54,39 @@ export class ServiceApiPost {
defaultDeployAltitude: number,
countOfJumps: number) {
const bodyNewjump: JumpReq = {
jumpTypeId: selectedJumpType,
aircraftId: selectedAircraft,
dropZoneId: selectedDz,
withCutaway: withCutaway,
//beginDate: beginDate,
//endDate: endDate,
exitAltitude: defaultExitAltitude,
deployAltitude: defaultDeployAltitude,
//countOfJumps: countOfJumps
gearId: selectedRig,
notes: '',
id: 0
};
const diffInTime = endDate.getTime() - beginDate.getTime();
const diffInDays = Math.round(diffInTime / (1000 * 3600 * 24));
this.http.post('http://localhost:5000/api/Jump',
bodyNewjump,
{ headers: this.headers })
.subscribe(data => console.log(data));
const countOfJumpsPerDay = Math.trunc(countOfJumps / diffInDays);
let temp: Date = beginDate;
for (let i = 1; temp.getDate() < endDate.getDate(); i++) {
this.AddJumps(
selectedJumpType,
selectedAircraft,
selectedDz,
selectedRig,
withCutaway,
temp,
defaultExitAltitude,
defaultDeployAltitude,
countOfJumpsPerDay
);
temp.setDate(temp.getDate() + 1);
}
const restfJumps = countOfJumps - (countOfJumpsPerDay * (diffInDays - 1));
this.AddJumps(
selectedJumpType,
selectedAircraft,
selectedDz,
selectedRig,
withCutaway,
beginDate,
defaultExitAltitude,
defaultDeployAltitude,
restfJumps
);
}
}