Evol de la page Summary avec

les stats pour la saison en cours
This commit is contained in:
Sébastien André
2020-02-15 22:40:26 +01:00
parent 6e804b1ae4
commit 0eeb0d3e12
6 changed files with 154 additions and 71 deletions

View File

@@ -43,10 +43,10 @@ export class NewJumpComponent implements OnInit {
private serviceDropzone: DropzoneService, private serviceDropzone: DropzoneService,
private serviceGear: GearService, private serviceGear: GearService,
private dateService: DateService private dateService: DateService
) { } ) {}
ngOnInit() { ngOnInit() {
this.serviceComm.UpdatedComponentTitle('Add a new jump'); this.serviceComm.UpdatedComponentTitle("Add a new jump");
this.endDate = new Date(); this.endDate = new Date();
this.beginDate = this.dateService.AddDays(new Date(), -1); this.beginDate = this.dateService.AddDays(new Date(), -1);
@@ -126,8 +126,8 @@ export class NewJumpComponent implements OnInit {
return data ? data.name : undefined; return data ? data.name : undefined;
} }
public onChangeDz(event: DropZoneResp) { public onChangeDz(event: string) {
const filterValue = event.name.toLowerCase(); const filterValue = event.toLowerCase();
this.listOfFilteredDropZone = this.listOfDropZone; this.listOfFilteredDropZone = this.listOfDropZone;
this.listOfFilteredDropZone = this.listOfFilteredDropZone.filter(option => this.listOfFilteredDropZone = this.listOfFilteredDropZone.filter(option =>

View File

@@ -15,10 +15,50 @@
<div class="paragraph"> <div class="paragraph">
<label>Jumps in the last month</label> <label>Jumps in the last month</label>
<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>
<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>
</div> </div>
<div class="paragraph"> <div class="paragraph">
<label>Jumps in the last year</label> <label>Jumps in the last year</label>
<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>
<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>
</div> </div>
<div class="paragraph"> <div class="paragraph">

View File

@@ -1,30 +1,42 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from "@angular/core";
import { MatTableDataSource } from '@angular/material/table'; import { MatTableDataSource } from "@angular/material/table";
import { ServiceComm } from '../../services/service-comm.service'; import { ServiceComm } from "../../services/service-comm.service";
import { StatsService } from '../../services/stats.service'; import { StatsService } from "../../services/stats.service";
import {
StatsByDzResp,
StatsByAircraftResp,
StatsByGearResp,
StatsByJumpTypeResp,
StatsByYearResp
} from "../../models/stats";
@Component({ @Component({
selector: 'app-summary', selector: "app-summary",
templateUrl: './summary.component.html', templateUrl: "./summary.component.html",
styleUrls: ['./summary.component.css'] styleUrls: ["./summary.component.css"]
}) })
export class SummaryComponent implements OnInit { export class SummaryComponent implements OnInit {
public displayedColumns: Array<string> = ['label', 'nb']; public dsNbJumpByDz: MatTableDataSource<StatsByDzResp>;
public dsNbJumpByDz; public dsNbJumpByAircraft: MatTableDataSource<StatsByAircraftResp>;
public dsNbJumpByAircraft; public dsNbJumpByGear: MatTableDataSource<StatsByGearResp>;
public dsNbJumpByGear; public dsNbJumpByType: MatTableDataSource<StatsByJumpTypeResp>;
public dsNbJumpByType; public dsNbJumpByYear: MatTableDataSource<StatsByYearResp>;
public dsNbJumpByYear; public dsJumpForLastYearByDz: MatTableDataSource<StatsByDzResp>;
public dsJumpForLastYearByJumpType: MatTableDataSource<StatsByJumpTypeResp>;
public dsJumpForLastMonthByDz: MatTableDataSource<StatsByDzResp>;
public dsJumpForLastMonthByJumpType: MatTableDataSource<StatsByJumpTypeResp>;
private countDatasLoaded: number; private countDatasLoaded: number;
public displayedColumns: Array<string> = ["label", "nb"];
constructor( constructor(
private serviceApi: StatsService, private serviceApi: StatsService,
private serviceComm: ServiceComm private serviceComm: ServiceComm
) { } ) {}
ngOnInit() { ngOnInit() {
this.countDatasLoaded = 0; this.countDatasLoaded = 0;
this.serviceComm.UpdatedComponentTitle('Summary'); this.serviceComm.UpdatedComponentTitle("Summary");
const statsResult = this.serviceApi.getStatsOfJumps(); const statsResult = this.serviceApi.getStatsOfJumps();
@@ -50,11 +62,17 @@ export class SummaryComponent implements OnInit {
}); });
statsResult.statsForLastYear.subscribe(data => { statsResult.statsForLastYear.subscribe(data => {
this.dsNbJumpByYear = new MatTableDataSource(data); this.dsJumpForLastYearByDz = new MatTableDataSource(data.byDz);
this.dsJumpForLastYearByJumpType = new MatTableDataSource(
data.byJumpType
);
this.countDatasLoaded++; this.countDatasLoaded++;
}); });
statsResult.statsForLastMonth.subscribe(data => { statsResult.statsForLastMonth.subscribe(data => {
this.dsNbJumpByYear = new MatTableDataSource(data); this.dsJumpForLastMonthByDz = new MatTableDataSource(data.byDz);
this.dsJumpForLastMonthByJumpType = new MatTableDataSource(
data.byJumpType
);
this.countDatasLoaded++; this.countDatasLoaded++;
}); });
} }

View File

@@ -1,4 +1,4 @@
import { Observable } from 'rxjs'; import { Observable } from "rxjs";
export class StatsResp { export class StatsResp {
public statsByDz: Observable<Array<StatsByDzResp>>; public statsByDz: Observable<Array<StatsByDzResp>>;
@@ -19,6 +19,7 @@ export class StatsByDzResp {
public label: string; public label: string;
public nb: number; public nb: number;
} }
export class StatsByAircraftResp { export class StatsByAircraftResp {
constructor(data: any) { constructor(data: any) {
Object.assign(this, data); Object.assign(this, data);
@@ -27,6 +28,7 @@ export class StatsByAircraftResp {
public label: string; public label: string;
public nb: number; public nb: number;
} }
export class StatsByGearResp { export class StatsByGearResp {
constructor(data: any) { constructor(data: any) {
Object.assign(this, data); Object.assign(this, data);
@@ -35,6 +37,7 @@ export class StatsByGearResp {
public label: string; public label: string;
public nb: number; public nb: number;
} }
export class StatsByJumpTypeResp { export class StatsByJumpTypeResp {
constructor(data: any) { constructor(data: any) {
Object.assign(this, data); Object.assign(this, data);
@@ -43,6 +46,7 @@ export class StatsByJumpTypeResp {
public label: string; public label: string;
public nb: number; public nb: number;
} }
export class StatsByYearResp { export class StatsByYearResp {
constructor(data: any) { constructor(data: any) {
Object.assign(this, data); Object.assign(this, data);
@@ -52,11 +56,16 @@ export class StatsByYearResp {
public nb: number; public nb: number;
} }
export class StatsForLastYearResp { export class StatsForLastYearResp {
constructor(data: any) { constructor(
Object.assign(this, data); dataByDz: Array<StatsByDzResp>,
dataByJumpType: Array<StatsByJumpTypeResp>
) {
this.byDz = new Array<StatsByDzResp>();
this.byJumpType = new Array<StatsByJumpTypeResp>();
Object.assign(this.byDz, dataByDz);
Object.assign(this.byJumpType, dataByJumpType);
} }
public byDz: Array<StatsByDzResp>; public byDz: Array<StatsByDzResp>;
@@ -64,8 +73,15 @@ export class StatsForLastYearResp {
} }
export class StatsForLastMonthResp { export class StatsForLastMonthResp {
constructor(data: any) { constructor(
Object.assign(this, data); dataByDz: Array<StatsByDzResp>,
dataByJumpType: Array<StatsByJumpTypeResp>
) {
this.byDz = new Array<StatsByDzResp>();
this.byJumpType = new Array<StatsByJumpTypeResp>();
Object.assign(this.byDz, dataByDz);
Object.assign(this.byJumpType, dataByJumpType);
} }
public byDz: Array<StatsByDzResp>; public byDz: Array<StatsByDzResp>;

View File

@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core'; import { Injectable } from "@angular/core";
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from "@angular/common/http";
import { Observable } from 'rxjs'; import { Observable } from "rxjs";
import { map } from 'rxjs/operators'; import { map } from "rxjs/operators";
import { environment } from '../environments/environment'; import { environment } from "../environments/environment";
import { import {
StatsResp, StatsResp,
StatsByDzResp, StatsByDzResp,
@@ -12,16 +12,15 @@ import {
StatsByYearResp, StatsByYearResp,
StatsForLastMonthResp, StatsForLastMonthResp,
StatsForLastYearResp StatsForLastYearResp
} from '../models/stats'; } from "../models/stats";
@Injectable() @Injectable()
export class StatsService { export class StatsService {
private readonly headers = new HttpHeaders({ private readonly headers = new HttpHeaders({
'Access-Control-Allow-Origin': environment.urlApi "Access-Control-Allow-Origin": environment.urlApi
}); });
constructor(private http: HttpClient) { } constructor(private http: HttpClient) {}
public getStatsOfJumps(): StatsResp { public getStatsOfJumps(): StatsResp {
const resultats = new StatsResp(); const resultats = new StatsResp();
@@ -39,10 +38,10 @@ export class StatsService {
} }
private getStatsByDz(): Observable<Array<StatsByDzResp>> { private getStatsByDz(): Observable<Array<StatsByDzResp>> {
return this.http.get<Array<StatsByDzResp>>( return this.http
`${environment.urlApi}/api/Stats/ByDz`, .get<Array<StatsByDzResp>>(`${environment.urlApi}/api/Stats/ByDz`, {
{ headers: this.headers } headers: this.headers
) })
.pipe( .pipe(
map(response => { map(response => {
const stats = response.map(data => new StatsByDzResp(data)); const stats = response.map(data => new StatsByDzResp(data));
@@ -52,10 +51,11 @@ export class StatsService {
} }
private getStatsByAircraft(): Observable<Array<StatsByAircraftResp>> { private getStatsByAircraft(): Observable<Array<StatsByAircraftResp>> {
return this.http.get<Array<StatsByAircraftResp>>( return this.http
`${environment.urlApi}/api/Stats/ByAircraft`, .get<Array<StatsByAircraftResp>>(
{ headers: this.headers } `${environment.urlApi}/api/Stats/ByAircraft`,
) { headers: this.headers }
)
.pipe( .pipe(
map(response => { map(response => {
const stats = response.map(data => new StatsByAircraftResp(data)); const stats = response.map(data => new StatsByAircraftResp(data));
@@ -65,10 +65,11 @@ export class StatsService {
} }
private getStatsByJumpType(): Observable<Array<StatsByJumpTypeResp>> { private getStatsByJumpType(): Observable<Array<StatsByJumpTypeResp>> {
return this.http.get<Array<StatsByJumpTypeResp>>( return this.http
`${environment.urlApi}/api/Stats/ByJumpType`, .get<Array<StatsByJumpTypeResp>>(
{ headers: this.headers } `${environment.urlApi}/api/Stats/ByJumpType`,
) { headers: this.headers }
)
.pipe( .pipe(
map(response => { map(response => {
const stats = response.map(data => new StatsByJumpTypeResp(data)); const stats = response.map(data => new StatsByJumpTypeResp(data));
@@ -78,10 +79,10 @@ export class StatsService {
} }
private getStatsByGear(): Observable<Array<StatsByGearResp>> { private getStatsByGear(): Observable<Array<StatsByGearResp>> {
return this.http.get<Array<StatsByGearResp>>( return this.http
`${environment.urlApi}/api/Stats/ByGear`, .get<Array<StatsByGearResp>>(`${environment.urlApi}/api/Stats/ByGear`, {
{ headers: this.headers } headers: this.headers
) })
.pipe( .pipe(
map(response => { map(response => {
const stats = response.map(data => new StatsByGearResp(data)); const stats = response.map(data => new StatsByGearResp(data));
@@ -91,10 +92,10 @@ export class StatsService {
} }
private getStatsByYear(): Observable<Array<StatsByYearResp>> { private getStatsByYear(): Observable<Array<StatsByYearResp>> {
return this.http.get<Array<StatsByYearResp>>( return this.http
`${environment.urlApi}/api/Stats/ByYear`, .get<Array<StatsByYearResp>>(`${environment.urlApi}/api/Stats/ByYear`, {
{ headers: this.headers } headers: this.headers
) })
.pipe( .pipe(
map(response => { map(response => {
const stats = response.map(data => new StatsByYearResp(data)); const stats = response.map(data => new StatsByYearResp(data));
@@ -103,31 +104,39 @@ export class StatsService {
); );
} }
private getStatsOfLastYear(): Observable<StatsForLastYearResp> { private getStatsOfLastYear(): Observable<StatsForLastYearResp> {
return this.http.get<StatsForLastYearResp>( return this.http
`${environment.urlApi}/api/Stats/ForLastYear`, .get<StatsForLastYearResp>(
{ headers: this.headers } `${environment.urlApi}/api/Stats/ForLastYear`,
) { headers: this.headers }
)
.pipe( .pipe(
map(response => { map(response => {
const stats = response.map(data => new StatsByDzResp(data)); const statsByDz = response.byDz.map(data => new StatsByDzResp(data));
return stats; const statsByJumpType = response.byJumpType.map(
data => new StatsByDzResp(data)
);
return new StatsForLastYearResp(statsByDz, statsByJumpType);
}) })
); );
} }
private getStatsOfLastMonth(): Observable<StatsForLastMonthResp> { private getStatsOfLastMonth(): Observable<StatsForLastMonthResp> {
return this.http.get<StatsForLastYearResp>( return this.http
`${environment.urlApi}/api/Stats/ForLastMonth`, .get<StatsForLastYearResp>(
{ headers: this.headers } `${environment.urlApi}/api/Stats/ForLastMonth`,
) { headers: this.headers }
)
.pipe( .pipe(
map(response => { map(response => {
const stats = response.map(data => new StatsByDzResp(data)); const statsByDz = response.byDz.map(data => new StatsByDzResp(data));
return stats; const statsByJumpType = response.byJumpType.map(
data => new StatsByDzResp(data)
);
return new StatsForLastMonthResp(statsByDz, statsByJumpType);
}) })
); );
} }
} }