Correction sur la mise en cache des

données référentiel et leurs utilisation
sur la liste des sauts.
This commit is contained in:
Sébastien André
2021-05-28 17:19:12 +02:00
parent dba69b938e
commit ba99a0f047
14 changed files with 143 additions and 79 deletions

View File

@@ -1,6 +1,18 @@
<mat-toolbar *ngIf="this.show()">
<button mat-icon-button (click)="snav.toggle()"><mat-icon>menu</mat-icon></button>
<h2>{{ title }}</h2>
<mat-select (selectionChange)="switchLang($event)" [(value)]="selectedLanguageFlag"
style="width: 40px;" >
<mat-select-trigger>
<img src="{{ 'assets/img/' + selectedLanguageFlag + '.svg' }}" style="width: 15px;">
</mat-select-trigger>
<mat-option value="fr" style="width: 50px;">
<img src="assets/img/fr.svg" style="width: 15px;">
</mat-option>
<mat-option value="en" style="width: 50px;">
<img src="assets/img/en.svg" style="width: 15px;">
</mat-option>
</mat-select>
</mat-toolbar>
<mat-sidenav-container>
@@ -44,7 +56,7 @@
</mat-nav-list>
<mat-nav-list *ngIf="currentUser">
<mat-icon aria-hidden="false" aria-label="To logout">logout</mat-icon>
<span (click)="snav.toggle(); logout()" style="cursor: pointer;">sdfsdfsf {{ 'App_Nav_Logout' | translate }}</span>
<span (click)="snav.toggle(); logout()" style="cursor: pointer;">{{ 'App_Nav_Logout' | translate }}</span>
</mat-nav-list>
</mat-sidenav>

View File

