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() {
this.serviceApi.getListOfDropZones().subscribe((data) => {
this.serviceApi.getListOfDropZones()
.subscribe((data) => {
setTimeout(() => {
data.sort((a, b) => (b.isFavorite ? 1 : 0) - (a.isFavorite ? 1 : 0) || a.name.localeCompare(b.name));
this.dataSourceTable = new MatTableDataSource<DropZoneResp>(data);

View File

@@ -15,6 +15,7 @@
</div>
<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;"
(click)='refreshStats()'>cached</mat-icon>
</div>

View File

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

View File

@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from "rxjs/operators";
import { AircraftResp, AircraftReq } from '../models/aircraft';
@@ -36,4 +37,11 @@ export class AircraftService extends BaseService {
bodyNewAircraft,
{ 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,
{ 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 { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { GearResp, GearReq } from "../models/gear";
@@ -40,4 +41,11 @@ export class GearService extends BaseService {
this.serviceCacheApi.delete(CacheApiKey.Gear);
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 { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { JumpTypeResp, JumpTypeReq } from "../models/jumpType";
@@ -28,4 +29,11 @@ export class JumpTypeService extends BaseService {
bodyJumpType,
{ 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 { 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()
export class JumpService extends BaseService {
constructor(private http: HttpClient,
private dateService: DateService,
private datePipe: DatePipe) {
private datePipe: DatePipe,
private dropzoneService: DropzoneService,
private aircraftService: AircraftService,
private jumpTypeService: JumpTypeService,
private gearService: GearService,) {
super();
}
@@ -22,7 +30,15 @@ export class JumpService extends BaseService {
{ headers: this.headers })
.pipe(
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;
})
);

View File

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