New service and model for the tunnel flights
This commit is contained in:
@@ -38,6 +38,7 @@ import { AuthGuardService } from "../services/auth-guard.service";
|
||||
import { ImageService } from "../services/image.service";
|
||||
import { ConfigurationHelper } from "../services/configuration-helper";
|
||||
import { ServiceCacheApi } from "../services/service-cache-api.service";
|
||||
import { TunnelService } from "../services/tunnel.service";
|
||||
|
||||
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
|
||||
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
|
||||
@@ -193,6 +194,7 @@ export function initConfig(configService: ConfigurationHelper) {
|
||||
],
|
||||
exports: [HttpClientModule],
|
||||
providers: [
|
||||
TunnelService,
|
||||
ImageService,
|
||||
AircraftService,
|
||||
DropzoneService,
|
||||
|
||||
@@ -3,16 +3,38 @@ import { formatDate } from '@angular/common';
|
||||
import { DateAdapter, MAT_DATE_FORMATS, NativeDateAdapter } from "@angular/material/core";
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
import { TunnelResp } from "../../models/tunnel";
|
||||
|
||||
import { DateService } from 'src/services/date.service';
|
||||
import { TunnelService } from 'src/services/tunnel.service';
|
||||
import { ServiceComm } from 'src/services/service-comm.service';
|
||||
import { StatsService } from 'src/services/stats.service';
|
||||
|
||||
export const PICK_FORMATS = {
|
||||
parse: { dateInput: 'yy MM dd' },
|
||||
display: {
|
||||
dateInput: 'yyyy-MM-dd',
|
||||
monthYearLabel: 'yyyy MMM',
|
||||
dateA11yLabel: 'yyyy MM dd',
|
||||
monthYearA11yLabel: 'yyyy MMMM',
|
||||
}
|
||||
};
|
||||
class PickDateAdapter extends NativeDateAdapter {
|
||||
format(date: Date, displayFormat: Object): string {
|
||||
return formatDate(date, displayFormat.toString(), "en");
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-new-tunnel-flight',
|
||||
templateUrl: './new-tunnel-flight.component.html',
|
||||
styleUrls: ['./new-tunnel-flight.component.css']
|
||||
styleUrls: ['./new-tunnel-flight.component.css'],
|
||||
providers: [
|
||||
{ provide: DateAdapter, useClass: PickDateAdapter },
|
||||
{ provide: MAT_DATE_FORMATS, useValue: PICK_FORMATS }
|
||||
]
|
||||
})
|
||||
export class NewTunnelFlightComponent {
|
||||
export class NewTunnelFlightComponent implements OnInit {
|
||||
public beginDate: Date;
|
||||
public endDate: Date;
|
||||
public minutesOfFlight: number;
|
||||
@@ -45,7 +67,20 @@ export class NewTunnelFlightComponent {
|
||||
onFormSubmit() {
|
||||
this.pendingAddRequest = true;
|
||||
|
||||
this.serviceTunnel.AddFlight(this.selectedTunnel.id,
|
||||
this.beginDate,
|
||||
this.minutesOfFlight,
|
||||
this.comments)
|
||||
.subscribe(() => {
|
||||
this.statsService.resetStats();
|
||||
this.comments = undefined;
|
||||
|
||||
if (this.resetForm === true) {
|
||||
this.initForm();
|
||||
}
|
||||
this.pendingAddRequest = false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public isValidatedForm(): boolean {
|
||||
@@ -56,7 +91,7 @@ export class NewTunnelFlightComponent {
|
||||
}
|
||||
|
||||
private getListOfTunnels() {
|
||||
this.serviceTunnel.getListOfTunnels(true).subscribe((data) => {
|
||||
this.serviceTunnel.getListOfTunnels().subscribe((data) => {
|
||||
data.sort((a, b) => a.name.localeCompare(b.name));
|
||||
this.listOfTunnel = data;
|
||||
this.countDatasLoaded++;
|
||||
|
||||
@@ -10,5 +10,6 @@ export enum CacheApiKey {
|
||||
StatsByGear,
|
||||
StatsOfLastYear,
|
||||
StatsOfLastMonth,
|
||||
StatsByYear
|
||||
StatsByYear,
|
||||
Tunnel
|
||||
}
|
||||
|
||||
25
Front/skydivelogs-app/src/models/tunnel.ts
Normal file
25
Front/skydivelogs-app/src/models/tunnel.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export class TunnelReq {
|
||||
constructor(data: any) {
|
||||
Object.assign(this, data);
|
||||
}
|
||||
|
||||
public id: number;
|
||||
public comment: string;
|
||||
public tunnelId: number;
|
||||
public nbMinutes: number;
|
||||
public flightDate: string;
|
||||
}
|
||||
|
||||
export class TunnelResp {
|
||||
constructor(data: any) {
|
||||
Object.assign(this, data);
|
||||
}
|
||||
|
||||
public id: number;
|
||||
public latitude: string;
|
||||
public longitude: string;
|
||||
public name: string;
|
||||
public address: string;
|
||||
public website: string;
|
||||
public email: string;
|
||||
}
|
||||
@@ -64,8 +64,7 @@ export class JumpService extends BaseService {
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number,
|
||||
notes: string,
|
||||
isSpecial: boolean): Observable<any[]>
|
||||
{
|
||||
isSpecial: boolean): Observable<any[]> {
|
||||
this.callsToAdd = new Array<Observable<any>>();
|
||||
const diffInDays = this.dateService.DiffBetweenDates(beginDate, endDate) + 1;
|
||||
const countOfJumpsPerDay = Math.trunc(countOfJumps / diffInDays);
|
||||
@@ -136,8 +135,7 @@ export class JumpService extends BaseService {
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number,
|
||||
notes: string,
|
||||
isSpecial: boolean)
|
||||
{
|
||||
isSpecial: boolean) {
|
||||
for (let i = 0; i < countOfJumps; i++) {
|
||||
const bodyNewjump: JumpReq = {
|
||||
jumpTypeId: selectedJumpType,
|
||||
@@ -153,9 +151,7 @@ export class JumpService extends BaseService {
|
||||
isSpecial: isSpecial
|
||||
};
|
||||
|
||||
let call = this.http.post(`${this.apiUrl}/Jump`,
|
||||
bodyNewjump,
|
||||
{ headers: this.headers });
|
||||
let call = this.http.post(`${this.apiUrl}/Jump`, bodyNewjump, { headers: this.headers });
|
||||
|
||||
this.callsToAdd.push(call);
|
||||
}
|
||||
@@ -171,8 +167,7 @@ export class JumpService extends BaseService {
|
||||
let allGears: Array<GearResp>;
|
||||
this.gearService.getFromCache().subscribe(data => { allGears = data; });
|
||||
|
||||
return apiResp.map((data) =>
|
||||
{
|
||||
return apiResp.map((data) => {
|
||||
let tmp = new Jump(data);
|
||||
|
||||
tmp.dropZone = allDropzones.find(d => d.id == data.dropZoneId);
|
||||
|
||||
52
Front/skydivelogs-app/src/services/tunnel.service.ts
Normal file
52
Front/skydivelogs-app/src/services/tunnel.service.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { DatePipe } from "@angular/common";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { Observable } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
|
||||
import { TunnelResp, TunnelReq } from "../models/tunnel";
|
||||
|
||||
import { BaseService } from "./base.service";
|
||||
import { CacheApiKey } from "../models/cache-api-key.enum";
|
||||
|
||||
@Injectable()
|
||||
export class TunnelService extends BaseService {
|
||||
private datePipe: DatePipe;
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
super();
|
||||
}
|
||||
|
||||
public getListOfTunnels(): Observable<Array<TunnelResp>> {
|
||||
let callToApi = this.http.get<Array<TunnelResp>>(`${this.apiUrl}/Tunnel`, { headers: this.headers });
|
||||
return this.serviceCacheApi.get<Array<TunnelResp>>(CacheApiKey.Gear, callToApi);
|
||||
}
|
||||
|
||||
public AddFlight(selectedTunnel: number,
|
||||
flightDate: Date,
|
||||
nbMinutes: number,
|
||||
comment: string)
|
||||
{
|
||||
|
||||
const bodyNewFlight: TunnelReq = {
|
||||
id: 0,
|
||||
tunnelId: selectedTunnel,
|
||||
flightDate: this.datePipe.transform(flightDate, "yyyy-MM-dd"),
|
||||
comment: comment,
|
||||
nbMinutes: nbMinutes
|
||||
};
|
||||
|
||||
return this.http.post(`${this.apiUrl}/Tunnel`, bodyNewFlight, { headers: this.headers});
|
||||
}
|
||||
|
||||
public getById(id: number) : Observable<TunnelResp> {
|
||||
return this.serviceCacheApi.getByKey<Array<TunnelResp>>(CacheApiKey.Tunnel)
|
||||
.pipe(map(data => {
|
||||
return data.find(f => f.id === id);
|
||||
}));
|
||||
}
|
||||
|
||||
public getFromCache(): Observable<Array<TunnelResp>> {
|
||||
return this.serviceCacheApi.getByKey<Array<TunnelResp>>(CacheApiKey.Tunnel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user