@@ -1,6 +1,7 @@
import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import { forkJoin, Observable } from 'rxjs';
import { User } from "../models/user";
import { CacheApiKey } from "../models/cache-api-key.enum";
@@ -9,6 +10,10 @@ import { AuthenticationService } from "../services/authentication.service";
import { ServiceComm } from "../services/service-comm.service";
import { ConfigurationHelper } from "../services/configuration-helper";
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";
import { DropzoneService } from "../services/dropzone.service";
@Component({
selector: "app-root",
@@ -19,37 +24,66 @@ export class AppComponent implements OnInit {
public title = "app";
public currentUser: User;
public version: string;
public selectedLanguageFlag: string;
constructor(private router: Router,
private authenticationService: AuthenticationService,
private serviceComm: ServiceComm,
private serviceCacheApi : ServiceCacheApi,
private translateService: TranslateService)
private translateService: TranslateService,
private serviceApiAircraft : AircraftService,
private serviceApiJumpType : JumpTypeService,
private serviceApiDropzone : DropzoneService,
private serviceApiGear : GearService)
{
this.authenticationService.currentUser.subscribe(user => {
this.currentUser = user;
this.translateService.use(user.language);
this.authenticationService.alwaysLogin();
this.authenticationService.currentUser.subscribe(user => {
if (user) {
this.currentUser = user;
this.translateService.addLangs(['en', 'fr']);
this.translateService.use(user.language);
this.selectedLanguageFlag = user.language;
this.putToCacheRefDatas().subscribe(() => { console.log("Push to cache the referentiel datas"); });
}
});
ConfigurationHelper.settings.subscribe(settings =>
{
if (settings != null) {
this.version = settings.version;
}
});
{
if (settings != null) {
this.version = settings.version;
}
});
}
ngOnInit() {
this.serviceComm.componentTitle.subscribe(title => (this.title = title));
}
show() {
public show() {
return this.authenticationService.currentUserValue != undefined;
}
logout() {
public logout() {
this.serviceCacheApi.delete(CacheApiKey.Dropzone);
this.authenticationService.logout();
this.router.navigate(["/login"], { skipLocationChange: true });
}
public switchLang(event: any) {
this.translateService.use(event.value);
this.currentUser.language = event.value;
this.authenticationService.currentUserValue = this.currentUser;
this.selectedLanguageFlag = event.value;
}
private putToCacheRefDatas(): Observable<any[]> {
var aircraftResp = this.serviceApiAircraft.getListOfAircrafts(false);
var jumpTypeResp = this.serviceApiJumpType.getListOfJumpTypes();
var dzResp = this.serviceApiDropzone.getListOfDropZones(false);
var gearResp = this.serviceApiGear.getListOfGears();
return forkJoin([aircraftResp, jumpTypeResp, dzResp, gearResp]);
}
}

View File

@@ -1,6 +1,5 @@
import { Component, OnInit } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";
import { AuthenticationService } from "../../services/authentication.service";
import { ServiceComm } from "../../services/service-comm.service";
@Component({
@@ -10,13 +9,11 @@ import { ServiceComm } from "../../services/service-comm.service";
})
export class DefaultComponent implements OnInit {
constructor(private serviceComm: ServiceComm,
private authenticationService: AuthenticationService,
private translateService: TranslateService) {}
ngOnInit() {
this.translateService.get("Home").subscribe(
data => { this.serviceComm.UpdatedComponentTitle(data); }
)
this.authenticationService.alwaysLogin();
);
}
}
}

View File

@@ -16,7 +16,6 @@ import { JumpInfosComponent } from "../jump-infos/jump-infos.component";
styleUrls: ['./list-of-jumps.component.css']
})
export class ListOfJumpsComponent implements OnInit {
public listOfJumps: Observable<Array<Jump>>;
public displayedColumns: Array<string> = [
'infos',
'id',
@@ -46,8 +45,7 @@ export class ListOfJumpsComponent implements OnInit {
}
getListOfJumps() {
this.listOfJumps = this.serviceApi.GetListOfJumps();
this.listOfJumps.subscribe(data => {
this.serviceApi.GetListOfJumps().subscribe(data => {
setTimeout(() => {
data.sort((a, b) => {
if (a.jumpDate.getTime() === b.jumpDate.getTime()) {

View File

@@ -2,15 +2,10 @@ import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatInput } from '@angular/material/input';
import { TranslateService } from '@ngx-translate/core';
import { first } from 'rxjs/operators';
import { AuthenticationService } from '../../services/authentication.service';
import { AircraftService } from "../../services/aircraft.service";
import { GearService } from "../../services/gear.service";
import { JumpTypeService } from "../../services/jump-type.service";
import { DropzoneService } from "../../services/dropzone.service";
@Component({
selector: 'app-login-user',
@@ -28,12 +23,7 @@ export class LoginUserComponent implements OnInit, AfterViewInit {
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private authenticationService: AuthenticationService,
private serviceApiAircraft : AircraftService,
private serviceApiJumpType : JumpTypeService,
private serviceApiDropzone : DropzoneService,
private serviceApiGear : GearService,
private translateService: TranslateService) {
private authenticationService: AuthenticationService) {
if (this.authenticationService.currentUserValue) {
this.router.navigate(['/']);
}
@@ -64,7 +54,6 @@ export class LoginUserComponent implements OnInit, AfterViewInit {
onLoginSubmit() {
this.submitted = true;
// stop here if form is invalid
if (this.loginForm.invalid) {
return;
}
@@ -74,11 +63,6 @@ export class LoginUserComponent implements OnInit, AfterViewInit {
.pipe(first())
.subscribe(
data => {
this.serviceApiAircraft.getListOfAircrafts(false).subscribe();
this.serviceApiJumpType.getListOfJumpTypes().subscribe();
this.serviceApiDropzone.getListOfDropZones(false).subscribe();
this.serviceApiGear.getListOfGears().subscribe();
this.router.navigate([this.returnUrl]);
},
error => {

View File

@@ -8,7 +8,6 @@ import { TranslateService } from "@ngx-translate/core";
})
export class LoginComponent implements OnInit {
public selectedLanguageFlag: string;
private flag: Map<string, string>;
constructor(private translate: TranslateService) {
translate.addLangs(['en', 'fr']);

View File

@@ -45,10 +45,10 @@ export class SummaryComponent implements OnInit {
this.serviceApi.getStatsOfLastMonth()
.subscribe(data => {
data.byDz.sort((a, b) => b.nb - a.nb );
this.dsJumpForLastMonthByDz = new MatTableDataSource(data.byDz);
this.dsJumpForLastMonthByJumpType = new MatTableDataSource(
data.byJumpType
);
data.byJumpType.sort((a, b) => b.nb - a.nb );
this.dsJumpForLastMonthByJumpType = new MatTableDataSource(data.byJumpType);
});
}
@@ -94,7 +94,7 @@ export class SummaryComponent implements OnInit {
case 4:
this.serviceApi.getStatsByGear()
.subscribe(data => {
data.sort((a, b) => b.nb - a.nb );
data.sort((a, b) => b.label.localeCompare(a.label) );
this.dsNbJumpByGear = new MatTableDataSource(data);
});
break;