Commit fdd14802 authored by Mathias Chouet's avatar Mathias Chouet :spaghetti:
Browse files

Fix order of selected PAB items, for interpolation

Showing with 38 additions and 1 deletion
+38 -1
......@@ -270,6 +270,7 @@ export class PabTableComponent implements AfterViewInit, OnInit {
} else {
this.selectedItems.push(cell.selectable);
}
this.sortSelectedItems();
}
} else { // just a click
......@@ -321,6 +322,36 @@ export class PabTableComponent implements AfterViewInit, OnInit {
this.refresh();
}
/**
* Ensures that this.selectedItems elements are ordered according to
* the walls order in the PAB (important for interpolation)
*/
private sortSelectedItems() {
// extract PAB walls order
const wallsUIDs: string[] = [];
for (const c of this.pabTable.pab.children) {
wallsUIDs.push(c.uid);
}
wallsUIDs.push(this.pabTable.pab.downWall.uid);
// are items walls or devices ?
if (this.onlyWallsAreSelected(false)) {
// 1. walls : order by uid, according to model
this.selectedItems.sort((a, b) => {
const posA = wallsUIDs.indexOf(a.uid);
const posB = wallsUIDs.indexOf(b.uid);
return posA - posB;
});
} else {
// 2. devices : order by parent (wall) uid, according to model
this.selectedItems.sort((a, b) => {
const posA = wallsUIDs.indexOf(a.parent.uid);
const posB = wallsUIDs.indexOf(b.parent.uid);
return posA - posB;
});
}
return this.selectedItems;
}
/**
* Builds the editable data grid from the Pab model
*/
......@@ -741,7 +772,13 @@ export class PabTableComponent implements AfterViewInit, OnInit {
* returns true if at least one object is selected
*/
public get enableEditPabButton() {
return this.selectedItems.length > 0;
return (
this.selectedItems.length > 0
&& (
this.onlyDevicesAreSelected()
|| this.onlyWallsAreSelected(false)
)
);
}
public onAddClick() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment