From 784bdea78674d983e15b12513ebaac57c521aabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Mon, 3 May 2021 16:13:55 +0200 Subject: [PATCH] =?UTF-8?q?Bug=20fix=20+=20Meilleur=20chargement=20du=20ca?= =?UTF-8?q?che=20apr=C3=A8s=20login?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../skydivelogs-app/src/app/app.component.ts | 17 +----- .../list-of-jumps/list-of-jumps.component.ts | 12 ++--- .../app/login-user/login-user.component.ts | 54 ++++++++++--------- .../src/app/summary/summary.component.html | 4 +- .../src/app/summary/summary.component.ts | 2 - Front/skydivelogs-app/src/models/jump.ts | 19 +++++++ Front/skydivelogs-app/src/models/stats.ts | 19 ++++--- .../src/services/jump.service.ts | 34 ++++++------ .../src/services/stats.service.ts | 27 +++++++--- 9 files changed, 107 insertions(+), 81 deletions(-) diff --git a/Front/skydivelogs-app/src/app/app.component.ts b/Front/skydivelogs-app/src/app/app.component.ts index 8188b9b..5cf31a2 100644 --- a/Front/skydivelogs-app/src/app/app.component.ts +++ b/Front/skydivelogs-app/src/app/app.component.ts @@ -8,10 +8,6 @@ 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", @@ -26,11 +22,7 @@ export class AppComponent implements OnInit { constructor(private router: Router, private authenticationService: AuthenticationService, private serviceComm: ServiceComm, - private serviceCacheApi : ServiceCacheApi, - private serviceApiAircraft : AircraftService, - private serviceApiJumpType : JumpTypeService, - private serviceApiDropzone : DropzoneService, - private serviceApiGear : GearService) + private serviceCacheApi : ServiceCacheApi) { this.authenticationService.currentUser.subscribe(user => { this.currentUser = user; }); @@ -44,13 +36,6 @@ export class AppComponent implements OnInit { ngOnInit() { this.serviceComm.componentTitle.subscribe(title => (this.title = title)); - - if (this.authenticationService.currentUserValue != undefined) { - this.serviceApiAircraft.getListOfAircrafts(false).subscribe(); - this.serviceApiJumpType.getListOfJumpTypes().subscribe(); - this.serviceApiDropzone.getListOfDropZones(false).subscribe(); - this.serviceApiGear.getListOfGears().subscribe(); - } } show() { 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 ad4a5cc..40e9765 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 @@ -5,7 +5,7 @@ import { MatDialog } from "@angular/material/dialog"; import { Observable } from 'rxjs'; import { AddAction } from '../../models/add-action.enum'; -import { JumpResp } from '../../models/jump'; +import { Jump } from '../../models/jump'; import { JumpService } from '../../services/jump.service'; import { ServiceComm } from '../../services/service-comm.service'; import { JumpInfosComponent } from "../jump-infos/jump-infos.component"; @@ -16,7 +16,7 @@ import { JumpInfosComponent } from "../jump-infos/jump-infos.component"; styleUrls: ['./list-of-jumps.component.css'] }) export class ListOfJumpsComponent implements OnInit { - public listOfJumps: Observable>; + public listOfJumps: Observable>; public displayedColumns: Array = [ 'infos', 'id', @@ -56,7 +56,7 @@ export class ListOfJumpsComponent implements OnInit { return b.jumpDate > a.jumpDate ? 1 : -1; }); - this.dataSourceTable = new MatTableDataSource(data); + this.dataSourceTable = new MatTableDataSource(data); this.dataSourceTable.paginator = this.paginator; this.paginator.pageSize this.resultsLength = data.length; @@ -64,7 +64,7 @@ export class ListOfJumpsComponent implements OnInit { }); } - openDialog(item: JumpResp, editMode: boolean) { + openDialog(item: Jump, editMode: boolean) { this.dialog.open(JumpInfosComponent, { data: { "jump": item, "editMode": editMode}, maxHeight: "400px", @@ -72,8 +72,8 @@ export class ListOfJumpsComponent implements OnInit { }); } - delete(item: JumpResp) { - let data : Array = this.dataSourceTable.data; + delete(item: Jump) { + let data : Array = this.dataSourceTable.data; data = data.filter(d => d.id !== item.id); this.dataSourceTable.data = data; 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 dd815bd..9464afe 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 @@ -6,6 +6,10 @@ import { MatInput } from '@angular/material/input'; 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', @@ -20,13 +24,14 @@ export class LoginUserComponent implements OnInit, AfterViewInit { error = ''; @ViewChild('username') userNameInput: MatInput; - constructor( - private formBuilder: FormBuilder, - private route: ActivatedRoute, - private router: Router, - private authenticationService: AuthenticationService - ) { - // redirect to home if already logged in + 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) { if (this.authenticationService.currentUserValue) { this.router.navigate(['/']); } @@ -40,12 +45,7 @@ export class LoginUserComponent implements OnInit, AfterViewInit { this.loginForm = this.formBuilder.group( { username: ['', [Validators.required, Validators.minLength(3)]], - password: [ - '', - [ - Validators.required - ] - ] + password: ['', [Validators.required]] }, { updateOn: 'blur' } ); @@ -68,17 +68,21 @@ export class LoginUserComponent implements OnInit, AfterViewInit { } this.loading = true; - this.authenticationService - .login(this.formCtrls.username.value, this.formCtrls.password.value) - .pipe(first()) - .subscribe( - data => { - this.router.navigate([this.returnUrl]); - }, - error => { - this.error = error; - this.loading = false; - } - ); + this.authenticationService.login(this.formCtrls.username.value, this.formCtrls.password.value) + .pipe(first()) + .subscribe( + () => { + this.serviceApiAircraft.getListOfAircrafts(false).subscribe(); + this.serviceApiJumpType.getListOfJumpTypes().subscribe(); + this.serviceApiDropzone.getListOfDropZones(false).subscribe(); + this.serviceApiGear.getListOfGears().subscribe(); + + this.router.navigate([this.returnUrl]); + }, + error => { + this.error = error; + this.loading = false; + } + ); } } diff --git a/Front/skydivelogs-app/src/app/summary/summary.component.html b/Front/skydivelogs-app/src/app/summary/summary.component.html index 546d566..5bf3710 100644 --- a/Front/skydivelogs-app/src/app/summary/summary.component.html +++ b/Front/skydivelogs-app/src/app/summary/summary.component.html @@ -11,7 +11,7 @@
- : {{ lastJump | date: 'yyyy-MM-dd' }} + : {{ lastJump }}
@@ -21,7 +21,7 @@
+ (selectedIndex)="0" (selectedTabChange)="onTabChanged($event);">
diff --git a/Front/skydivelogs-app/src/app/summary/summary.component.ts b/Front/skydivelogs-app/src/app/summary/summary.component.ts index 10c3e40..c381c62 100644 --- a/Front/skydivelogs-app/src/app/summary/summary.component.ts +++ b/Front/skydivelogs-app/src/app/summary/summary.component.ts @@ -50,8 +50,6 @@ export class SummaryComponent implements OnInit { data.byJumpType ); }); - - this.tabGroup.selectedIndex = 0; } public refreshStats() { diff --git a/Front/skydivelogs-app/src/models/jump.ts b/Front/skydivelogs-app/src/models/jump.ts index ddf1f19..940cbc9 100644 --- a/Front/skydivelogs-app/src/models/jump.ts +++ b/Front/skydivelogs-app/src/models/jump.ts @@ -45,3 +45,22 @@ export class JumpResp { public jumpDate: Date; public isSpecial: boolean; } + +export class Jump { + constructor(data: any) { + Object.assign(this, data); + this.jumpDate = new Date(data.jumpDate); + } + + public id: number; + public jumpType: JumpTypeResp; + public aircraft: AircraftResp; + public dropZone: DropZoneResp; + public gear: GearResp; + public exitAltitude: number; + public deployAltitude: number; + public withCutaway: boolean; + public notes: string; + public jumpDate: Date; + public isSpecial: boolean; +} \ No newline at end of file diff --git a/Front/skydivelogs-app/src/models/stats.ts b/Front/skydivelogs-app/src/models/stats.ts index 95d9f6d..bfc7b33 100644 --- a/Front/skydivelogs-app/src/models/stats.ts +++ b/Front/skydivelogs-app/src/models/stats.ts @@ -1,5 +1,5 @@ import { Observable } from 'rxjs'; -import { JumpResp } from './jump'; +import { Jump, JumpResp } from './jump'; export class StatsResp { public simpleSummary: Observable; @@ -14,14 +14,10 @@ export class StatsResp { public statsForLastMonth: Observable; } -export class SimpleSummary { +export class SimpleSummaryResp { constructor(data: any) { this.totalJumps = data.totalJumps; this.totalCutaways = data.totalCutaways; - - if (data.lastJump !== null) { - this.lastJump = new JumpResp(data.lastJump); - } } public totalJumps: number; @@ -29,6 +25,17 @@ export class SimpleSummary { public lastJump: JumpResp; } +export class SimpleSummary { + constructor(data: any) { + this.totalJumps = data.totalJumps; + this.totalCutaways = data.totalCutaways; + } + + public totalJumps: number; + public totalCutaways: number; + public lastJump: Jump; +} + export class StatsByDzResp { constructor(data: any) { Object.assign(this, data); diff --git a/Front/skydivelogs-app/src/services/jump.service.ts b/Front/skydivelogs-app/src/services/jump.service.ts index d623876..5d80ba2 100644 --- a/Front/skydivelogs-app/src/services/jump.service.ts +++ b/Front/skydivelogs-app/src/services/jump.service.ts @@ -4,7 +4,7 @@ import { DatePipe } from '@angular/common'; import { Observable } from "rxjs"; import { map } from "rxjs/operators"; -import { JumpResp, JumpReq } from "../models/jump"; +import { JumpResp, JumpReq, Jump } from "../models/jump"; import { DateService } from "./date.service"; import { BaseService } from "./base.service"; @@ -21,27 +21,25 @@ export class JumpService extends BaseService { private dropzoneService: DropzoneService, private aircraftService: AircraftService, private jumpTypeService: JumpTypeService, - private gearService: GearService,) { + private gearService: GearService) { super(); } - public GetListOfJumps(): Observable> { + public GetListOfJumps(): Observable> { return this.http.get>(`${this.apiUrl}/Jump`, { headers: this.headers }) - .pipe( - map((response) => { + .pipe(map((response) => { 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; - }); + { + 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; - }) - ); + })); } public AddListOfJump(selectedJumpType: number, @@ -91,10 +89,10 @@ export class JumpService extends BaseService { isSpecial); } - public DeleteJump(item: JumpResp) { + public DeleteJump(item: Jump) { this.http.delete(`${this.apiUrl}/Jump/${item.id}`, { headers: this.headers, }) - .subscribe((data) => console.log(data)); + .subscribe(); } public UpdateJump(id: number, @@ -144,7 +142,7 @@ export class JumpService extends BaseService { this.http.post(`${this.apiUrl}/Jump`, bodyNewjump, { headers: this.headers, }) - .subscribe((data) => console.log(data)); + .subscribe(); } } } diff --git a/Front/skydivelogs-app/src/services/stats.service.ts b/Front/skydivelogs-app/src/services/stats.service.ts index d78679e..920e9a7 100644 --- a/Front/skydivelogs-app/src/services/stats.service.ts +++ b/Front/skydivelogs-app/src/services/stats.service.ts @@ -5,15 +5,24 @@ import { map } from 'rxjs/operators'; import { StatsByDzResp, StatsByAircraftResp, StatsByJumpTypeResp, StatsByGearResp, StatsByYearResp, StatsForLastMonthResp, - StatsForLastYearResp, SimpleSummary } from '../models/stats'; + StatsForLastYearResp, SimpleSummary, SimpleSummaryResp } from '../models/stats'; 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"; import { CacheApiKey } from '../models/cache-api-key.enum'; +import { Jump } from '../models/jump'; @Injectable() export class StatsService extends BaseService { - constructor(private http: HttpClient) { + constructor(private http: HttpClient, + private dropzoneService: DropzoneService, + private aircraftService: AircraftService, + private jumpTypeService: JumpTypeService, + private gearService: GearService) { super(); } @@ -29,10 +38,16 @@ export class StatsService extends BaseService { } public getSimpleSummary(): Observable { - let callToApi = this.http.get>(`${this.apiUrl}/Stats/Simple`, { headers: this.headers }) - .pipe( - map(response => { - const stats = new SimpleSummary(response); + let callToApi = this.http.get(`${this.apiUrl}/Stats/Simple`, { headers: this.headers }) + .pipe(map(response => { + let tmp = new Jump(response.lastJump); + this.dropzoneService.getById(response.lastJump.dropZoneId).subscribe((d)=> tmp.dropZone = d ); + this.aircraftService.getById(response.lastJump.aircraftId).subscribe((d)=> tmp.aircraft = d ); + this.jumpTypeService.getById(response.lastJump.jumpTypeId).subscribe((d)=> tmp.jumpType = d ); + this.gearService.getById(response.lastJump.gearId).subscribe((d)=> tmp.gear = d ); + + let stats = new SimpleSummary(response); + stats.lastJump = tmp; return stats; }) );