Ajout du cache sur les appels pour les stats
Et appel à l'API sur l'affichage de l'onglet
This commit is contained in:
@@ -2,12 +2,12 @@ import { Component, OnInit } from "@angular/core";
|
||||
import { Router } from "@angular/router";
|
||||
|
||||
import { User } from "../models/user";
|
||||
import { RefData } from "../models/ref-data.enum";
|
||||
import { CacheApiKey } from "../models/cache-api-key.enum";
|
||||
|
||||
import { AuthenticationService } from "../services/authentication.service";
|
||||
import { ServiceComm } from "../services/service-comm.service";
|
||||
import { ConfigurationHelper } from "../services/configuration-helper";
|
||||
import { ServiceRefData } from "../services/service-ref-data.service";
|
||||
import { ServiceCacheApi } from "../services/service-cache-api.service";
|
||||
import { AircraftService } from "../services/aircraft.service";
|
||||
import { GearService } from "../services/gear.service";
|
||||
import { JumpTypeService } from "../services/jump-type.service";
|
||||
@@ -26,7 +26,7 @@ export class AppComponent implements OnInit {
|
||||
constructor(private router: Router,
|
||||
private authenticationService: AuthenticationService,
|
||||
private serviceComm: ServiceComm,
|
||||
private serviceRefData : ServiceRefData,
|
||||
private serviceCacheApi : ServiceCacheApi,
|
||||
private serviceApiAircraft : AircraftService,
|
||||
private serviceApiJumpType : JumpTypeService,
|
||||
private serviceApiDropzone : DropzoneService,
|
||||
@@ -58,7 +58,7 @@ export class AppComponent implements OnInit {
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.serviceRefData.delete(RefData.Dropzone);
|
||||
this.serviceCacheApi.delete(CacheApiKey.Dropzone);
|
||||
this.authenticationService.logout();
|
||||
this.router.navigate(["/login"], { skipLocationChange: true });
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import { RequestCache } from "../services/request-cache.service";
|
||||
import { AuthGuardService } from "../services/auth-guard.service";
|
||||
import { ImageService } from "../services/image.service";
|
||||
import { ConfigurationHelper } from "../services/configuration-helper";
|
||||
import { ServiceRefData } from "../services/service-ref-data.service";
|
||||
import { ServiceCacheApi } from "../services/service-cache-api.service";
|
||||
|
||||
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
|
||||
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
|
||||
@@ -183,7 +183,7 @@ export function initConfig(configService: ConfigurationHelper) {
|
||||
RequestCache,
|
||||
ConfigurationHelper,
|
||||
DatePipe,
|
||||
ServiceRefData,
|
||||
ServiceCacheApi,
|
||||
{ provide: APP_INITIALIZER, useFactory: initConfig, deps: [ConfigurationHelper], multi: true },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: JwtAuthInterceptor, multi: true },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true }
|
||||
|
||||
@@ -33,10 +33,6 @@
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.mat-tab-group {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.containerFlex {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
@@ -11,126 +11,146 @@
|
||||
|
||||
<div class="paragraph">
|
||||
<label class="left130">Last jump</label>
|
||||
<span>: {{ lastJump }}</span>
|
||||
<span>: {{ lastJump | date: 'yyyy-MM-dd' }}</span>
|
||||
</div>
|
||||
|
||||
<mat-tab-group mat-align-tabs="left" animationDuration="0ms">
|
||||
<div class="paragraph" style="margin-top: 20px;">
|
||||
<mat-icon aria-hidden="false" aria-label="Force the refresh of the stats" style="cursor: pointer;"
|
||||
(click)='refreshStats()'>cached</mat-icon>
|
||||
</div>
|
||||
|
||||
<mat-tab-group mat-align-tabs="left" animationDuration="0ms"
|
||||
(selectedTabChange)="onTabChanged($event);">
|
||||
<mat-tab label="Jumps in the last month">
|
||||
<div class="containerFlex">
|
||||
<fieldset class="contentFlex">
|
||||
<legend>By DZ</legend>
|
||||
<table mat-table [dataSource]="dsJumpForLastMonthByDz">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
<fieldset class="contentFlex">
|
||||
<legend>By jump type</legend>
|
||||
<table mat-table [dataSource]="dsJumpForLastMonthByJumpType">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
<ng-template matTabContent>
|
||||
<div class="containerFlex">
|
||||
<fieldset class="contentFlex">
|
||||
<legend>By DZ</legend>
|
||||
<table mat-table [dataSource]="dsJumpForLastMonthByDz">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
<fieldset class="contentFlex">
|
||||
<legend>By jump type</legend>
|
||||
<table mat-table [dataSource]="dsJumpForLastMonthByJumpType">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
|
||||
<mat-tab label="Jumps in the last year">
|
||||
<div class="containerFlex">
|
||||
<fieldset class="contentFlex">
|
||||
<legend>By DZ</legend>
|
||||
<table mat-table [dataSource]="dsJumpForLastYearByDz">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
<fieldset class="contentFlex">
|
||||
<legend>By jump type</legend>
|
||||
<table mat-table [dataSource]="dsJumpForLastYearByJumpType">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
<ng-template matTabContent>
|
||||
<div class="containerFlex">
|
||||
<fieldset class="contentFlex">
|
||||
<legend>By DZ</legend>
|
||||
<table mat-table [dataSource]="dsJumpForLastYearByDz">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
<fieldset class="contentFlex">
|
||||
<legend>By jump type</legend>
|
||||
<table mat-table [dataSource]="dsJumpForLastYearByJumpType">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
|
||||
<mat-tab label="By DZ">
|
||||
<table mat-table [dataSource]="dsNbJumpByDz">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
<ng-template matTabContent>
|
||||
<table mat-table [dataSource]="dsNbJumpByDz">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
|
||||
<mat-tab label="By aircraft">
|
||||
<table mat-table [dataSource]="dsNbJumpByAircraft">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
<ng-template matTabContent>
|
||||
<table mat-table [dataSource]="dsNbJumpByAircraft">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
|
||||
<mat-tab label="By gear">
|
||||
<table mat-table [dataSource]="dsNbJumpByGear">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
<ng-template matTabContent>
|
||||
<table mat-table [dataSource]="dsNbJumpByGear">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
|
||||
<mat-tab label="By jump type">
|
||||
<table mat-table [dataSource]="dsNbJumpByType">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
<ng-template matTabContent>
|
||||
<table mat-table [dataSource]="dsNbJumpByType">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
|
||||
<mat-tab label="By year">
|
||||
<table mat-table [dataSource]="dsNbJumpByYear">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
<ng-template matTabContent>
|
||||
<table mat-table [dataSource]="dsNbJumpByYear">
|
||||
<ng-container matColumnDef="label">
|
||||
<td mat-cell *matCellDef="let element">{{element.label}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="nb">
|
||||
<td mat-cell *matCellDef="let element">{{element.nb}}</td>
|
||||
</ng-container>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
</div>
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { MatTabChangeEvent, MatTabGroup } from '@angular/material/tabs';
|
||||
import { ServiceComm } from '../../services/service-comm.service';
|
||||
import { StatsService } from '../../services/stats.service';
|
||||
import {
|
||||
StatsByDzResp,
|
||||
StatsByAircraftResp,
|
||||
StatsByGearResp,
|
||||
StatsByJumpTypeResp,
|
||||
StatsByYearResp,
|
||||
StatType
|
||||
} from '../../models/stats';
|
||||
import { StatsByDzResp, StatsByAircraftResp, StatsByGearResp,
|
||||
StatsByJumpTypeResp, StatsByYearResp } from '../../models/stats';
|
||||
|
||||
@Component({
|
||||
selector: 'app-summary',
|
||||
@@ -29,86 +24,91 @@ export class SummaryComponent implements OnInit {
|
||||
public dsJumpForLastMonthByJumpType: MatTableDataSource<StatsByJumpTypeResp>;
|
||||
|
||||
public displayedColumns: Array<string> = ['label', 'nb'];
|
||||
private _shownStats: Map<StatType, boolean>;
|
||||
public StatType = StatType;
|
||||
|
||||
public totalJumps: number;
|
||||
public totalCutaways: number;
|
||||
public lastJump: string;
|
||||
|
||||
constructor(
|
||||
private _serviceApi: StatsService,
|
||||
private _serviceComm: ServiceComm
|
||||
) { }
|
||||
@ViewChild(MatTabGroup) tabGroup: MatTabGroup;
|
||||
|
||||
constructor(private serviceApi: StatsService,
|
||||
private serviceComm: ServiceComm) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.initShownStats();
|
||||
this.serviceComm.UpdatedComponentTitle('Summary');
|
||||
|
||||
this._serviceComm.UpdatedComponentTitle('Summary');
|
||||
this.serviceApi.getSimpleSummary()
|
||||
.subscribe(data => {
|
||||
this.totalJumps = data.totalJumps;
|
||||
this.totalCutaways = data.totalCutaways;
|
||||
this.lastJump = data.lastJump.jumpDate + ' (' + data.lastJump.dropZone.name + ')';
|
||||
});
|
||||
|
||||
const statsResult = this._serviceApi.getStatsOfJumps();
|
||||
|
||||
statsResult.simpleSummary.subscribe(data => {
|
||||
this.totalJumps = data.totalJumps;
|
||||
this.totalCutaways = data.totalCutaways;
|
||||
this.lastJump = data.lastJump.jumpDate + ' (' + data.lastJump.dropZone.name + ')';
|
||||
});
|
||||
|
||||
statsResult.statsByDz.subscribe(data => {
|
||||
this.dsNbJumpByDz = new MatTableDataSource(data);
|
||||
});
|
||||
statsResult.statsByAircraft.subscribe(data => {
|
||||
this.dsNbJumpByAircraft = new MatTableDataSource(data);
|
||||
});
|
||||
statsResult.statsByGear.subscribe(data => {
|
||||
this.dsNbJumpByGear = new MatTableDataSource(data);
|
||||
});
|
||||
statsResult.statsByJumpType.subscribe(data => {
|
||||
this.dsNbJumpByType = new MatTableDataSource(data);
|
||||
});
|
||||
statsResult.statsByYear.subscribe(data => {
|
||||
this.dsNbJumpByYear = new MatTableDataSource(data);
|
||||
});
|
||||
|
||||
statsResult.statsForLastYear.subscribe(data => {
|
||||
this.dsJumpForLastYearByDz = new MatTableDataSource(data.byDz);
|
||||
this.dsJumpForLastYearByJumpType = new MatTableDataSource(
|
||||
data.byJumpType
|
||||
);
|
||||
});
|
||||
statsResult.statsForLastMonth.subscribe(data => {
|
||||
this.dsJumpForLastMonthByDz = new MatTableDataSource(data.byDz);
|
||||
this.dsJumpForLastMonthByJumpType = new MatTableDataSource(
|
||||
data.byJumpType
|
||||
);
|
||||
});
|
||||
this.serviceApi.getStatsOfLastMonth()
|
||||
.subscribe(data => {
|
||||
this.dsJumpForLastMonthByDz = new MatTableDataSource(data.byDz);
|
||||
this.dsJumpForLastMonthByJumpType = new MatTableDataSource(
|
||||
data.byJumpType
|
||||
);
|
||||
});
|
||||
|
||||
this.tabGroup.selectedIndex = 0;
|
||||
}
|
||||
|
||||
public showStats(statsToShow: StatType) {
|
||||
this._shownStats.set(StatType.ForLastMonth, false);
|
||||
this._shownStats.set(StatType.ForLastYear, false);
|
||||
this._shownStats.set(StatType.ByDz, false);
|
||||
this._shownStats.set(StatType.ByAircraft, false);
|
||||
this._shownStats.set(StatType.ByGear, false);
|
||||
this._shownStats.set(StatType.ByJumpType, false);
|
||||
this._shownStats.set(StatType.ByYear, false);
|
||||
|
||||
this._shownStats.set(statsToShow, true);
|
||||
public refreshStats() {
|
||||
this.serviceApi.deleteAllCache();
|
||||
this.tabGroup.selectedIndex = 0;
|
||||
}
|
||||
|
||||
private initShownStats() {
|
||||
this._shownStats = new Map<StatType, boolean>();
|
||||
|
||||
this._shownStats.set(StatType.ForLastMonth, false);
|
||||
this._shownStats.set(StatType.ForLastYear, false);
|
||||
this._shownStats.set(StatType.ByDz, false);
|
||||
this._shownStats.set(StatType.ByAircraft, false);
|
||||
this._shownStats.set(StatType.ByGear, false);
|
||||
this._shownStats.set(StatType.ByJumpType, false);
|
||||
this._shownStats.set(StatType.ByYear, true);
|
||||
}
|
||||
|
||||
public statsToShow(statsToShow: StatType): boolean {
|
||||
return this._shownStats.get(statsToShow);
|
||||
public onTabChanged(event: MatTabChangeEvent) {
|
||||
switch (event.index) {
|
||||
case 0:
|
||||
this.serviceApi.getStatsOfLastMonth()
|
||||
.subscribe(data => {
|
||||
this.dsJumpForLastMonthByDz = new MatTableDataSource(data.byDz);
|
||||
this.dsJumpForLastMonthByJumpType = new MatTableDataSource(
|
||||
data.byJumpType
|
||||
);
|
||||
});
|
||||
break;
|
||||
case 1:
|
||||
this.serviceApi.getStatsOfLastYear()
|
||||
.subscribe(data => {
|
||||
this.dsJumpForLastYearByDz = new MatTableDataSource(data.byDz);
|
||||
this.dsJumpForLastYearByJumpType = new MatTableDataSource(
|
||||
data.byJumpType
|
||||
);
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
this.serviceApi.getStatsByDz()
|
||||
.subscribe(data => {
|
||||
this.dsNbJumpByDz = new MatTableDataSource(data);
|
||||
});
|
||||
break;
|
||||
case 3:
|
||||
this.serviceApi.getStatsByAircraft()
|
||||
.subscribe(data => {
|
||||
this.dsNbJumpByAircraft = new MatTableDataSource(data);
|
||||
});
|
||||
break;
|
||||
case 4:
|
||||
this.serviceApi.getStatsByGear()
|
||||
.subscribe(data => {
|
||||
this.dsNbJumpByGear = new MatTableDataSource(data);
|
||||
});
|
||||
break;
|
||||
case 5:
|
||||
this.serviceApi.getStatsByJumpType()
|
||||
.subscribe(data => {
|
||||
this.dsNbJumpByType = new MatTableDataSource(data);
|
||||
});
|
||||
break;
|
||||
case 6:
|
||||
this.serviceApi.getStatsByYear()
|
||||
.subscribe(data => {
|
||||
this.dsNbJumpByYear = new MatTableDataSource(data);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
Front/skydivelogs-app/src/models/cache-api-key.enum.ts
Normal file
13
Front/skydivelogs-app/src/models/cache-api-key.enum.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export enum CacheApiKey {
|
||||
JumpType,
|
||||
Aircraft,
|
||||
Gear,
|
||||
Dropzone,
|
||||
SimpleSummary,
|
||||
StatsByDz,
|
||||
StatsByAircraft,
|
||||
StatsByJumpType,
|
||||
StatsByGear,
|
||||
StatsOfLastYear,
|
||||
StatsOfLastMonth
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
export enum RefData {
|
||||
JumpType,
|
||||
Aircraft,
|
||||
Gear,
|
||||
Dropzone
|
||||
}
|
||||
@@ -1,16 +1,6 @@
|
||||
import { Observable } from 'rxjs';
|
||||
import { JumpResp } from './jump';
|
||||
|
||||
export enum StatType {
|
||||
ForLastMonth = 1,
|
||||
ForLastYear = 2,
|
||||
ByDz = 3,
|
||||
ByAircraft = 4,
|
||||
ByGear = 5,
|
||||
ByJumpType = 6,
|
||||
ByYear = 7,
|
||||
}
|
||||
|
||||
export class StatsResp {
|
||||
public simpleSummary: Observable<SimpleSummary>;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Observable } from 'rxjs';
|
||||
import { AircraftResp, AircraftReq } from '../models/aircraft';
|
||||
|
||||
import { BaseService } from './base.service';
|
||||
import { RefData } from '../models/ref-data.enum';
|
||||
import { CacheApiKey } from '../models/cache-api-key.enum';
|
||||
|
||||
@Injectable()
|
||||
export class AircraftService extends BaseService {
|
||||
@@ -22,7 +22,7 @@ export class AircraftService extends BaseService {
|
||||
}
|
||||
|
||||
let callToApi = this.http.get<Array<AircraftResp>>(url, { headers: this.headers });
|
||||
return this.serviceRefData.get<Array<AircraftResp>>(RefData.Aircraft, callToApi);
|
||||
return this.serviceCacheApi.get<Array<AircraftResp>>(CacheApiKey.Aircraft, callToApi);
|
||||
}
|
||||
|
||||
public AddAircraft(aircraftName: string, dataImg: string) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { HttpHeaders } from '@angular/common/http';
|
||||
|
||||
import { ConfigurationHelper } from './configuration-helper';
|
||||
import { ServiceRefData } from './service-ref-data.service';
|
||||
import { ServiceCacheApi } from './service-cache-api.service';
|
||||
|
||||
export class BaseService {
|
||||
protected headers: HttpHeaders;
|
||||
protected apiUrl: string;
|
||||
protected serviceRefData : ServiceRefData;
|
||||
protected serviceCacheApi : ServiceCacheApi;
|
||||
|
||||
constructor() {
|
||||
ConfigurationHelper.settings.subscribe(settings =>
|
||||
@@ -21,6 +21,6 @@ export class BaseService {
|
||||
}
|
||||
});
|
||||
|
||||
this.serviceRefData = new ServiceRefData();
|
||||
this.serviceCacheApi = new ServiceCacheApi();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { map } from "rxjs/operators";
|
||||
import { DropZoneResp, DropZoneReq } from "../models/dropzone";
|
||||
|
||||
import { BaseService } from "./base.service";
|
||||
import { RefData } from "../models/ref-data.enum";
|
||||
import { CacheApiKey } from "../models/cache-api-key.enum";
|
||||
|
||||
@Injectable()
|
||||
export class DropzoneService extends BaseService {
|
||||
@@ -27,7 +27,7 @@ export class DropzoneService extends BaseService {
|
||||
const details = response.map(data => new DropZoneResp(data));
|
||||
return details;
|
||||
}));
|
||||
return this.serviceRefData.get<Array<DropZoneResp>>(RefData.Dropzone, callToApi);
|
||||
return this.serviceCacheApi.get<Array<DropZoneResp>>(CacheApiKey.Dropzone, callToApi);
|
||||
}
|
||||
|
||||
public SetFavoriteDropZone(selectedDz: DropZoneResp) {
|
||||
@@ -37,7 +37,7 @@ export class DropzoneService extends BaseService {
|
||||
selectedDz,
|
||||
{ headers: this.headers })
|
||||
.subscribe(() => {
|
||||
this.serviceRefData.delete(RefData.Dropzone);
|
||||
this.serviceCacheApi.delete(CacheApiKey.Dropzone);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export class DropzoneService extends BaseService {
|
||||
selectedDz,
|
||||
{ headers: this.headers })
|
||||
.subscribe(() => {
|
||||
this.serviceRefData.delete(RefData.Dropzone);
|
||||
this.serviceCacheApi.delete(CacheApiKey.Dropzone);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ export class DropzoneService extends BaseService {
|
||||
isFavorite: isFavorite
|
||||
};
|
||||
|
||||
this.serviceRefData.delete(RefData.Dropzone);
|
||||
this.serviceCacheApi.delete(CacheApiKey.Dropzone);
|
||||
return this.http.post(`${this.apiUrl}/DropZone`,
|
||||
bodyNewDropZone,
|
||||
{ headers: this.headers });
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Observable } from "rxjs";
|
||||
import { GearResp, GearReq } from "../models/gear";
|
||||
|
||||
import { BaseService } from "./base.service";
|
||||
import { RefData } from "../models/ref-data.enum";
|
||||
import { CacheApiKey } from "../models/cache-api-key.enum";
|
||||
|
||||
@Injectable()
|
||||
export class GearService extends BaseService {
|
||||
@@ -15,7 +15,7 @@ export class GearService extends BaseService {
|
||||
|
||||
public getListOfGears(): Observable<Array<GearResp>> {
|
||||
let callToApi = this.http.get<Array<GearResp>>(`${this.apiUrl}/Gear`, { headers: this.headers });
|
||||
return this.serviceRefData.get<Array<GearResp>>(RefData.Gear, callToApi);
|
||||
return this.serviceCacheApi.get<Array<GearResp>>(CacheApiKey.Gear, callToApi);
|
||||
}
|
||||
|
||||
public AddGear(name: string,
|
||||
@@ -37,7 +37,7 @@ export class GearService extends BaseService {
|
||||
reserveCanopy: reserveCanopy
|
||||
};
|
||||
|
||||
this.serviceRefData.delete(RefData.Gear);
|
||||
this.serviceCacheApi.delete(CacheApiKey.Gear);
|
||||
return this.http.post(`${this.apiUrl}/Gear`, bodyNewGear, { headers: this.headers});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Observable } from "rxjs";
|
||||
import { JumpTypeResp, JumpTypeReq } from "../models/jumpType";
|
||||
|
||||
import { BaseService } from "./base.service";
|
||||
import { RefData } from "../models/ref-data.enum";
|
||||
import { CacheApiKey } from "../models/cache-api-key.enum";
|
||||
|
||||
@Injectable()
|
||||
export class JumpTypeService extends BaseService {
|
||||
@@ -15,7 +15,7 @@ export class JumpTypeService extends BaseService {
|
||||
|
||||
public getListOfJumpTypes(): Observable<Array<JumpTypeResp>> {
|
||||
let callToApi = this.http.get<Array<JumpTypeResp>>(`${this.apiUrl}/JumpType`, { headers: this.headers });
|
||||
return this.serviceRefData.get<Array<JumpTypeResp>>(RefData.JumpType, callToApi);
|
||||
return this.serviceCacheApi.get<Array<JumpTypeResp>>(CacheApiKey.JumpType, callToApi);
|
||||
}
|
||||
|
||||
public AddJumpType(jumptypetName: string) {
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { RefData } from '../models/ref-data.enum';
|
||||
import { CacheApiKey } from '../models/cache-api-key.enum';
|
||||
import { of } from 'rxjs';
|
||||
//import 'rxjs/add/observable/of';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ServiceRefData {
|
||||
private cache: Map<RefData, Observable<any>>;
|
||||
export class ServiceCacheApi {
|
||||
private cache: Map<CacheApiKey, Observable<any>>;
|
||||
|
||||
constructor() {
|
||||
this.cache = new Map<RefData, Observable<any>>();
|
||||
this.cache = new Map<CacheApiKey, Observable<any>>();
|
||||
}
|
||||
|
||||
public get<T>(key: RefData, callToApi: Observable<T>, withResetCache: boolean = false) : Observable<T> {
|
||||
public get<T>(key: CacheApiKey, callToApi: Observable<T>, withResetCache: boolean = false) : Observable<T> {
|
||||
if (withResetCache === true) {
|
||||
this.cache.delete(key);
|
||||
}
|
||||
@@ -32,7 +31,7 @@ export class ServiceRefData {
|
||||
}
|
||||
}
|
||||
|
||||
public delete(key: RefData) {
|
||||
public delete(key: CacheApiKey) {
|
||||
this.cache.delete(key);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,14 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import {
|
||||
StatsResp,
|
||||
StatsByDzResp,
|
||||
StatsByAircraftResp,
|
||||
StatsByJumpTypeResp,
|
||||
StatsByGearResp,
|
||||
StatsByYearResp,
|
||||
StatsForLastMonthResp,
|
||||
StatsForLastYearResp,
|
||||
SimpleSummary
|
||||
} from '../models/stats';
|
||||
import { StatsByDzResp, StatsByAircraftResp, StatsByJumpTypeResp,
|
||||
StatsByGearResp, StatsByYearResp, StatsForLastMonthResp,
|
||||
StatsForLastYearResp, SimpleSummary } from '../models/stats';
|
||||
|
||||
import { BaseService } from './base.service';
|
||||
import { CacheApiKey } from '../models/cache-api-key.enum';
|
||||
|
||||
|
||||
@Injectable()
|
||||
@@ -24,136 +17,117 @@ export class StatsService extends BaseService {
|
||||
super();
|
||||
}
|
||||
|
||||
public getStatsOfJumps(): StatsResp {
|
||||
const resultats = new StatsResp();
|
||||
|
||||
resultats.simpleSummary = this.getSimpleSummary();
|
||||
|
||||
resultats.statsByDz = this.getStatsByDz();
|
||||
resultats.statsByAircraft = this.getStatsByAircraft();
|
||||
resultats.statsByJumpType = this.getStatsByJumpType();
|
||||
resultats.statsByGear = this.getStatsByGear();
|
||||
resultats.statsByYear = this.getStatsByYear();
|
||||
|
||||
resultats.statsForLastYear = this.getStatsOfLastYear();
|
||||
resultats.statsForLastMonth = this.getStatsOfLastMonth();
|
||||
|
||||
return resultats;
|
||||
public deleteAllCache() {
|
||||
this.serviceCacheApi.delete(CacheApiKey.SimpleSummary);
|
||||
this.serviceCacheApi.delete(CacheApiKey.StatsByDz);
|
||||
this.serviceCacheApi.delete(CacheApiKey.StatsByAircraft);
|
||||
this.serviceCacheApi.delete(CacheApiKey.StatsByJumpType);
|
||||
this.serviceCacheApi.delete(CacheApiKey.StatsByGear);
|
||||
this.serviceCacheApi.delete(CacheApiKey.StatsOfLastYear);
|
||||
this.serviceCacheApi.delete(CacheApiKey.StatsOfLastMonth);
|
||||
}
|
||||
|
||||
private getSimpleSummary(): Observable<SimpleSummary> {
|
||||
return this.http
|
||||
.get<Array<SimpleSummary>>(`${this.apiUrl}/Stats/Simple`, {
|
||||
headers: this.headers
|
||||
})
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = new SimpleSummary(response);
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
public getSimpleSummary(): Observable<SimpleSummary> {
|
||||
let callToApi = this.http.get<Array<SimpleSummary>>(`${this.apiUrl}/Stats/Simple`, { headers: this.headers })
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = new SimpleSummary(response);
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
|
||||
return this.serviceCacheApi.get<SimpleSummary>(CacheApiKey.SimpleSummary, callToApi);
|
||||
}
|
||||
|
||||
private getStatsByDz(): Observable<Array<StatsByDzResp>> {
|
||||
return this.http
|
||||
.get<Array<StatsByDzResp>>(`${this.apiUrl}/Stats/ByDz`, {
|
||||
headers: this.headers
|
||||
})
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = response.map(data => new StatsByDzResp(data));
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
public getStatsByDz(): Observable<Array<StatsByDzResp>> {
|
||||
let callToApi = this.http.get<Array<StatsByDzResp>>(`${this.apiUrl}/Stats/ByDz`, { headers: this.headers })
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = response.map(data => new StatsByDzResp(data));
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
|
||||
return this.serviceCacheApi.get<Array<StatsByDzResp>>(CacheApiKey.StatsByDz, callToApi);
|
||||
}
|
||||
|
||||
private getStatsByAircraft(): Observable<Array<StatsByAircraftResp>> {
|
||||
return this.http
|
||||
.get<Array<StatsByAircraftResp>>(
|
||||
`${this.apiUrl}/Stats/ByAircraft`,
|
||||
{ headers: this.headers }
|
||||
)
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = response.map(data => new StatsByAircraftResp(data));
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
public getStatsByAircraft(): Observable<Array<StatsByAircraftResp>> {
|
||||
let callToApi = this.http.get<Array<StatsByAircraftResp>>(`${this.apiUrl}/Stats/ByAircraft`, { headers: this.headers })
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = response.map(data => new StatsByAircraftResp(data));
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
|
||||
return this.serviceCacheApi.get<Array<StatsByAircraftResp>>(CacheApiKey.StatsByAircraft, callToApi);
|
||||
}
|
||||
|
||||
private getStatsByJumpType(): Observable<Array<StatsByJumpTypeResp>> {
|
||||
return this.http
|
||||
.get<Array<StatsByJumpTypeResp>>(
|
||||
`${this.apiUrl}/Stats/ByJumpType`,
|
||||
{ headers: this.headers }
|
||||
)
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = response.map(data => new StatsByJumpTypeResp(data));
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
public getStatsByJumpType(): Observable<Array<StatsByJumpTypeResp>> {
|
||||
let callToApi = this.http.get<Array<StatsByJumpTypeResp>>(`${this.apiUrl}/Stats/ByJumpType`,{ headers: this.headers })
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = response.map(data => new StatsByJumpTypeResp(data));
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
|
||||
return this.serviceCacheApi.get<Array<StatsByJumpTypeResp>>(CacheApiKey.StatsByJumpType, callToApi);
|
||||
}
|
||||
|
||||
private getStatsByGear(): Observable<Array<StatsByGearResp>> {
|
||||
return this.http
|
||||
.get<Array<StatsByGearResp>>(`${this.apiUrl}/Stats/ByGear`, {
|
||||
headers: this.headers
|
||||
})
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = response.map(data => new StatsByGearResp(data));
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
public getStatsByGear(): Observable<Array<StatsByGearResp>> {
|
||||
let callToApi = this.http.get<Array<StatsByGearResp>>(`${this.apiUrl}/Stats/ByGear`, { headers: this.headers })
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = response.map(data => new StatsByGearResp(data));
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
|
||||
return this.serviceCacheApi.get<Array<StatsByGearResp>>(CacheApiKey.StatsByGear, callToApi);
|
||||
}
|
||||
|
||||
private getStatsByYear(): Observable<Array<StatsByYearResp>> {
|
||||
return this.http
|
||||
.get<Array<StatsByYearResp>>(`${this.apiUrl}/Stats/ByYear`, {
|
||||
headers: this.headers
|
||||
})
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = response.map(data => new StatsByYearResp(data));
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
public getStatsByYear(): Observable<Array<StatsByYearResp>> {
|
||||
let callToApi = this.http.get<Array<StatsByYearResp>>(`${this.apiUrl}/Stats/ByYear`, { headers: this.headers })
|
||||
.pipe(
|
||||
map(response => {
|
||||
const stats = response.map(data => new StatsByYearResp(data));
|
||||
return stats;
|
||||
})
|
||||
);
|
||||
|
||||
return this.serviceCacheApi.get<Array<StatsByYearResp>>(CacheApiKey.StatsByGear, callToApi);
|
||||
}
|
||||
|
||||
private getStatsOfLastYear(): Observable<StatsForLastYearResp> {
|
||||
return this.http
|
||||
.get<StatsForLastYearResp>(
|
||||
`${this.apiUrl}/Stats/ForLastYear`,
|
||||
{ headers: this.headers }
|
||||
)
|
||||
.pipe(
|
||||
map(response => {
|
||||
const statsByDz = response.byDz.map(data => new StatsByDzResp(data));
|
||||
const statsByJumpType = response.byJumpType.map(
|
||||
data => new StatsByDzResp(data)
|
||||
);
|
||||
public getStatsOfLastYear(): Observable<StatsForLastYearResp> {
|
||||
let callToApi = this.http.get<StatsForLastYearResp>(`${this.apiUrl}/Stats/ForLastYear`, { headers: this.headers })
|
||||
.pipe(
|
||||
map(response => {
|
||||
const statsByDz = response.byDz.map(data => new StatsByDzResp(data));
|
||||
const statsByJumpType = response.byJumpType.map(
|
||||
data => new StatsByDzResp(data)
|
||||
);
|
||||
|
||||
return new StatsForLastYearResp(statsByDz, statsByJumpType);
|
||||
})
|
||||
);
|
||||
return new StatsForLastYearResp(statsByDz, statsByJumpType);
|
||||
})
|
||||
);
|
||||
|
||||
return this.serviceCacheApi.get<StatsForLastYearResp>(CacheApiKey.StatsOfLastYear, callToApi);
|
||||
}
|
||||
|
||||
private getStatsOfLastMonth(): Observable<StatsForLastMonthResp> {
|
||||
return this.http
|
||||
.get<StatsForLastYearResp>(
|
||||
`${this.apiUrl}/Stats/ForLastMonth`,
|
||||
{ headers: this.headers }
|
||||
)
|
||||
.pipe(
|
||||
map(response => {
|
||||
const statsByDz = response.byDz.map(data => new StatsByDzResp(data));
|
||||
const statsByJumpType = response.byJumpType.map(
|
||||
data => new StatsByDzResp(data)
|
||||
);
|
||||
public getStatsOfLastMonth(): Observable<StatsForLastMonthResp> {
|
||||
let callToApi = this.http.get<StatsForLastYearResp>(`${this.apiUrl}/Stats/ForLastMonth`, { headers: this.headers })
|
||||
.pipe(
|
||||
map(response => {
|
||||
const statsByDz = response.byDz.map(data => new StatsByDzResp(data));
|
||||
const statsByJumpType = response.byJumpType.map(
|
||||
data => new StatsByDzResp(data)
|
||||
);
|
||||
|
||||
return new StatsForLastMonthResp(statsByDz, statsByJumpType);
|
||||
})
|
||||
);
|
||||
return new StatsForLastMonthResp(statsByDz, statsByJumpType);
|
||||
})
|
||||
);
|
||||
|
||||
return this.serviceCacheApi.get<StatsForLastMonthResp>(CacheApiKey.StatsOfLastMonth, callToApi);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user