Fix autour des dates des jumps lors
de la création
This commit is contained in:
@@ -2,6 +2,7 @@ import { BrowserModule } from "@angular/platform-browser";
|
||||
import { APP_INITIALIZER, NgModule } from "@angular/core";
|
||||
import { RouterModule, Routes } from "@angular/router";
|
||||
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
|
||||
import { DatePipe } from '@angular/common';
|
||||
|
||||
import { AppComponent } from "./app.component";
|
||||
import { environment } from "../environments/environment";
|
||||
@@ -184,9 +185,10 @@ export function initConfig(configService: ConfigurationHelper) {
|
||||
DateService,
|
||||
RequestCache,
|
||||
ConfigurationHelper,
|
||||
DatePipe,
|
||||
{ provide: APP_INITIALIZER, useFactory: initConfig, deps: [ConfigurationHelper], multi: true },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: JwtAuthInterceptor, multi: true },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true }
|
||||
// { provide: HTTP_INTERCEPTORS, useClass: CachingInterceptor, multi: true }
|
||||
],
|
||||
bootstrap: [AppComponent],
|
||||
|
||||
@@ -10,13 +10,11 @@ import { AircraftService } from "../../services/aircraft.service";
|
||||
import { JumpService } from "../../services/jump.service";
|
||||
import { JumpTypeService } from "../../services/jump-type.service";
|
||||
import { GearService } from "../../services/gear.service";
|
||||
import { isNumber } from "util";
|
||||
import { ThrowStmt } from "@angular/compiler";
|
||||
|
||||
@Component({
|
||||
selector: "app-new-jump",
|
||||
templateUrl: "./new-jump.component.html",
|
||||
styleUrls: ["./new-jump.component.css"],
|
||||
styleUrls: ["./new-jump.component.css"]
|
||||
})
|
||||
export class NewJumpComponent implements OnInit {
|
||||
beginDate: Date;
|
||||
@@ -38,15 +36,13 @@ export class NewJumpComponent implements OnInit {
|
||||
private pendingAddRequest: boolean;
|
||||
comments: string;
|
||||
|
||||
constructor(
|
||||
private serviceComm: ServiceComm,
|
||||
private serviceJump: JumpService,
|
||||
private serviceJumpType: JumpTypeService,
|
||||
private serviceAircraft: AircraftService,
|
||||
private serviceDropzone: DropzoneService,
|
||||
private serviceGear: GearService,
|
||||
private dateService: DateService
|
||||
) {}
|
||||
constructor(private serviceComm: ServiceComm,
|
||||
private serviceJump: JumpService,
|
||||
private serviceJumpType: JumpTypeService,
|
||||
private serviceAircraft: AircraftService,
|
||||
private serviceDropzone: DropzoneService,
|
||||
private serviceGear: GearService,
|
||||
private dateService: DateService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.serviceComm.UpdatedComponentTitle("Add a new jump");
|
||||
@@ -60,19 +56,17 @@ 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.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);
|
||||
|
||||
setTimeout(() => {
|
||||
this.initForm();
|
||||
@@ -111,14 +105,14 @@ export class NewJumpComponent implements OnInit {
|
||||
}
|
||||
|
||||
private getListOfAircrafts() {
|
||||
this.serviceAircraft.getListOfAircrafts().subscribe((data) => {
|
||||
this.serviceAircraft.getListOfAircrafts(true).subscribe((data) => {
|
||||
this.listOfAircraft = data;
|
||||
this.countDatasLoaded++;
|
||||
});
|
||||
}
|
||||
|
||||
private getListOfDropZones() {
|
||||
this.serviceDropzone.getListOfDropZones().subscribe((data) => {
|
||||
this.serviceDropzone.getListOfDropZones(true).subscribe((data) => {
|
||||
data.sort((a, b) => (b.isFavorite ? 1 : 0) - (a.isFavorite ? 1 : 0));
|
||||
this.listOfDropZone = data;
|
||||
this.listOfFilteredDropZone = data;
|
||||
@@ -147,6 +141,7 @@ export class NewJumpComponent implements OnInit {
|
||||
this.selectedJumpType = undefined;
|
||||
|
||||
this.listOfFilteredDropZone = this.listOfDropZone;
|
||||
this.comments = undefined;
|
||||
}
|
||||
|
||||
public displayFn(data?: JumpTypeResp): string | undefined {
|
||||
|
||||
@@ -17,7 +17,7 @@ export class JumpReq {
|
||||
public deployAltitude: number;
|
||||
public withCutaway: boolean;
|
||||
public notes: string;
|
||||
public jumpDate: Date;
|
||||
public jumpDate: string; //Date;
|
||||
}
|
||||
|
||||
export class JumpResp {
|
||||
|
||||
@@ -12,10 +12,15 @@ export class AircraftService extends BaseService {
|
||||
super();
|
||||
}
|
||||
|
||||
public getListOfAircrafts(): Observable<Array<AircraftResp>> {
|
||||
return this.http.get<Array<AircraftResp>>(`${this.apiUrl}/Aircraft`, {
|
||||
headers: this.headers
|
||||
});
|
||||
public getListOfAircrafts(simple: boolean = false): Observable<Array<AircraftResp>> {
|
||||
let url : string;
|
||||
if (simple === true) {
|
||||
url = `${this.apiUrl}/Aircraft/GetSimple`;
|
||||
} else {
|
||||
url = `${this.apiUrl}/Aircraft`;
|
||||
}
|
||||
|
||||
return this.http.get<Array<AircraftResp>>(url, { headers: this.headers });
|
||||
}
|
||||
|
||||
public AddAircraft(aircraftName: string, dataImg: string) {
|
||||
|
||||
@@ -13,12 +13,18 @@ export class DropzoneService extends BaseService {
|
||||
super();
|
||||
}
|
||||
|
||||
public getListOfDropZones(): Observable<Array<DropZoneResp>> {
|
||||
return this.http.get<Array<DropZoneResp>>(`${this.apiUrl}/DropZone`,
|
||||
{ headers: this.headers })
|
||||
public getListOfDropZones(simple: boolean = false): Observable<Array<DropZoneResp>> {
|
||||
let url : string;
|
||||
if (simple === true) {
|
||||
url = `${this.apiUrl}/DropZone/GetSimple`;
|
||||
} else {
|
||||
url = `${this.apiUrl}/DropZone`;
|
||||
}
|
||||
|
||||
return this.http.get<Array<DropZoneResp>>(url, { headers: this.headers })
|
||||
.pipe(map(response => {
|
||||
const details = response.map(data => new DropZoneResp(data));
|
||||
return details;
|
||||
const details = response.map(data => new DropZoneResp(data));
|
||||
return details;
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { Observable } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
|
||||
@@ -10,7 +11,9 @@ import { BaseService } from "./base.service";
|
||||
|
||||
@Injectable()
|
||||
export class JumpService extends BaseService {
|
||||
constructor(private http: HttpClient, private dateService: DateService) {
|
||||
constructor(private http: HttpClient,
|
||||
private dateService: DateService,
|
||||
private datePipe: DatePipe) {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -27,66 +30,61 @@ export class JumpService extends BaseService {
|
||||
);
|
||||
}
|
||||
|
||||
public AddListOfJump(
|
||||
selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
selectedRig: number,
|
||||
withCutaway: boolean,
|
||||
beginDate: Date,
|
||||
endDate: Date,
|
||||
defaultExitAltitude: number,
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number,
|
||||
notes: string) {
|
||||
public AddListOfJump(selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
selectedRig: number,
|
||||
withCutaway: boolean,
|
||||
beginDate: Date,
|
||||
endDate: Date,
|
||||
defaultExitAltitude: number,
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number,
|
||||
notes: string)
|
||||
{
|
||||
const diffInDays = this.dateService.DiffBetweenDates(beginDate, endDate) + 1;
|
||||
const countOfJumpsPerDay = Math.trunc(countOfJumps / diffInDays);
|
||||
|
||||
for (let i = 1; beginDate.getTime() < endDate.getTime(); i++) {
|
||||
this.AddJumps(
|
||||
selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedRig,
|
||||
withCutaway,
|
||||
beginDate,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
countOfJumpsPerDay,
|
||||
notes
|
||||
);
|
||||
this.AddJumps(selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedRig,
|
||||
withCutaway,
|
||||
beginDate,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
countOfJumpsPerDay,
|
||||
notes);
|
||||
|
||||
beginDate = this.dateService.AddDays(beginDate, 1);
|
||||
}
|
||||
|
||||
const restfJumps = countOfJumps - countOfJumpsPerDay * (diffInDays - 1);
|
||||
|
||||
this.AddJumps(
|
||||
selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedRig,
|
||||
withCutaway,
|
||||
beginDate,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
restfJumps,
|
||||
notes
|
||||
);
|
||||
this.AddJumps(selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedRig,
|
||||
withCutaway,
|
||||
beginDate,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
restfJumps,
|
||||
notes);
|
||||
}
|
||||
|
||||
private AddJumps(
|
||||
selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
selectedRig: number,
|
||||
withCutaway: boolean,
|
||||
jumpDate: Date,
|
||||
defaultExitAltitude: number,
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number,
|
||||
notes: string
|
||||
) {
|
||||
private AddJumps(selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
selectedRig: number,
|
||||
withCutaway: boolean,
|
||||
jumpDate: Date,
|
||||
defaultExitAltitude: number,
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number,
|
||||
notes: string)
|
||||
{
|
||||
for (let i = 0; i < countOfJumps; i++) {
|
||||
const bodyNewjump: JumpReq = {
|
||||
jumpTypeId: selectedJumpType,
|
||||
@@ -98,7 +96,7 @@ export class JumpService extends BaseService {
|
||||
gearId: selectedRig,
|
||||
notes: notes,
|
||||
id: 0,
|
||||
jumpDate: jumpDate,
|
||||
jumpDate: this.datePipe.transform(jumpDate, "yyyy-MM-dd")
|
||||
};
|
||||
|
||||
this.http
|
||||
|
||||
Reference in New Issue
Block a user