"Sort" sur les tableaux et listes déroulantes.

This commit is contained in:
Sébastien André
2021-04-22 14:29:22 +02:00
parent a2ea873ae3
commit 6f7b439e56
8 changed files with 19 additions and 13 deletions

View File

@@ -16,7 +16,7 @@ import { AircraftResp } from '../../models/aircraft';
styleUrls: ['./list-of-aircrafts.component.css'] styleUrls: ['./list-of-aircrafts.component.css']
}) })
export class ListOfAircraftsComponent implements OnInit { export class ListOfAircraftsComponent implements OnInit {
public displayedColumns: Array<string> = ['id', 'name', 'imageData']; public displayedColumns: Array<string> = ['name', 'imageData'];
public dataSourceTable: MatTableDataSource<AircraftResp>; public dataSourceTable: MatTableDataSource<AircraftResp>;
public resultsLength = 0; public resultsLength = 0;
public isUserAdmin: boolean; public isUserAdmin: boolean;
@@ -43,7 +43,7 @@ export class ListOfAircraftsComponent implements OnInit {
private getListOfAircrafts() { private getListOfAircrafts() {
this.serviceApi.getListOfAircrafts().subscribe(data => { this.serviceApi.getListOfAircrafts().subscribe(data => {
setTimeout(() => { setTimeout(() => {
data.sort((a, b) => (b.name < a.name ? 1 : -1)); data.sort((a, b) => a.name.localeCompare(b.name));
this.dataSourceTable = new MatTableDataSource<AircraftResp>(data); this.dataSourceTable = new MatTableDataSource<AircraftResp>(data);
this.dataSourceTable.paginator = this.paginator; this.dataSourceTable.paginator = this.paginator;
this.resultsLength = data.length; this.resultsLength = data.length;

View File

@@ -18,7 +18,6 @@ import { NewDropZoneComponent } from '../new-drop-zone/new-drop-zone.component';
export class ListOfDzsComponent implements OnInit { export class ListOfDzsComponent implements OnInit {
public displayedColumns: Array<string> = [ public displayedColumns: Array<string> = [
'isfavorite', 'isfavorite',
'id',
'name', 'name',
'address', 'address',
'type', 'type',
@@ -49,7 +48,7 @@ export class ListOfDzsComponent implements OnInit {
private getListOfDropZones() { private getListOfDropZones() {
this.serviceApi.getListOfDropZones().subscribe((data) => { this.serviceApi.getListOfDropZones().subscribe((data) => {
setTimeout(() => { setTimeout(() => {
data.sort((a, b) => (b.isFavorite ? 1 : 0) - (a.isFavorite ? 1 : 0)); data.sort((a, b) => (b.isFavorite ? 1 : 0) - (a.isFavorite ? 1 : 0) || a.name.localeCompare(b.name));
this.dataSourceTable = new MatTableDataSource<DropZoneResp>(data); this.dataSourceTable = new MatTableDataSource<DropZoneResp>(data);
this.dataSourceTable.paginator = this.paginator; this.dataSourceTable.paginator = this.paginator;
this.resultsLength = data.length; this.resultsLength = data.length;

View File

@@ -16,7 +16,6 @@ import { NewGearComponent } from "../new-gear/new-gear.component";
}) })
export class ListOfGearsComponent implements OnInit { export class ListOfGearsComponent implements OnInit {
public displayedColumns: Array<string> = [ public displayedColumns: Array<string> = [
"id",
"name", "name",
"manufacturer", "manufacturer",
"maxSize", "maxSize",
@@ -47,6 +46,7 @@ export class ListOfGearsComponent implements OnInit {
this.serviceApi.getListOfGears() this.serviceApi.getListOfGears()
.subscribe(data => { .subscribe(data => {
setTimeout(() => { setTimeout(() => {
data.sort((a, b) => b.id - a.id);
this.dataSourceTable = new MatTableDataSource<GearResp>(data); this.dataSourceTable = new MatTableDataSource<GearResp>(data);
this.dataSourceTable.paginator = this.paginator; this.dataSourceTable.paginator = this.paginator;
this.resultsLength = data.length; this.resultsLength = data.length;

View File

@@ -16,7 +16,7 @@ import { NewJumpTypeComponent } from "../new-jump-type/new-jump-type.component";
styleUrls: ["./list-of-jump-types.component.css"] styleUrls: ["./list-of-jump-types.component.css"]
}) })
export class ListOfJumpTypesComponent implements OnInit { export class ListOfJumpTypesComponent implements OnInit {
public displayedColumns: Array<string> = ["id", "name"]; public displayedColumns: Array<string> = ["name"];
public dataSourceTable: MatTableDataSource<JumpTypeResp>; public dataSourceTable: MatTableDataSource<JumpTypeResp>;
public isUserAdmin: boolean; public isUserAdmin: boolean;
public resultsLength = 0; public resultsLength = 0;
@@ -43,7 +43,7 @@ export class ListOfJumpTypesComponent implements OnInit {
getListOfJumpTypes() { getListOfJumpTypes() {
this.serviceApi.getListOfJumpTypes().subscribe(data => { this.serviceApi.getListOfJumpTypes().subscribe(data => {
setTimeout(() => { setTimeout(() => {
data.sort((a, b) => (b.name < a.name ? 1 : -1)); data.sort((a, b) => a.name.localeCompare(b.name));
this.dataSourceTable = new MatTableDataSource<JumpTypeResp>(data); this.dataSourceTable = new MatTableDataSource<JumpTypeResp>(data);
this.dataSourceTable.paginator = this.paginator; this.dataSourceTable.paginator = this.paginator;
this.resultsLength = data.length; this.resultsLength = data.length;

View File

@@ -26,3 +26,7 @@ table {
align-items: initial; align-items: initial;
padding-top: 25px; padding-top: 25px;
} }
th.mat-header-cell {
text-align: center;
}

View File

@@ -5,7 +5,7 @@
<div *ngIf="dataSourceTable != null else loading"> <div *ngIf="dataSourceTable != null else loading">
<table mat-table [dataSource]="dataSourceTable"> <table mat-table [dataSource]="dataSourceTable">
<ng-container matColumnDef="infos"> <ng-container matColumnDef="infos">
<th mat-header-cell *matHeaderCellDef></th> <th mat-header-cell *matHeaderCellDef style="width: 60px;"></th>
<td mat-cell *matCellDef="let element" style="text-align: left;"> <td mat-cell *matCellDef="let element" style="text-align: left;">
<mat-icon aria-hidden="false" aria-label="Special jump" [style.visibility]="element.isSpecial ? 'visible' : 'hidden'">celebration</mat-icon> <mat-icon aria-hidden="false" aria-label="Special jump" [style.visibility]="element.isSpecial ? 'visible' : 'hidden'">celebration</mat-icon>
<mat-icon aria-hidden="false" aria-label="Additional informations of the jump" style="cursor: pointer;" <mat-icon aria-hidden="false" aria-label="Additional informations of the jump" style="cursor: pointer;"
@@ -14,7 +14,7 @@
</ng-container> </ng-container>
<ng-container matColumnDef="id"> <ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef>ID</th> <th mat-header-cell *matHeaderCellDef style="width: 60px;">Num</th>
<td mat-cell *matCellDef="let element">{{element.id}}</td> <td mat-cell *matCellDef="let element">{{element.id}}</td>
</ng-container> </ng-container>
@@ -52,7 +52,7 @@
</ng-container> </ng-container>
<ng-container matColumnDef="actions"> <ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef></th> <th mat-header-cell *matHeaderCellDef style="width: 70px;"></th>
<td mat-cell *matCellDef="let element" style="text-align: left;"> <td mat-cell *matCellDef="let element" style="text-align: left;">
<mat-icon aria-hidden="false" aria-label="Delete this jump" style="cursor: pointer;" <mat-icon aria-hidden="false" aria-label="Delete this jump" style="cursor: pointer;"
(click)='delete(element)'>delete</mat-icon> (click)='delete(element)'>delete</mat-icon>
@@ -65,7 +65,7 @@
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table> </table>
</div> </div>
<mat-paginator [length]="resultsLength" [pageSize]="10"></mat-paginator> <mat-paginator [length]="resultsLength" [pageSize]="20"></mat-paginator>
<ng-template #loading> <ng-template #loading>
<mat-progress-spinner [mode]="'indeterminate'"></mat-progress-spinner> <mat-progress-spinner [mode]="'indeterminate'"></mat-progress-spinner>

View File

@@ -49,7 +49,7 @@ export class ListOfJumpsComponent implements OnInit {
this.listOfJumps = this.serviceApi.GetListOfJumps(); this.listOfJumps = this.serviceApi.GetListOfJumps();
this.listOfJumps.subscribe(data => { this.listOfJumps.subscribe(data => {
setTimeout(() => { setTimeout(() => {
data.sort((a, b) => b.jumpDate.getTime() - a.jumpDate.getTime()); data.sort((a, b) => b.id - a.id);
this.dataSourceTable = new MatTableDataSource<JumpResp>(data); this.dataSourceTable = new MatTableDataSource<JumpResp>(data);
this.dataSourceTable.paginator = this.paginator; this.dataSourceTable.paginator = this.paginator;
this.resultsLength = data.length; this.resultsLength = data.length;

View File

@@ -98,6 +98,7 @@ export class NewJumpComponent implements OnInit {
private getListOfJumpTypes() { private getListOfJumpTypes() {
this.serviceJumpType.getListOfJumpTypes().subscribe((data) => { this.serviceJumpType.getListOfJumpTypes().subscribe((data) => {
data.sort((a, b) => a.name.localeCompare(b.name));
this.listOfJumpType = data; this.listOfJumpType = data;
this.countDatasLoaded = 1; this.countDatasLoaded = 1;
@@ -109,6 +110,7 @@ export class NewJumpComponent implements OnInit {
private getListOfAircrafts() { private getListOfAircrafts() {
this.serviceAircraft.getListOfAircrafts(true).subscribe((data) => { this.serviceAircraft.getListOfAircrafts(true).subscribe((data) => {
data.sort((a, b) => a.name.localeCompare(b.name));
this.listOfAircraft = data; this.listOfAircraft = data;
this.countDatasLoaded++; this.countDatasLoaded++;
}); });
@@ -116,7 +118,7 @@ export class NewJumpComponent implements OnInit {
private getListOfDropZones() { private getListOfDropZones() {
this.serviceDropzone.getListOfDropZones(true).subscribe((data) => { this.serviceDropzone.getListOfDropZones(true).subscribe((data) => {
data.sort((a, b) => (b.isFavorite ? 1 : 0) - (a.isFavorite ? 1 : 0)); data.sort((a, b) => (b.isFavorite ? 1 : 0) - (a.isFavorite ? 1 : 0) || a.name.localeCompare(b.name));
this.listOfDropZone = data; this.listOfDropZone = data;
this.listOfFilteredDropZone = data; this.listOfFilteredDropZone = data;
this.countDatasLoaded++; this.countDatasLoaded++;
@@ -125,6 +127,7 @@ export class NewJumpComponent implements OnInit {
private getListOfGears() { private getListOfGears() {
this.serviceGear.getListOfGears().subscribe((data) => { this.serviceGear.getListOfGears().subscribe((data) => {
data.sort((a, b) => b.id - a.id);
this.listOfGear = data; this.listOfGear = data;
this.countDatasLoaded++; this.countDatasLoaded++;
}); });