adding/removing rows

pull/6834/head
Jens Ulferts 6 years ago
parent 28fbc62fec
commit 8d4bf0fef2
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 7
      frontend/src/app/modules/grids/context_menus/row.directive.ts
  2. 41
      frontend/src/app/modules/grids/grid.component.ts

@ -82,27 +82,28 @@ export class GridRowContextMenu extends OpContextMenuTrigger {
private buildItems() {
let grid = this.grid;
let rowNumber = this.rowNumber;
// TODO: I18n
this.items = [
{
linkText: "Add row before",
onClick: () => {
//this.wpTableSortBy.addDescending(c);
grid.addRow(rowNumber - 1);
return true;
}
},
{
linkText: "Add row after",
onClick: () => {
//this.wpTableSortBy.addAscending(c);
grid.addRow(rowNumber);
return true;
}
},
{
linkText: "Remove row",
onClick: () => {
//this.wpTableGroupBy.setBy(c);
grid.removeRow(rowNumber);
return true;
}
}

@ -265,6 +265,19 @@ export class GridComponent implements OnDestroy, OnInit {
this.buildAreas();
}
public addRow(row:number) {
this.numRows++;
this.widgetResources.filter((widget) => {
return widget.startRow > row;
}).forEach((widget) => {
widget.startRow++;
widget.endRow++;
});
this.buildAreas();
}
public removeColumn(column:number) {
this.numColumns--;
@ -293,6 +306,34 @@ export class GridComponent implements OnDestroy, OnInit {
this.buildAreas();
}
public removeRow(row:number) {
this.numRows--;
// remove widgets that only span the removed row
this.widgetResources = this.widgetResources.filter((widget) => {
return !(widget.startRow === row && widget.endRow === row + 1);
});
//shrink widgets that span more than the removed row
this.widgetResources.forEach((widget) => {
if (widget.startRow <= row && widget.endRow >= row + 1) {
//shrink widgets that span more than the removed row
widget.endRow--;
}
});
// move all widgets that are after the removed row
// so that they appear to keep their place.
this.widgetResources.filter((widget) => {
return widget.startRow > row;
}).forEach((widget) => {
widget.startRow--;
widget.endRow--;
});
this.buildAreas();
}
private buildAreas() {
this.gridAreas = this.buildGridAreas();
this.gridAreaDropIds = this.buildGridAreaDropIds();

Loading…
Cancel
Save