Update to retrieve the jumps page by page.
This commit is contained in:
@@ -51,6 +51,7 @@ import { MatIconModule } from "@angular/material/icon";
|
||||
import { MatInputModule } from "@angular/material/input";
|
||||
import { MatPaginatorModule } from "@angular/material/paginator";
|
||||
import { MatProgressSpinnerModule } from "@angular/material/progress-spinner";
|
||||
import { MatProgressBarModule } from "@angular/material/progress-bar";
|
||||
import { MatSelectModule } from "@angular/material/select";
|
||||
import { MatTableModule } from "@angular/material/table";
|
||||
import { MatTabsModule } from "@angular/material/tabs";
|
||||
@@ -173,6 +174,7 @@ export function initConfig(configService: ConfigurationHelper) {
|
||||
MatIconModule,
|
||||
MatAutocompleteModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatProgressBarModule,
|
||||
MatTabsModule,
|
||||
MatDialogModule,
|
||||
MatCardModule,
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
<div>
|
||||
<button mat-raised-button color="accent" [routerLink]="['/newjump']" [routerLinkActive]="['active']" skipLocationChange>{{ 'List_Jump_Add' | translate }}</button>
|
||||
</div>
|
||||
<div *ngIf="dataSourceTable != null else loading">
|
||||
|
||||
<mat-progress-bar [mode]="'indeterminate'" *ngIf="isLoading"></mat-progress-bar>
|
||||
|
||||
<div>
|
||||
<table mat-table [dataSource]="dataSourceTable">
|
||||
<ng-container matColumnDef="infos">
|
||||
<th mat-header-cell *matHeaderCellDef style="min-width: 80px;"></th>
|
||||
@@ -17,7 +20,7 @@
|
||||
<ng-container matColumnDef="id">
|
||||
<th mat-header-cell *matHeaderCellDef style="min-width: 70px;">{{ 'List_Jump_Header_Num' | translate }}</th>
|
||||
<td mat-cell *matCellDef="let element; let i = index">
|
||||
{{ resultsLength - ( (dataSourceTable.paginator.pageIndex * dataSourceTable.paginator.pageSize ) + i ) }}
|
||||
{{ paginator.length - ( (paginator.pageIndex * paginator.pageSize ) + i ) }}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
@@ -68,9 +71,6 @@
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</div>
|
||||
<mat-paginator [length]="resultsLength" [pageSize]="20"></mat-paginator>
|
||||
|
||||
<ng-template #loading>
|
||||
<mat-progress-spinner [mode]="'indeterminate'"></mat-progress-spinner>
|
||||
</ng-template>
|
||||
<mat-paginator #paginator [pageSize]="20" (page)="pageChanged($event)" showFirstLastButtons></mat-paginator>
|
||||
</div>
|
||||
|
||||
@@ -1,98 +1,102 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { Component, OnInit, ViewChild } from "@angular/core";
|
||||
import { MatPaginator, PageEvent } from "@angular/material/paginator";
|
||||
import { MatTableDataSource } from "@angular/material/table";
|
||||
import { MatDialog } from "@angular/material/dialog";
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
|
||||
import { AddAction } from '../../models/add-action.enum';
|
||||
import { Jump } from '../../models/jump';
|
||||
import { JumpService } from '../../services/jump.service';
|
||||
import { ServiceComm } from '../../services/service-comm.service';
|
||||
import { AddAction } from "../../models/add-action.enum";
|
||||
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";
|
||||
import { StatsService } from '../../services/stats.service';
|
||||
import { StatsService } from "../../services/stats.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-list-of-jumps',
|
||||
templateUrl: './list-of-jumps.component.html',
|
||||
styleUrls: ['./list-of-jumps.component.css']
|
||||
selector: "app-list-of-jumps",
|
||||
templateUrl: "./list-of-jumps.component.html",
|
||||
styleUrls: ["./list-of-jumps.component.css"],
|
||||
})
|
||||
export class ListOfJumpsComponent implements OnInit {
|
||||
public displayedColumns: Array<string> = [
|
||||
'infos',
|
||||
'id',
|
||||
'jumpDate',
|
||||
'jumpType',
|
||||
'aircraft',
|
||||
'dropZone',
|
||||
'actions'
|
||||
"infos",
|
||||
"id",
|
||||
"jumpDate",
|
||||
"jumpType",
|
||||
"aircraft",
|
||||
"dropZone",
|
||||
"actions",
|
||||
];
|
||||
public dataSourceTable;
|
||||
public resultsLength = 0;
|
||||
public dataSourceTable: MatTableDataSource<Jump> = new MatTableDataSource();
|
||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||
public isLoading: boolean = false;
|
||||
|
||||
constructor(private serviceApi: JumpService,
|
||||
private serviceComm: ServiceComm,
|
||||
public dialog: MatDialog,
|
||||
private translateService: TranslateService,
|
||||
private statsService : StatsService) { }
|
||||
private statsService: StatsService
|
||||
) {}
|
||||
|
||||
ngAferViewInit(): void {
|
||||
this.dataSourceTable.paginator = this.paginator;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.serviceComm.refreshRequest.subscribe(action => {
|
||||
this.serviceComm.refreshRequest.subscribe((action) => {
|
||||
if (action === AddAction.Jump) {
|
||||
this.dialog.closeAll();
|
||||
this.getListOfJumps();
|
||||
}
|
||||
});
|
||||
this.serviceComm.forceTranslateTitle.subscribe((data)=> {
|
||||
if (data === true){
|
||||
this.serviceComm.forceTranslateTitle.subscribe((data) => {
|
||||
if (data === true) {
|
||||
this.updateTitle();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.updateTitle();
|
||||
this.getListOfJumps();
|
||||
}
|
||||
|
||||
getListOfJumps() {
|
||||
this.serviceApi.GetListOfJumps().subscribe(data => {
|
||||
setTimeout(() => {
|
||||
data.sort((a, b) => {
|
||||
if (a.jumpDate.getTime() === b.jumpDate.getTime()) {
|
||||
return b.id > a.id ? 1 : -1;
|
||||
}
|
||||
return b.jumpDate > a.jumpDate ? 1 : -1;
|
||||
});
|
||||
getListOfJumps(pageSize: number = 20, pageIndex: number = 0) {
|
||||
this.isLoading = true;
|
||||
|
||||
this.dataSourceTable = new MatTableDataSource<Jump>(data);
|
||||
this.dataSourceTable.paginator = this.paginator;
|
||||
this.paginator.pageSize
|
||||
this.resultsLength = data.length;
|
||||
}, 500);
|
||||
});
|
||||
this.serviceApi.GetJumps(pageIndex * pageSize, pageIndex * pageSize + pageSize)
|
||||
.subscribe((data) => {
|
||||
this.dataSourceTable.data = data.rows;
|
||||
setTimeout(() => {
|
||||
this.paginator.length = data.count;
|
||||
this.paginator.pageIndex = pageIndex;
|
||||
this.isLoading = false;
|
||||
}, 500);
|
||||
});
|
||||
}
|
||||
|
||||
openDialog(item: Jump, editMode: boolean) {
|
||||
this.dialog.open(JumpInfosComponent,
|
||||
{ data: { "jump": item, "editMode": editMode},
|
||||
maxHeight: "400px",
|
||||
minWidth: "350px"
|
||||
});
|
||||
this.dialog.open(JumpInfosComponent, {
|
||||
data: { jump: item, editMode: editMode },
|
||||
maxHeight: "400px",
|
||||
minWidth: "350px",
|
||||
});
|
||||
}
|
||||
|
||||
delete(item: Jump) {
|
||||
let data : Array<Jump> = this.dataSourceTable.data;
|
||||
data = data.filter(d => d.id !== item.id);
|
||||
|
||||
let data: Array<Jump> = this.dataSourceTable.data;
|
||||
data = data.filter((d) => d.id !== item.id);
|
||||
|
||||
this.dataSourceTable.data = data;
|
||||
this.resultsLength = data.length;
|
||||
|
||||
this.serviceApi.DeleteJump(item);
|
||||
this.statsService.resetStats();
|
||||
}
|
||||
|
||||
pageChanged(event: PageEvent) {
|
||||
this.getListOfJumps(event.pageSize, event.pageIndex);
|
||||
}
|
||||
|
||||
private updateTitle() {
|
||||
this.translateService.get("ListJumps_Title").subscribe(
|
||||
data => { this.serviceComm.UpdatedComponentTitle(data); }
|
||||
);
|
||||
this.translateService.get("ListJumps_Title").subscribe((data) => {
|
||||
this.serviceComm.UpdatedComponentTitle(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
19
Front/skydivelogs-app/src/models/jumpList.ts
Normal file
19
Front/skydivelogs-app/src/models/jumpList.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { JumpResp, Jump } from "./jump";
|
||||
|
||||
export class JumpListResp {
|
||||
constructor(data: any) {
|
||||
Object.assign(this, data);
|
||||
}
|
||||
|
||||
public count: number;
|
||||
public rows: Array<JumpResp>;
|
||||
}
|
||||
|
||||
export class JumpList {
|
||||
constructor(data: any) {
|
||||
Object.assign(this, data);
|
||||
}
|
||||
|
||||
public count: number;
|
||||
public rows: Array<Jump>;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { forkJoin, Observable, of } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
|
||||
import { JumpResp, JumpReq, Jump } from "../models/jump";
|
||||
import { JumpListResp, JumpList } from "../models/jumpList";
|
||||
import { GearResp } from "../models/gear";
|
||||
import { DropZoneResp } from "../models/dropzone";
|
||||
import { AircraftResp } from "../models/aircraft";
|
||||
@@ -39,6 +40,19 @@ export class JumpService extends BaseService {
|
||||
}));
|
||||
}
|
||||
|
||||
public GetJumps(beginIndex: number, endIndex: number): Observable<JumpList> {
|
||||
return this.http.get<JumpListResp>(`${this.apiUrl}/Jump/${beginIndex}/${endIndex}`,
|
||||
{ headers: this.headers })
|
||||
.pipe(map((response) => {
|
||||
let result: JumpList = {
|
||||
rows : this.MapWithDataInCache(response.rows),
|
||||
count : response.count
|
||||
};
|
||||
|
||||
return new JumpList(result);
|
||||
}));
|
||||
}
|
||||
|
||||
public AddListOfJump(selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
|
||||
Reference in New Issue
Block a user