diff --git a/Front/skydivelogs-app/src/app/app.component.html b/Front/skydivelogs-app/src/app/app.component.html
index ca06df6..c0d5cbd 100644
--- a/Front/skydivelogs-app/src/app/app.component.html
+++ b/Front/skydivelogs-app/src/app/app.component.html
@@ -1,6 +1,18 @@
{{ title }}
+
+
+
+
+
+
+
+
+
+
+
@@ -44,7 +56,7 @@
logout
- sdfsdfsf {{ 'App_Nav_Logout' | translate }}
+ {{ 'App_Nav_Logout' | translate }}
diff --git a/Front/skydivelogs-app/src/app/app.component.ts b/Front/skydivelogs-app/src/app/app.component.ts
index 7cf0f5b..932c497 100644
--- a/Front/skydivelogs-app/src/app/app.component.ts
+++ b/Front/skydivelogs-app/src/app/app.component.ts
@@ -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 {
+ 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]);
+ }
}
diff --git a/Front/skydivelogs-app/src/app/default/default.component.ts b/Front/skydivelogs-app/src/app/default/default.component.ts
index da327ca..5c7a09c 100644
--- a/Front/skydivelogs-app/src/app/default/default.component.ts
+++ b/Front/skydivelogs-app/src/app/default/default.component.ts
@@ -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();
+ );
}
-}
+}
\ No newline at end of file
diff --git a/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts b/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts
index 40e9765..601481a 100644
--- a/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts
+++ b/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts
@@ -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>;
public displayedColumns: Array = [
'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()) {
diff --git a/Front/skydivelogs-app/src/app/login-user/login-user.component.ts b/Front/skydivelogs-app/src/app/login-user/login-user.component.ts
index 8cba0fa..ddd276c 100644
--- a/Front/skydivelogs-app/src/app/login-user/login-user.component.ts
+++ b/Front/skydivelogs-app/src/app/login-user/login-user.component.ts
@@ -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 => {
diff --git a/Front/skydivelogs-app/src/app/login/login.component.ts b/Front/skydivelogs-app/src/app/login/login.component.ts
index 3f761ca..c3f6741 100644
--- a/Front/skydivelogs-app/src/app/login/login.component.ts
+++ b/Front/skydivelogs-app/src/app/login/login.component.ts
@@ -8,7 +8,6 @@ import { TranslateService } from "@ngx-translate/core";
})
export class LoginComponent implements OnInit {
public selectedLanguageFlag: string;
- private flag: Map;
constructor(private translate: TranslateService) {
translate.addLangs(['en', 'fr']);
diff --git a/Front/skydivelogs-app/src/app/summary/summary.component.ts b/Front/skydivelogs-app/src/app/summary/summary.component.ts
index c381c62..ed63fa0 100644
--- a/Front/skydivelogs-app/src/app/summary/summary.component.ts
+++ b/Front/skydivelogs-app/src/app/summary/summary.component.ts
@@ -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;
diff --git a/Front/skydivelogs-app/src/services/aircraft.service.ts b/Front/skydivelogs-app/src/services/aircraft.service.ts
index 1575ddd..b922eb8 100644
--- a/Front/skydivelogs-app/src/services/aircraft.service.ts
+++ b/Front/skydivelogs-app/src/services/aircraft.service.ts
@@ -40,8 +40,12 @@ export class AircraftService extends BaseService {
public getById(id: number) : Observable {
return this.serviceCacheApi.getByKey>(CacheApiKey.Aircraft)
- .pipe(map(data => {
- return data.find(f => f.id === id);
- }));
+ .pipe(map(data => {
+ return data.find(f => f.id === id);
+ }));
+ }
+
+ public getFromCache(): Observable> {
+ return this.serviceCacheApi.getByKey>(CacheApiKey.Aircraft);
}
}
diff --git a/Front/skydivelogs-app/src/services/authentication.service.ts b/Front/skydivelogs-app/src/services/authentication.service.ts
index 16cf178..ecda8ad 100644
--- a/Front/skydivelogs-app/src/services/authentication.service.ts
+++ b/Front/skydivelogs-app/src/services/authentication.service.ts
@@ -22,10 +22,6 @@ export class AuthenticationService extends BaseService {
this.currentUser = this.currentUserSubject.asObservable();
}
- public get currentUserValue(): User {
- return this.currentUserSubject.value;
- }
-
public login(username: string, password: string) {
const bodyLogin = {
login: username,
@@ -61,6 +57,24 @@ export class AuthenticationService extends BaseService {
}));
}
+ public alwaysLogin() {
+ this.http.get(`${this.apiUrl}/User/AlwaysLogin`,
+ { headers: this.headers })
+ .subscribe();
+ }
+
+ public logout() {
+ localStorage.removeItem("currentUser");
+ this.currentUserSubject.next(null);
+ }
+
+ public get currentUserValue(): User {
+ return this.currentUserSubject.value;
+ }
+ public set currentUserValue(value: User) {
+ this.currentUserSubject.next(value);
+ }
+
private pushToken(login: string, password: string, user: User){
if (user && user.token) {
user.authdata = window.btoa(login + ":" + password);
@@ -72,15 +86,4 @@ export class AuthenticationService extends BaseService {
this.currentUserSubject.next(user);
}
}
-
- public alwaysLogin() {
- this.http.get(`${this.apiUrl}/User/AlwaysLogin`,
- { headers: this.headers })
- .subscribe();
- }
-
- public logout() {
- localStorage.removeItem("currentUser");
- this.currentUserSubject.next(null);
- }
}
diff --git a/Front/skydivelogs-app/src/services/dropzone.service.ts b/Front/skydivelogs-app/src/services/dropzone.service.ts
index 647f393..28acc88 100644
--- a/Front/skydivelogs-app/src/services/dropzone.service.ts
+++ b/Front/skydivelogs-app/src/services/dropzone.service.ts
@@ -80,8 +80,12 @@ export class DropzoneService extends BaseService {
public getById(id: number) : Observable {
return this.serviceCacheApi.getByKey>(CacheApiKey.Dropzone)
- .pipe(map(data => {
- return data.find(f => f.id === id);
- }));
+ .pipe(map(data => {
+ return data.find(f => f.id === id);
+ }));
+ }
+
+ public getFromCache(): Observable> {
+ return this.serviceCacheApi.getByKey>(CacheApiKey.Dropzone);
}
}
diff --git a/Front/skydivelogs-app/src/services/gear.service.ts b/Front/skydivelogs-app/src/services/gear.service.ts
index 927d9dd..798f158 100644
--- a/Front/skydivelogs-app/src/services/gear.service.ts
+++ b/Front/skydivelogs-app/src/services/gear.service.ts
@@ -44,8 +44,12 @@ export class GearService extends BaseService {
public getById(id: number) : Observable {
return this.serviceCacheApi.getByKey>(CacheApiKey.Gear)
- .pipe(map(data => {
- return data.find(f => f.id === id);
- }));
+ .pipe(map(data => {
+ return data.find(f => f.id === id);
+ }));
+ }
+
+ public getFromCache(): Observable> {
+ return this.serviceCacheApi.getByKey>(CacheApiKey.Gear);
}
}
diff --git a/Front/skydivelogs-app/src/services/jump-type.service.ts b/Front/skydivelogs-app/src/services/jump-type.service.ts
index 6d25998..32cf748 100644
--- a/Front/skydivelogs-app/src/services/jump-type.service.ts
+++ b/Front/skydivelogs-app/src/services/jump-type.service.ts
@@ -32,8 +32,12 @@ export class JumpTypeService extends BaseService {
public getById(id: number) : Observable {
return this.serviceCacheApi.getByKey>(CacheApiKey.JumpType)
- .pipe(map(data => {
- return data.find(f => f.id === id);
- }));
+ .pipe(map(data => {
+ return data.find(f => f.id === id);
+ }));
+ }
+
+ public getFromCache(): Observable> {
+ return this.serviceCacheApi.getByKey>(CacheApiKey.JumpType);
}
}
diff --git a/Front/skydivelogs-app/src/services/jump.service.ts b/Front/skydivelogs-app/src/services/jump.service.ts
index 5d80ba2..d37ef6b 100644
--- a/Front/skydivelogs-app/src/services/jump.service.ts
+++ b/Front/skydivelogs-app/src/services/jump.service.ts
@@ -5,6 +5,10 @@ import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { JumpResp, JumpReq, Jump } from "../models/jump";
+import { GearResp } from "../models/gear";
+import { DropZoneResp } from "../models/dropzone";
+import { AircraftResp } from "../models/aircraft";
+import { JumpTypeResp } from "../models/jumpType";
import { DateService } from "./date.service";
import { BaseService } from "./base.service";
@@ -29,16 +33,7 @@ export class JumpService extends BaseService {
return this.http.get>(`${this.apiUrl}/Jump`,
{ headers: this.headers })
.pipe(map((response) => {
- let details = response.map((data) =>
- {
- let tmp = new Jump(data);
- this.dropzoneService.getById(data.dropZoneId).subscribe((d)=> tmp.dropZone = d );
- this.aircraftService.getById(data.aircraftId).subscribe((d)=> tmp.aircraft = d );
- this.jumpTypeService.getById(data.jumpTypeId).subscribe((d)=> tmp.jumpType = d );
- this.gearService.getById(data.gearId).subscribe((d)=> tmp.gear = d );
- return tmp;
- });
- return details;
+ return this.MapWithDataInCache(response);
}));
}
@@ -145,4 +140,27 @@ export class JumpService extends BaseService {
.subscribe();
}
}
+
+ private MapWithDataInCache(apiResp: Array) : Array {
+ let allDropzones: Array;
+ this.dropzoneService.getFromCache().subscribe(data => { allDropzones = data; });
+ let allAircrafts: Array;
+ this.aircraftService.getFromCache().subscribe(data => { allAircrafts = data; });
+ let allJumpType: Array;
+ this.jumpTypeService.getFromCache().subscribe(data => { allJumpType = data; });
+ let allGears: Array;
+ this.gearService.getFromCache().subscribe(data => { allGears = data; });
+
+ return apiResp.map((data) =>
+ {
+ let tmp = new Jump(data);
+
+ tmp.dropZone = allDropzones.find(d => d.id == data.dropZoneId);
+ tmp.aircraft = allAircrafts.find(d => d.id == data.aircraftId);
+ tmp.jumpType = allJumpType.find(d => d.id == data.jumpTypeId);
+ tmp.gear = allGears.find(d => d.id == data.gearId);
+
+ return tmp;
+ });
+ }
}
diff --git a/Front/skydivelogs-app/src/services/service-cache-api.service.ts b/Front/skydivelogs-app/src/services/service-cache-api.service.ts
index 1a7db62..1924e97 100644
--- a/Front/skydivelogs-app/src/services/service-cache-api.service.ts
+++ b/Front/skydivelogs-app/src/services/service-cache-api.service.ts
@@ -15,6 +15,7 @@ export class ServiceCacheApi {
}
public get(key: CacheApiKey, callToApi: Observable) : Observable {
+ console.log(`Get cache : ${CacheApiKey[key]}`);
const cached = this.cache.get(key);
if (cached) {
@@ -28,10 +29,12 @@ export class ServiceCacheApi {
}
public delete(key: CacheApiKey) {
+ console.log(`Delete cache : ${CacheApiKey[key]}`);
this.cache.delete(key);
}
public getByKey(key: CacheApiKey) : Observable {
+ console.log(`Get cache by key : ${CacheApiKey[key]}`);
return this.cache.get(key);
}
}