From cf9c88b7e306b7f8d15b073829e58adfaecd42f7 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Wed, 12 Jun 2019 16:03:45 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9placement=20/=20suppression=20de=20clois?= =?UTF-8?q?on=20/=20ouvrage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/calculators/pab/pab.en.json | 1 + src/app/calculators/pab/pab.fr.json | 1 + .../dialog-edit-pab.component.ts | 4 +- .../pab-table/pab-table.component.ts | 84 ++++++++++++------- 4 files changed, 57 insertions(+), 33 deletions(-) diff --git a/src/app/calculators/pab/pab.en.json b/src/app/calculators/pab/pab.en.json index 01b163816..54434a65a 100644 --- a/src/app/calculators/pab/pab.en.json +++ b/src/app/calculators/pab/pab.en.json @@ -9,6 +9,7 @@ "W": "Gate opening", "ZRAM": "Bottom elevation", "ZRMB": "Mid-basin elevation", + "h1": "Head", "fs_bassin": "Basin", "fs_cloison_aval": "Downstream wall", "bassin_container": "Basins", diff --git a/src/app/calculators/pab/pab.fr.json b/src/app/calculators/pab/pab.fr.json index 3d48ab993..f0b6ba086 100644 --- a/src/app/calculators/pab/pab.fr.json +++ b/src/app/calculators/pab/pab.fr.json @@ -9,6 +9,7 @@ "W": "Ouverture de vanne", "ZRAM": "Cote de radier amont", "ZRMB": "Cote de radier mi-bassin", + "h1": "Charge", "fs_bassin": "Bassin", "fs_cloison_aval": "Cloison aval", "bassin_container": "Bassins", diff --git a/src/app/components/dialog-edit-pab/dialog-edit-pab.component.ts b/src/app/components/dialog-edit-pab/dialog-edit-pab.component.ts index a2e4c57ae..0be09d40f 100644 --- a/src/app/components/dialog-edit-pab/dialog-edit-pab.component.ts +++ b/src/app/components/dialog-edit-pab/dialog-edit-pab.component.ts @@ -81,8 +81,8 @@ export class DialogEditPabComponent { this.dialogRef.close({ action: this.varAction, variable: this.variable, - value: this.valueToSet, - delta: this.delta, + value: Number(this.valueToSet), + delta: Number(this.delta), variableDetails: this.findVariableDetails(this.variable) }); } diff --git a/src/app/components/pab-table/pab-table.component.ts b/src/app/components/pab-table/pab-table.component.ts index f2949db1f..48d108657 100644 --- a/src/app/components/pab-table/pab-table.component.ts +++ b/src/app/components/pab-table/pab-table.component.ts @@ -127,6 +127,7 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { return undefined; } + /** returns true if the cell / row has a selectable item */ public isSelectable(cellOrRow: any): boolean { return ( @@ -253,6 +254,14 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { } } + // quick getter for 1st selected item + public get selectedItem() { + if (this.selectedItems.length === 0) { + throw new Error("get selectedItem() : no item selected"); + } + return this.selectedItems[0]; + } + // prevents Firefox to display weird cell border when ctrl+clicking public preventCtrlClickBorder($event) { if ($event.ctrlKey) { @@ -367,13 +376,13 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { // ------------- FIN TEST -------------------- - this.buildTable(); + this.refresh(); } /** * Builds the editable data grid from the Pab model */ - private buildTable() { + private refresh() { const maxNbDevices = this.findMaxNumberOfDevices(); // 0. build spanned headers over real columns @@ -671,7 +680,7 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { public get selectionIsOneDevice() { return ( this.selectedItems.length === 1 - && this.selectedItems[0] instanceof Structure + && this.selectedItem instanceof Structure ); } @@ -694,12 +703,16 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { * Returns true if there is at least one selected item, * and all selected items are walls */ - private onlyWallsAreSelected() { + private onlyWallsAreSelected(excludeDownwall: boolean = true) { let ok = false; if (this.selectedItems.length > 0) { ok = true; for (const s of this.selectedItems) { - ok = ok && (s instanceof ParallelStructure); + if (excludeDownwall) { + ok = ok && (s instanceof Cloisons); + } else { + ok = ok && (s instanceof ParallelStructure); + } } } return ok; @@ -719,46 +732,54 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { } public get enableAddButton() { - return this.selectedItems.length === 1; + return ( + this.selectedItems.length === 1 + && this.selectedItem.parent // exclude downwall + ); } public get enableCopyButton() { - return this.selectedItems.length === 1; + return ( + this.selectedItems.length === 1 + && this.selectedItem.parent // exclude downwall + ); } public get enableUpButton() { - return this.selectedItems.length === 1; + return ( + this.selectedItems.length === 1 + && this.selectedItem.parent + && this.selectedItem.findPositionInParent() !== 0 + ); } public get enableDownButton() { - return this.selectedItems.length === 1; + return ( + this.selectedItems.length === 1 + && this.selectedItem.parent + && this.selectedItem.findPositionInParent() < (this.selectedItem.parent.getChildren().length - 1) + ); } public get enableRemoveButton() { - return this.selectedItems.length === 1; - // return this.selectedItems.length > 0; // too dangerous ? or @TODO ask confirmation ? + return ( + this.selectedItems.length === 1 + && this.selectedItem.parent + && this.selectedItem.parent.getChildren().length > 1 + ); } /** - * returns true if "many" objects are selected: either more than one object, - * or a wall that contains more than one device + * returns true if at least one object is selected */ public get enableEditPabButton() { - return ( - this.selectedItems.length > 0 - - // too restrictive ? - /* this.selectedItems.length > 1 - || ( - this.selectedItems.length > 0 - && this.selectedItems[0] instanceof ParallelStructure - && this.selectedItems[0].getChildren().length > 1 - ) */ - ); + return this.selectedItems.length > 0; } public onAddClick() { console.log("Add !!!"); + /* const newChild = undefined; + this.selectedItem.parent.addChild(newChild, this.selectedItem.findPositionInParent()); */ } public onCopyClick() { @@ -766,15 +787,18 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { } public onMoveUpClick() { - console.log("Move up !!!"); + this.selectedItem.parent.moveChildUp(this.selectedItem); + this.refresh(); } public onMoveDownClick() { - console.log("Move down !!!"); + this.selectedItem.parent.moveChildDown(this.selectedItem); + this.refresh(); } public onRemoveClick() { - console.log("Remove !!!"); + this.selectedItem.parent.deleteChild(this.selectedItem.findPositionInParent()); + this.refresh(); } // show modal dialog for values edition @@ -868,8 +892,8 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { // apply modifications dialogRef.afterClosed().subscribe(result => { if (result) { - console.log("Apply values in parent !!", result.action, result.variable, result.value, - result.delta, result.variableDetails); + /* console.log("Apply values in parent !!", result.action, result.variable, result.value, + result.delta, result.variableDetails); */ switch (result.action) { case "set-value": for (const s of this.selectedItems) { @@ -900,7 +924,6 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { (result.variableDetails.last - result.variableDetails.first) / (result.variableDetails.occurrences - 1) ); - console.log(">>>> step", step); interpolatedValues.push(result.variableDetails.first); let currentValue: number = result.variableDetails.first; for (let i = 0; i < result.variableDetails.occurrences - 2; i++) { @@ -908,7 +931,6 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { interpolatedValues.push(Number(currentValue.toFixed(nDigits))); } interpolatedValues.push(result.variableDetails.last); - console.log(">>>> interp. values", interpolatedValues); // apply let idx = 0; for (const s of this.selectedItems) { -- GitLab