Fix autour des dates.
This commit is contained in:
@@ -12,6 +12,7 @@ import { NewJumpComponent } from './new-jump/new-jump.component';
|
|||||||
import { ListOfAircraftsComponent } from './list-of-aircrafts/list-of-aircrafts.component';
|
import { ListOfAircraftsComponent } from './list-of-aircrafts/list-of-aircrafts.component';
|
||||||
import { ListOfJumpTypesComponent } from './list-of-jump-types/list-of-jump-types.component';
|
import { ListOfJumpTypesComponent } from './list-of-jump-types/list-of-jump-types.component';
|
||||||
|
|
||||||
|
import { DateService } from '../services/dateService';
|
||||||
import { ServiceApiGet } from '../services/serviceApiGet';
|
import { ServiceApiGet } from '../services/serviceApiGet';
|
||||||
import { ServiceApiPost } from '../services/serviceApiPost';
|
import { ServiceApiPost } from '../services/serviceApiPost';
|
||||||
import { ServiceComm } from '../services/serviceComm';
|
import { ServiceComm } from '../services/serviceComm';
|
||||||
@@ -74,7 +75,7 @@ const appRoutes: Routes = [
|
|||||||
MatIconModule
|
MatIconModule
|
||||||
],
|
],
|
||||||
exports: [HttpClientModule],
|
exports: [HttpClientModule],
|
||||||
providers: [ServiceApiPost, ServiceApiGet, ServiceComm],
|
providers: [ServiceApiPost, ServiceApiGet, ServiceComm, DateService],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { ServiceApiPost } from '../../services/serviceApiPost';
|
|||||||
import { JumpTypeResp } from '../../models/jumpType';
|
import { JumpTypeResp } from '../../models/jumpType';
|
||||||
import { AircraftResp } from '../../models/aircraft';
|
import { AircraftResp } from '../../models/aircraft';
|
||||||
import { DropZoneResp } from '../../models/dropzone';
|
import { DropZoneResp } from '../../models/dropzone';
|
||||||
|
import { DateService } from '../../services/dateService';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -29,25 +30,22 @@ export class NewJumpComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(private serviceComm: ServiceComm,
|
constructor(private serviceComm: ServiceComm,
|
||||||
private serviceApiGet: ServiceApiGet,
|
private serviceApiGet: ServiceApiGet,
|
||||||
private serviceApiPost: ServiceApiPost) {
|
private serviceApiPost: ServiceApiPost,
|
||||||
|
private dateService: DateService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.serviceComm.updatedComponentTitle('Add a new jump');
|
this.serviceComm.updatedComponentTitle('Add a new jump');
|
||||||
|
|
||||||
this.beginDate = new Date();
|
|
||||||
|
|
||||||
const t = this.beginDate.getTime();
|
|
||||||
this.endDate = new Date();
|
this.endDate = new Date();
|
||||||
this.endDate.setTime(t - (1000 * 60 * 60 * 24));
|
|
||||||
|
this.beginDate = this.dateService.AddDays(new Date(), -1);
|
||||||
|
|
||||||
this.defaultExitAltitude = 4000;
|
this.defaultExitAltitude = 4000;
|
||||||
this.defaultDeployAltitude = 1000;
|
this.defaultDeployAltitude = 1000;
|
||||||
this.countOfJumps = 0;
|
this.countOfJumps = 1;
|
||||||
|
|
||||||
this.getListOfJumpTypes();
|
this.getListOfJumpTypes();
|
||||||
this.getListOfAircrafts();
|
|
||||||
this.getListOfDropZones();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onFormSubmit() {
|
onFormSubmit() {
|
||||||
@@ -69,6 +67,8 @@ export class NewJumpComponent implements OnInit {
|
|||||||
this.serviceApiGet.getListOfJumpTypes()
|
this.serviceApiGet.getListOfJumpTypes()
|
||||||
.subscribe(data => {
|
.subscribe(data => {
|
||||||
this.listOfJumpType = data;
|
this.listOfJumpType = data;
|
||||||
|
this.getListOfAircrafts();
|
||||||
|
this.getListOfDropZones();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
Front/skydivelogs-app/src/services/dateService.ts
Normal file
26
Front/skydivelogs-app/src/services/dateService.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DateService {
|
||||||
|
private milliSeconInDay: number;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.milliSeconInDay = 1000 * 60 * 60 * 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddDays(currentDate: Date, nbDays: number): Date {
|
||||||
|
const totalMilliSeconds = nbDays * this.milliSeconInDay;
|
||||||
|
const currentTime = currentDate.getTime();
|
||||||
|
|
||||||
|
currentDate.setTime(currentTime + totalMilliSeconds);
|
||||||
|
|
||||||
|
return currentDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DiffBetweenDates(beginDate: Date, endDate: Date): number {
|
||||||
|
const diffInTime = endDate.getTime() - beginDate.getTime();
|
||||||
|
const diffInDays = Math.round(diffInTime / (1000 * 3600 * 24));
|
||||||
|
|
||||||
|
return diffInDays;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { Observable } from "rxjs";
|
import { Observable } from 'rxjs';
|
||||||
import { map } from "rxjs/operators";
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
import { DropZoneResp } from "../models/dropzone";
|
import { DropZoneResp } from '../models/dropzone';
|
||||||
import { JumpResp } from "../models/jump";
|
import { JumpResp } from '../models/jump';
|
||||||
import { AircraftResp } from "../models/aircraft";
|
import { AircraftResp } from '../models/aircraft';
|
||||||
import { JumpTypeResp } from "../models/jumpType";
|
import { JumpTypeResp } from '../models/jumpType';
|
||||||
import {
|
import {
|
||||||
StatsResp,
|
StatsResp,
|
||||||
StatsByDzResp,
|
StatsByDzResp,
|
||||||
@@ -14,13 +14,13 @@ import {
|
|||||||
StatsByJumpTypeResp,
|
StatsByJumpTypeResp,
|
||||||
StatsByRigResp,
|
StatsByRigResp,
|
||||||
StatsByYearResp
|
StatsByYearResp
|
||||||
} from "../models/statsresp";
|
} from '../models/statsresp';
|
||||||
import { environment } from "../environments/environment";
|
import { environment } from '../environments/environment';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ServiceApiGet {
|
export class ServiceApiGet {
|
||||||
private readonly headers = new HttpHeaders({
|
private readonly headers = new HttpHeaders({
|
||||||
"Access-Control-Allow-Origin": environment.urlApi
|
'Access-Control-Allow-Origin': environment.urlApi
|
||||||
});
|
});
|
||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,65 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
|
|
||||||
import { JumpReq } from "../models/jump";
|
import { JumpReq } from '../models/jump';
|
||||||
import { environment } from "../environments/environment";
|
import { environment } from '../environments/environment';
|
||||||
|
import { DateService } from './dateService';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ServiceApiPost {
|
export class ServiceApiPost {
|
||||||
private readonly headers = new HttpHeaders({
|
private readonly headers = new HttpHeaders({
|
||||||
"Access-Control-Allow-Origin": environment.urlApi
|
'Access-Control-Allow-Origin': environment.urlApi
|
||||||
});
|
});
|
||||||
constructor(private http: HttpClient) {}
|
|
||||||
|
|
||||||
public AddJumps(
|
constructor(private http: HttpClient,
|
||||||
|
private dateService: DateService) { }
|
||||||
|
|
||||||
|
public AddListOfJump(
|
||||||
|
selectedJumpType: number,
|
||||||
|
selectedAircraft: number,
|
||||||
|
selectedDz: number,
|
||||||
|
selectedRig: number,
|
||||||
|
withCutaway: boolean,
|
||||||
|
beginDate: Date,
|
||||||
|
endDate: Date,
|
||||||
|
defaultExitAltitude: number,
|
||||||
|
defaultDeployAltitude: number,
|
||||||
|
countOfJumps: number
|
||||||
|
) {
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
beginDate = this.dateService.AddDays(beginDate, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const restfJumps = countOfJumps - countOfJumpsPerDay * (diffInDays - 1);
|
||||||
|
this.AddJumps(
|
||||||
|
selectedJumpType,
|
||||||
|
selectedAircraft,
|
||||||
|
selectedDz,
|
||||||
|
selectedRig,
|
||||||
|
withCutaway,
|
||||||
|
beginDate,
|
||||||
|
defaultExitAltitude,
|
||||||
|
defaultDeployAltitude,
|
||||||
|
restfJumps
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AddJumps(
|
||||||
selectedJumpType: number,
|
selectedJumpType: number,
|
||||||
selectedAircraft: number,
|
selectedAircraft: number,
|
||||||
selectedDz: number,
|
selectedDz: number,
|
||||||
@@ -31,7 +79,7 @@ export class ServiceApiPost {
|
|||||||
exitAltitude: defaultExitAltitude,
|
exitAltitude: defaultExitAltitude,
|
||||||
deployAltitude: defaultDeployAltitude,
|
deployAltitude: defaultDeployAltitude,
|
||||||
gearId: selectedRig,
|
gearId: selectedRig,
|
||||||
notes: "",
|
notes: '',
|
||||||
id: 0,
|
id: 0,
|
||||||
jumpDate: jumpDate
|
jumpDate: jumpDate
|
||||||
};
|
};
|
||||||
@@ -43,51 +91,4 @@ export class ServiceApiPost {
|
|||||||
// .subscribe(data => console.log(data));
|
// .subscribe(data => console.log(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddListOfJump(
|
|
||||||
selectedJumpType: number,
|
|
||||||
selectedAircraft: number,
|
|
||||||
selectedDz: number,
|
|
||||||
selectedRig: number,
|
|
||||||
withCutaway: boolean,
|
|
||||||
beginDate: Date,
|
|
||||||
endDate: Date,
|
|
||||||
defaultExitAltitude: number,
|
|
||||||
defaultDeployAltitude: number,
|
|
||||||
countOfJumps: number
|
|
||||||
) {
|
|
||||||
const diffInTime = endDate.getTime() - beginDate.getTime();
|
|
||||||
const diffInDays = Math.round(diffInTime / (1000 * 3600 * 24));
|
|
||||||
|
|
||||||
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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user