Fix table editing bug

pull/4/head
Max 4 years ago
parent 62dcc610a1
commit 044e9634e2

@ -23,10 +23,6 @@ export class CellComponent {
this.inputType = 'number'; this.inputType = 'number';
} else if (this.inputType === 'ID' || this.inputType === 'String') { } else if (this.inputType === 'ID' || this.inputType === 'String') {
this.inputType = 'text'; this.inputType = 'text';
} else if (this.inputType === 'Boolean') {
} else {
console.log(this.inputType);
} }
} }

@ -114,10 +114,20 @@ export class BikesComponent {
bikesService.bikes.subscribe((newTableDataSource) => { bikesService.bikes.subscribe((newTableDataSource) => {
this.reloadingTable = false; this.reloadingTable = false;
this.data = []; const tempDataSource = [];
for (const row of newTableDataSource) { for (const row of newTableDataSource) {
this.data.push(flatten(row)); const oldRow = this.getRowById(row.id);
/** make sure to not overwrite a row that is being edited */
if (!oldRow) {
tempDataSource.push(flatten(row));
} }
else if (!(oldRow.isLockedByMe && row.isLockedByMe)) {
tempDataSource.push(flatten(row));
} else if (!!oldRow) {
tempDataSource.push(oldRow);
}
}
this.data = tempDataSource;
}); });
bikesService.loadBikes(); bikesService.loadBikes();
} }
@ -191,6 +201,10 @@ export class BikesComponent {
this.bikesService.unlockBike({ id: row.id }); this.bikesService.unlockBike({ id: row.id });
} }
getRowById(id: string) {
return this.data.find(row => row.id === id);
}
drop(event: CdkDragDrop<string[]>) { drop(event: CdkDragDrop<string[]>) {
moveItemInArray( moveItemInArray(
this.displayedColumns, this.displayedColumns,

Loading…
Cancel
Save