From b087a84bf0f0f4df476aec8728c3ba8ade397e14 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Thu, 13 Jun 2019 12:28:25 +0200 Subject: [PATCH] Pab: changement de type d'ouvrages --- .../pab-table/pab-table.component.html | 11 +++-- .../pab-table/pab-table.component.ts | 45 ++++++++++++++++--- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/app/components/pab-table/pab-table.component.html b/src/app/components/pab-table/pab-table.component.html index f1e7c5dda..4ad104839 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 9feccf6df..c70b83a2b 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) { -- GitLab