From fdd148028e03219f16ec5d04dc8e87f4a8e1e03b Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Thu, 11 Jul 2019 12:26:09 +0200 Subject: [PATCH] Fix order of selected PAB items, for interpolation --- .../pab-table/pab-table.component.ts | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/app/components/pab-table/pab-table.component.ts b/src/app/components/pab-table/pab-table.component.ts index 954e6e39d..1001e6e7d 100644 --- a/src/app/components/pab-table/pab-table.component.ts +++ b/src/app/components/pab-table/pab-table.component.ts @@ -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() { -- GitLab