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 { ListOfJumpTypesComponent } from './list-of-jump-types/list-of-jump-types.component';
|
||||
|
||||
import { DateService } from '../services/dateService';
|
||||
import { ServiceApiGet } from '../services/serviceApiGet';
|
||||
import { ServiceApiPost } from '../services/serviceApiPost';
|
||||
import { ServiceComm } from '../services/serviceComm';
|
||||
@@ -74,7 +75,7 @@ const appRoutes: Routes = [
|
||||
MatIconModule
|
||||
],
|
||||
exports: [HttpClientModule],
|
||||
providers: [ServiceApiPost, ServiceApiGet, ServiceComm],
|
||||
providers: [ServiceApiPost, ServiceApiGet, ServiceComm, DateService],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
export class AppModule { }
|
||||
|
||||
@@ -5,6 +5,7 @@ import { ServiceApiPost } from '../../services/serviceApiPost';
|
||||
import { JumpTypeResp } from '../../models/jumpType';
|
||||
import { AircraftResp } from '../../models/aircraft';
|
||||
import { DropZoneResp } from '../../models/dropzone';
|
||||
import { DateService } from '../../services/dateService';
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -29,25 +30,22 @@ export class NewJumpComponent implements OnInit {
|
||||
|
||||
constructor(private serviceComm: ServiceComm,
|
||||
private serviceApiGet: ServiceApiGet,
|
||||
private serviceApiPost: ServiceApiPost) {
|
||||
private serviceApiPost: ServiceApiPost,
|
||||
private dateService: DateService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.serviceComm.updatedComponentTitle('Add a new jump');
|
||||
|
||||
this.beginDate = new Date();
|
||||
|
||||
const t = this.beginDate.getTime();
|
||||
this.endDate = new Date();
|
||||
this.endDate.setTime(t - (1000 * 60 * 60 * 24));
|
||||
|
||||
this.beginDate = this.dateService.AddDays(new Date(), -1);
|
||||
|
||||
this.defaultExitAltitude = 4000;
|
||||
this.defaultDeployAltitude = 1000;
|
||||
this.countOfJumps = 0;
|
||||
this.countOfJumps = 1;
|
||||
|
||||
this.getListOfJumpTypes();
|
||||
this.getListOfAircrafts();
|
||||
this.getListOfDropZones();
|
||||
}
|
||||
|
||||
onFormSubmit() {
|
||||
@@ -69,6 +67,8 @@ export class NewJumpComponent implements OnInit {
|
||||
this.serviceApiGet.getListOfJumpTypes()
|
||||
.subscribe(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 { HttpClient, HttpHeaders } from "@angular/common/http";
|
||||
import { Observable } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
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 } from "../models/jump";
|
||||
import { AircraftResp } from "../models/aircraft";
|
||||
import { JumpTypeResp } from "../models/jumpType";
|
||||
import { DropZoneResp } from '../models/dropzone';
|
||||
import { JumpResp } from '../models/jump';
|
||||
import { AircraftResp } from '../models/aircraft';
|
||||
import { JumpTypeResp } from '../models/jumpType';
|
||||
import {
|
||||
StatsResp,
|
||||
StatsByDzResp,
|
||||
@@ -14,13 +14,13 @@ import {
|
||||
StatsByJumpTypeResp,
|
||||
StatsByRigResp,
|
||||
StatsByYearResp
|
||||
} from "../models/statsresp";
|
||||
import { environment } from "../environments/environment";
|
||||
} from '../models/statsresp';
|
||||
import { environment } from '../environments/environment';
|
||||
|
||||
@Injectable()
|
||||
export class ServiceApiGet {
|
||||
private readonly headers = new HttpHeaders({
|
||||
"Access-Control-Allow-Origin": environment.urlApi
|
||||
'Access-Control-Allow-Origin': environment.urlApi
|
||||
});
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
|
||||
@@ -1,17 +1,65 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
|
||||
import { JumpReq } from "../models/jump";
|
||||
import { environment } from "../environments/environment";
|
||||
import { JumpReq } from '../models/jump';
|
||||
import { environment } from '../environments/environment';
|
||||
import { DateService } from './dateService';
|
||||
|
||||
@Injectable()
|
||||
export class ServiceApiPost {
|
||||
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,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
@@ -31,7 +79,7 @@ export class ServiceApiPost {
|
||||
exitAltitude: defaultExitAltitude,
|
||||
deployAltitude: defaultDeployAltitude,
|
||||
gearId: selectedRig,
|
||||
notes: "",
|
||||
notes: '',
|
||||
id: 0,
|
||||
jumpDate: jumpDate
|
||||
};
|
||||
@@ -43,51 +91,4 @@ export class ServiceApiPost {
|
||||
// .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