diff --git a/src/app/components/pab-table/pab-table.component.html b/src/app/components/pab-table/pab-table.component.html index f1e7c5dda49e929f69bbd59e02f98fc48c00496a..4ad10483919ea8a5be0f82b6567ec1995cce2358 100644 --- a/src/app/components/pab-table/pab-table.component.html +++ b/src/app/components/pab-table/pab-table.component.html @@ -80,12 +80,11 @@ <input matInput *ngIf="isNumberInput(cell)" type="number" [(ngModel)]="cell.model.singleValue"> - <mat-select *ngIf="isSelect(cell)" [(value)]="cell.model"> - <!-- <mat-option *ngFor="let opt of cell.options | keyvalue" [value]="l.key"> - {{ l.value }} - </mat-option> --> - <mat-option *ngFor="let opt of cell.options" [value]="opt"> - {{ opt }} + <mat-select *ngIf="isSelect(cell)" [value]="cell.modelValue" + (selectionChange)="loiDebitSelected($event, cell)"> + + <mat-option *ngFor="let opt of cell.options" [value]="opt.value"> + {{ opt.label }} </mat-option> </mat-select> diff --git a/src/app/components/pab-table/pab-table.component.ts b/src/app/components/pab-table/pab-table.component.ts index 9feccf6df2811677873ef249487213e3bd325be9..c70b83a2b7da7e5a26dc5e42c61f544a476fea4e 100644 --- a/src/app/components/pab-table/pab-table.component.ts +++ b/src/app/components/pab-table/pab-table.component.ts @@ -10,7 +10,8 @@ import { Cloisons, Nub, Structure, - ParallelStructure + ParallelStructure, + LoiDebit } from "jalhyd"; import { sprintf } from "sprintf-js"; @@ -377,6 +378,13 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { // B.1 many rows for each wall let childIndex = 0; for (const cloison of this.model.children) { + // admissible LoiDebit + const loisCloisons = cloison.getLoisAdmissiblesArray().map(l => { // @TODO move up ? (same for all cloisons) + return { + label: LoiDebit[l], + value: l + }; + }); // as much rows as the greatest number of parameters among its devices const maxNbParams = this.findMaxNumberOfDeviceParameters(cloison); // console.log(">>> max nb params: ", maxNbParams); @@ -406,9 +414,9 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { // cell 1 : device type if (i === 0) { // 1st row deviceParamRow.cells.push({ - model: ouvrage.properties.getPropValue("loiDebit"), - // options: StructureProperties.findCompatibleLoiDebit(ouvrage) - options: [ "salut", "coucou", "pouet" ], + model: ouvrage, + modelValue: ouvrage.properties.getPropValue("loiDebit"), + options: loisCloisons, selectable: ouvrage }); } @@ -491,6 +499,13 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { } // B.2 many rows for downwall + // admissible LoiDebit + const loisAval = this.model.downWall.getLoisAdmissiblesArray().map(l => { + return { + label: LoiDebit[l], + value: l + }; + }); // as much rows as the greatest number of parameters among its devices const maxNbParamsDW = this.findMaxNumberOfDeviceParameters(this.model.downWall); for (let i = 0; i < maxNbParamsDW; i++) { @@ -519,9 +534,9 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { // cell 1 : device type if (i === 0) { // 1st row deviceParamRowDW.cells.push({ - model: ouvrage.properties.getPropValue("loiDebit"), - // options: StructureProperties.findCompatibleLoiDebit(ouvrage) - options: [ "salut", "coucou", "pouet" ] + model: ouvrage, + modelValue: ouvrage.properties.getPropValue("loiDebit"), + options: loisAval }); } // fill space @@ -841,6 +856,22 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit { this.refresh(); } + /** Replace device Nub when LoiDebit is changed */ + public loiDebitSelected($event: any, cell: any) { + const device = cell.model as Nub; + const pos = device.findPositionInParent(); + // create new child device + const newDevice = Session.getInstance().createNub( + new Props({ + calcType: CalculatorType.Structure, + loiDebit: $event.value + }) + ); + // replace the current one + device.parent.replaceChildInplace(device, newDevice); + this.refresh(); + } + // show modal dialog for values edition public showEditPab() { if (this.selectedItems.length > 0) {