From 925304e90c09d465643a3168c89148663ad45a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Tue, 21 Feb 2023 14:44:38 +0100 Subject: [PATCH] refactor: PAB: table data: move type over parameter name and value refs #607 --- .../pab-table/pab-table.component.ts | 169 ++++++------------ 1 file changed, 59 insertions(+), 110 deletions(-) diff --git a/src/app/components/pab-table/pab-table.component.ts b/src/app/components/pab-table/pab-table.component.ts index db19cdb9d..c07ae0282 100644 --- a/src/app/components/pab-table/pab-table.component.ts +++ b/src/app/components/pab-table/pab-table.component.ts @@ -84,7 +84,6 @@ export class PabTableComponent implements AfterViewInit, AfterViewChecked, OnIni private i18nService: I18nService, private formService: FormulaireService, private editPabDialog: MatDialog, - private appSetupService: ApplicationSetupService, private notifService: NotificationsService ) { this.selectedItems = []; @@ -552,7 +551,7 @@ export class PabTableComponent implements AfterViewInit, AfterViewChecked, OnIni for (const cloison of this.model.children) { // as much rows as the greatest number of parameters among its devices const maxNbParams = this.findMaxNumberOfDeviceParameters(cloison); - for (let r = 0; r < maxNbParams; r++) { + for (let r = 0; r <= maxNbParams; r++) { // build device params row const deviceParamRow = { selectable: cloison, cells: [] }; // basin number, LB, BB, ZRMB and ZRAM @@ -560,7 +559,7 @@ export class PabTableComponent implements AfterViewInit, AfterViewChecked, OnIni // basin number deviceParamRow.cells.push({ value: childIndex + 1, - rowspan: maxNbParams, + rowspan: maxNbParams + 1, class: "basin_number", selectable: cloison }); @@ -592,60 +591,14 @@ export class PabTableComponent implements AfterViewInit, AfterViewChecked, OnIni deviceParamRow.cells.push({ model: qaParam, colspan: 4, - rowspan: maxNbParams - 1, + rowspan: maxNbParams, qa: true, title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "QA") }); } - // device param cells : 3 cells for each device - for (const ouvrage of cloison.structures) { - const nvParam = ouvrage.getNthVisibleParam(r); - const nvParamTitle = nvParam ? this.formService.expandVariableNameAndUnit(CalculatorType.Pab, nvParam.symbol) : ""; - const childStructParamCount = this.nubVisibleParameterCount(ouvrage); - // cell 1 : device type - if (r === 0) { // 1st row - deviceParamRow.cells.push({ - model: ouvrage, - modelValue: ouvrage.getPropValue("loiDebit"), - options: loisCloisons, - selectable: ouvrage - }); - } - // fill space below device type selector - else if (r === 1) { - deviceParamRow.cells.push({ - rowspan: (maxNbParams - 1), - selectable: ouvrage - }); - } - if (nvParam) { - // cell 2 : param name - deviceParamRow.cells.push({ - value: nvParam.symbol, - title: nvParamTitle, - selectable: ouvrage - }); - // cell 3 : param value - deviceParamRow.cells.push({ - model: nvParam, - title: nvParamTitle, - selectable: ouvrage - }); - } - else if (r === childStructParamCount) { - // fill remaining space - const remaining = maxNbParams - childStructParamCount; - if (remaining > 0) { - deviceParamRow.cells.push({ - colspan: 2, - rowspan: remaining, - selectable: cloison - }); - } - } - } - // done ! - this.rows.push(deviceParamRow); + + // devices + this.fillParallelStructureCells(deviceParamRow, r, maxNbParams, loisCloisons); } childIndex++; } @@ -660,21 +613,21 @@ export class PabTableComponent implements AfterViewInit, AfterViewChecked, OnIni }); // 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++) { + for (let r = 0; r <= maxNbParamsDW; r++) { // build device params row const deviceParamRowDW = { selectable: this.model.downWall, cells: [] }; - // basin number - if (i === 0) { + if (r === 0) { + // "downstream" deviceParamRowDW.cells.push({ value: "Aval", - rowspan: maxNbParamsDW, + rowspan: maxNbParamsDW + 1, class: "basin_number", selectable: this.model.downWall }); // 3 empty cells deviceParamRowDW.cells.push({ colspan: 3, - rowspan: maxNbParamsDW , + rowspan: maxNbParamsDW + 1, selectable: this.model.downWall }); // ZRAM @@ -683,74 +636,70 @@ export class PabTableComponent implements AfterViewInit, AfterViewChecked, OnIni title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "ZRAM") }); } - if (i === 1) { - // 1 empty cell + if (r === 1) { + // 1 empty cell (in place of the QA editor) deviceParamRowDW.cells.push({ - rowspan: maxNbParamsDW - 1, + rowspan: maxNbParamsDW, selectable: this.model.downWall }); } - // downwall device param cells : 3 cells for each device - for (const ouvrage of this.model.downWall.structures) { - const nvParam = ouvrage.getNthVisibleParam(i); - const nvParamTitle = nvParam ? this.formService.expandVariableNameAndUnit(CalculatorType.Pab, nvParam.symbol) : ""; - // cell 1 : device type - if (i === 0) { // 1st row - deviceParamRowDW.cells.push({ - model: ouvrage, - modelValue: ouvrage.getPropValue("loiDebit"), - options: loisAval - }); - } - // fill space - if (i === 1) { - deviceParamRowDW.cells.push({ - rowspan: (maxNbParamsDW - 1), - selectable: ouvrage + + // devices + this.fillParallelStructureCells(deviceParamRowDW, r, maxNbParamsDW, loisAval); + } + + this.updateValidity(); + } + + private fillParallelStructureCells(tableRow: any, rowIndex: number, maxParamCount: number, loisAdmissibles: any[]) { + // device param cells : 3 cells for each device + + const ps: ParallelStructure = tableRow.selectable; + + for (const struct of ps.structures) { + const childStructParamCount = this.nubVisibleParameterCount(struct); + // cell 1 : device type + if (rowIndex === 0) { // 1st row + tableRow.cells.push({ + model: struct, + modelValue: struct.getPropValue("loiDebit"), + options: loisAdmissibles, + selectable: struct, + colspan: 2 + }); + } + else if (rowIndex === childStructParamCount + 1) { + // fill remaining space + const remaining = maxParamCount - childStructParamCount; + if (remaining > 0) { + tableRow.cells.push({ + colspan: 2, + rowspan: remaining, + selectable: ps }); } - // cell 2 : param name + } + else { + const nvParam = struct.getNthVisibleParam(rowIndex - 1); if (nvParam) { - deviceParamRowDW.cells.push({ + const nvParamTitle = this.formService.expandVariableNameAndUnit(CalculatorType.Pab, nvParam.symbol); + // cell 2 : param name + tableRow.cells.push({ value: nvParam.symbol, title: nvParamTitle, - selectable: ouvrage - }); - } else { - deviceParamRowDW.cells.push({ - selectable: ouvrage + selectable: struct }); - } - // cell 3 : param value - if (nvParam) { - deviceParamRowDW.cells.push({ + // cell 3 : param value + tableRow.cells.push({ model: nvParam, title: nvParamTitle, - selectable: ouvrage - }); - } else { - deviceParamRowDW.cells.push({ - selectable: ouvrage + selectable: struct }); } } - // fill horizontal space - const devDiff = (maxNbDevices - this.model.downWall.structures.length); - if (i === 0) { - for (let j = 0; j < devDiff; j++) { - deviceParamRowDW.cells.push({ - colspan: 3, - rowspan: maxNbParamsDW, - selectable: this.model.downWall, - selectableColumn: this.model.downWall.structures.length + j - }); - } - } - // done ! - this.rows.push(deviceParamRowDW); } - - this.updateValidity(); + // done ! + this.rows.push(tableRow); } /** -- GitLab