Modification de la récupération des sauts et mapping entre les IDs des données référentielles et les données présentes dans le cache.

This commit is contained in:
Sébastien André
2021-05-02 15:00:11 +02:00
parent 192a985b50
commit f59d1828ca
9 changed files with 70 additions and 15 deletions

View File

@@ -46,7 +46,8 @@ export class ListOfDzsComponent implements OnInit {
} }
private getListOfDropZones() { private getListOfDropZones() {
this.serviceApi.getListOfDropZones().subscribe((data) => { this.serviceApi.getListOfDropZones()
.subscribe((data) => {
setTimeout(() => { setTimeout(() => {
data.sort((a, b) => (b.isFavorite ? 1 : 0) - (a.isFavorite ? 1 : 0) || a.name.localeCompare(b.name)); data.sort((a, b) => (b.isFavorite ? 1 : 0) - (a.isFavorite ? 1 : 0) || a.name.localeCompare(b.name));
this.dataSourceTable = new MatTableDataSource<DropZoneResp>(data); this.dataSourceTable = new MatTableDataSource<DropZoneResp>(data);

View File

@@ -15,6 +15,7 @@
</div> </div>
<div class="paragraph" style="margin-top: 20px;"> <div class="paragraph" style="margin-top: 20px;">
<label class="left130">Refresh</label>
<mat-icon aria-hidden="false" aria-label="Force the refresh of the stats" style="cursor: pointer;" <mat-icon aria-hidden="false" aria-label="Force the refresh of the stats" style="cursor: pointer;"
(click)='refreshStats()'>cached</mat-icon> (click)='refreshStats()'>cached</mat-icon>
</div> </div>

View File

@@ -32,6 +32,12 @@ export class JumpResp {
public aircraft: AircraftResp; public aircraft: AircraftResp;
public dropZone: DropZoneResp; public dropZone: DropZoneResp;
public gear: GearResp; public gear: GearResp;
public jumpTypeId: number;
public aircraftId: number;
public dropZoneId: number;
public gearId: number;
public exitAltitude: number; public exitAltitude: number;
public deployAltitude: number; public deployAltitude: number;
public withCutaway: boolean; public withCutaway: boolean;

View File

@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from "rxjs/operators";
import { AircraftResp, AircraftReq } from '../models/aircraft'; import { AircraftResp, AircraftReq } from '../models/aircraft';
@@ -36,4 +37,11 @@ export class AircraftService extends BaseService {
bodyNewAircraft, bodyNewAircraft,
{ headers: this.headers }); { headers: this.headers });
} }
public getById(id: number) : Observable<AircraftResp> {
return this.serviceCacheApi.getByKey<Array<AircraftResp>>(CacheApiKey.Aircraft)
.pipe(map(data => {
return data.find(f => f.id === id);
}));
}
} }

View File

@@ -77,4 +77,11 @@ export class DropzoneService extends BaseService {
bodyNewDropZone, bodyNewDropZone,
{ headers: this.headers }); { headers: this.headers });
} }
public getById(id: number) : Observable<DropZoneResp> {
return this.serviceCacheApi.getByKey<Array<DropZoneResp>>(CacheApiKey.Dropzone)
.pipe(map(data => {
return data.find(f => f.id === id);
}));
}
} }

View File

@@ -1,6 +1,7 @@
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http"; import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs"; import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { GearResp, GearReq } from "../models/gear"; import { GearResp, GearReq } from "../models/gear";
@@ -40,4 +41,11 @@ export class GearService extends BaseService {
this.serviceCacheApi.delete(CacheApiKey.Gear); this.serviceCacheApi.delete(CacheApiKey.Gear);
return this.http.post(`${this.apiUrl}/Gear`, bodyNewGear, { headers: this.headers}); return this.http.post(`${this.apiUrl}/Gear`, bodyNewGear, { headers: this.headers});
} }
public getById(id: number) : Observable<GearResp> {
return this.serviceCacheApi.getByKey<Array<GearResp>>(CacheApiKey.Gear)
.pipe(map(data => {
return data.find(f => f.id === id);
}));
}
} }

View File

@@ -1,6 +1,7 @@
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http"; import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs"; import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { JumpTypeResp, JumpTypeReq } from "../models/jumpType"; import { JumpTypeResp, JumpTypeReq } from "../models/jumpType";
@@ -28,4 +29,11 @@ export class JumpTypeService extends BaseService {
bodyJumpType, bodyJumpType,
{ headers: this.headers }); { headers: this.headers });
} }
public getById(id: number) : Observable<JumpTypeResp> {
return this.serviceCacheApi.getByKey<Array<JumpTypeResp>>(CacheApiKey.JumpType)
.pipe(map(data => {
return data.find(f => f.id === id);
}));
}
} }

View File

@@ -8,12 +8,20 @@ import { JumpResp, JumpReq } from "../models/jump";
import { DateService } from "./date.service"; import { DateService } from "./date.service";
import { BaseService } from "./base.service"; import { BaseService } from "./base.service";
import { DropzoneService } from "./dropzone.service";
import { AircraftService } from "./aircraft.service";
import { JumpTypeService } from "./jump-type.service";
import { GearService } from "./gear.service";
@Injectable() @Injectable()
export class JumpService extends BaseService { export class JumpService extends BaseService {
constructor(private http: HttpClient, constructor(private http: HttpClient,
private dateService: DateService, private dateService: DateService,
private datePipe: DatePipe) { private datePipe: DatePipe,
private dropzoneService: DropzoneService,
private aircraftService: AircraftService,
private jumpTypeService: JumpTypeService,
private gearService: GearService,) {
super(); super();
} }
@@ -22,7 +30,15 @@ export class JumpService extends BaseService {
{ headers: this.headers }) { headers: this.headers })
.pipe( .pipe(
map((response) => { map((response) => {
const details = response.map((data) => new JumpResp(data)); let details = response.map((data) =>
{
let t = new JumpResp(data);
this.dropzoneService.getById(t.dropZoneId).subscribe((d)=> t.dropZone = d );
this.aircraftService.getById(t.aircraftId).subscribe((d)=> t.aircraft = d );
this.jumpTypeService.getById(t.jumpTypeId).subscribe((d)=> t.jumpType = d );
this.gearService.getById(t.gearId).subscribe((d)=> t.gear = d );
return t;
});
return details; return details;
}) })
); );

View File

@@ -14,11 +14,7 @@ export class ServiceCacheApi {
this.cache = new Map<CacheApiKey, Observable<any>>(); this.cache = new Map<CacheApiKey, Observable<any>>();
} }
public get<T>(key: CacheApiKey, callToApi: Observable<T>, withResetCache: boolean = false) : Observable<T> { public get<T>(key: CacheApiKey, callToApi: Observable<T>) : Observable<T> {
if (withResetCache === true) {
this.cache.delete(key);
}
const cached = this.cache.get(key); const cached = this.cache.get(key);
if (cached) { if (cached) {
@@ -34,4 +30,8 @@ export class ServiceCacheApi {
public delete(key: CacheApiKey) { public delete(key: CacheApiKey) {
this.cache.delete(key); this.cache.delete(key);
} }
public getByKey<T>(key: CacheApiKey) : Observable<T> {
return this.cache.get(key);
}
} }