|
|
@ -1,12 +1,13 @@
|
|
|
|
import { SelectionModel } from '@angular/cdk/collections';
|
|
|
|
import { SelectionModel } from '@angular/cdk/collections';
|
|
|
|
import { Component, ChangeDetectorRef } from '@angular/core';
|
|
|
|
import { Component } from '@angular/core';
|
|
|
|
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
|
|
|
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
|
|
|
import { BikesService, CargoBikeResult } from 'src/app/services/bikes.service';
|
|
|
|
import { BikesService, CargoBikeResult } from 'src/app/services/bikes.service';
|
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
|
|
import { deepCopy } from 'src/app/services/deepCopy';
|
|
|
|
|
|
|
|
|
|
|
|
type CargoBikeDataRow = CargoBikeResult & {
|
|
|
|
type CargoBikeDataRow = CargoBikeResult & {
|
|
|
|
waitingForEditPermissions: boolean;
|
|
|
|
waitingForEditPermissions: boolean;
|
|
|
|
isGettingEdited: boolean;
|
|
|
|
isGettingEdited: boolean;
|
|
|
|
|
|
|
|
locked: boolean;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
@ -24,36 +25,42 @@ export class BikesComponent {
|
|
|
|
'buttons',
|
|
|
|
'buttons',
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
bikes = new MatTableDataSource(<Array<CargoBikeDataRow>>[]);
|
|
|
|
bikes = <Array<any>>[];
|
|
|
|
selection = new SelectionModel<CargoBikeDataRow>(true, []);
|
|
|
|
selection = new SelectionModel<CargoBikeDataRow>(true, []);
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
constructor(private bikesService: BikesService) {
|
|
|
|
private bikesService: BikesService,
|
|
|
|
|
|
|
|
private changeDetectorRefs: ChangeDetectorRef
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
bikesService.bikes.subscribe((bikes) => {
|
|
|
|
bikesService.bikes.subscribe((bikes) => {
|
|
|
|
this.bikes = new MatTableDataSource(
|
|
|
|
this.bikes = bikes.map((bike) => {
|
|
|
|
bikes.map((bike) => {
|
|
|
|
return <any>Object.assign({}, deepCopy(bike), {
|
|
|
|
return Object.assign({}, bike, {
|
|
|
|
|
|
|
|
waitingForEditPermissions: false,
|
|
|
|
waitingForEditPermissions: false,
|
|
|
|
isGettingEdited: false,
|
|
|
|
isGettingEdited: false,
|
|
|
|
|
|
|
|
locked: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
if (this.bikes.length > 6) {
|
|
|
|
|
|
|
|
this.bikes[5].locked = true;
|
|
|
|
|
|
|
|
this.bikes[2].locked = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
bikesService.loadBikes();
|
|
|
|
bikesService.loadBikes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
edit(row: CargoBikeDataRow) {
|
|
|
|
edit(row: CargoBikeDataRow) {
|
|
|
|
console.log('isGettingEdited: ' + row.isGettingEdited);
|
|
|
|
|
|
|
|
row.waitingForEditPermissions = true;
|
|
|
|
row.waitingForEditPermissions = true;
|
|
|
|
console.log('edit');
|
|
|
|
|
|
|
|
console.log(row.waitingForEditPermissions);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
row.waitingForEditPermissions = false;
|
|
|
|
row.waitingForEditPermissions = false;
|
|
|
|
row.isGettingEdited = true;
|
|
|
|
row.isGettingEdited = true;
|
|
|
|
console.log('gets edited');
|
|
|
|
}, 800);
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
save(row: CargoBikeDataRow) {
|
|
|
|
|
|
|
|
console.log(row);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cancel(row: CargoBikeDataRow) {
|
|
|
|
|
|
|
|
//fetch it again
|
|
|
|
|
|
|
|
//TODO: remove lock
|
|
|
|
|
|
|
|
this.bikesService.reloadBike({id: row.id});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drop(event: CdkDragDrop<string[]>) {
|
|
|
|
drop(event: CdkDragDrop<string[]>) {
|
|
|
@ -67,7 +74,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.data.length;
|
|
|
|
const numRows = this.bikes.length;
|
|
|
|
return numSelected === numRows;
|
|
|
|
return numSelected === numRows;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -75,6 +82,6 @@ export class BikesComponent {
|
|
|
|
masterToggle() {
|
|
|
|
masterToggle() {
|
|
|
|
this.isAllSelected()
|
|
|
|
this.isAllSelected()
|
|
|
|
? this.selection.clear()
|
|
|
|
? this.selection.clear()
|
|
|
|
: this.bikes.data.forEach((row) => this.selection.select(row));
|
|
|
|
: this.bikes.forEach((row) => this.selection.select(row));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|