Refactor var names

pull/3/head
Max Ehrlicher-Schmidt 4 years ago
parent 0180322e41
commit 4bf9915978

@ -17,7 +17,7 @@
<div class="table-container"> <div class="table-container">
<table <table
mat-table mat-table
[dataSource]="bikes" [dataSource]="data"
class="mat-elevation-z8" class="mat-elevation-z8"
matSort matSort
cdkDropList cdkDropList

@ -21,6 +21,7 @@ export class BikesComponent {
{ name: 'group', header: 'Gruppe', type: 'enum', enumValues: [] }, { name: 'group', header: 'Gruppe', type: 'enum', enumValues: [] },
]; ];
//properties that wont be shown in the table
blacklistedColumns = [ blacklistedColumns = [
'__typename', '__typename',
'isLocked', 'isLocked',
@ -36,7 +37,7 @@ export class BikesComponent {
loadingRowIds: string[] = []; loadingRowIds: string[] = [];
bikes = <Array<any>>[]; data = <Array<any>>[];
selection = new SelectionModel<CargoBikeResult>(true, []); selection = new SelectionModel<CargoBikeResult>(true, []);
reloadingTable = false; reloadingTable = false;
@ -61,13 +62,19 @@ export class BikesComponent {
bikesService.bikes.subscribe((bikes) => { bikesService.bikes.subscribe((bikes) => {
this.reloadingTable = false; this.reloadingTable = false;
this.bikes = bikes; this.data = bikes;
if (bikes[0]) {
if (this.data[0]) {
this.displayedColumns = []; this.displayedColumns = [];
this.dataColumns = []; this.dataColumns = [];
this.addColumnsFromObject('', bikes[0]); this.addColumnsFromObject('', this.data[0]);
for (const bike of this.data)
//sort, so the displayedColumns array is in the same order as the columnInfo
this.dataColumns.sort((columnA, columnB) => { this.dataColumns.sort((columnA, columnB) => {
const indexA = this.columnInfo.findIndex((c) => c.name == columnA); const indexA = this.columnInfo.findIndex((c) => c.name == columnA);
const indexB = this.columnInfo.findIndex((c) => c.name == columnB); const indexB = this.columnInfo.findIndex((c) => c.name == columnB);
@ -89,9 +96,9 @@ export class BikesComponent {
ngOnInit() { ngOnInit() {
this.relockingInterval = setInterval(() => { this.relockingInterval = setInterval(() => {
for (const bike of this.bikes) { for (const row of this.data) {
if (bike.isLockedByMe) { if (row.isLockedByMe) {
this.bikesService.relockBike({ id: bike.id }); this.bikesService.relockBike({ id: row.id });
} }
} }
}, this.relockingDuration); }, this.relockingDuration);
@ -187,7 +194,7 @@ export class BikesComponent {
/** Whether the number of selected elements matches the total number of rows. */ /** Whether the number of selected elements matches the total number of rows. */
isAllSelected() { isAllSelected() {
const numSelected = this.selection.selected.length; const numSelected = this.selection.selected.length;
const numRows = this.bikes.length; const numRows = this.data.length;
return numSelected === numRows; return numSelected === numRows;
} }
@ -195,6 +202,6 @@ export class BikesComponent {
masterToggle() { masterToggle() {
this.isAllSelected() this.isAllSelected()
? this.selection.clear() ? this.selection.clear()
: this.bikes.forEach((row) => this.selection.select(row)); : this.data.forEach((row) => this.selection.select(row));
} }
} }

Loading…
Cancel
Save