diff --git a/src/app/calculators/pab/pab.en.json b/src/app/calculators/pab/pab.en.json index 01b16381672c1d415f23ca6ada7d5d74f7f53aa8..54434a65a41503cb9fa66f6f0f3a7badf8f6fa93 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 3d48ab99334a798a8905e518178421dc06a26855..f0b6ba0864fef7ed70d8273c30d5377977fc6fa4 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 a2e4c57ae7a3f94bfaba0939bbbdcfdc5b5195f8..0be09d40f61e6926ad12ec3364a4d218c50c6554 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 f2949db1f7ad9ac294b9c4b4fb185b3dcae1ff9e..48d1086577a5a1b8ad8e89294e7a71ab0e714fe6 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) {