From f7dbfb69021ce8486d8af5dc9b6ca5d40161e142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Mon, 20 Feb 2023 15:45:51 +0100 Subject: [PATCH] refactor: PAB: optimise table space by moving up values of the basin section (length, width, ZRMB) refs #607 --- .../pab-table/pab-table.component.ts | 131 +++++++----------- 1 file changed, 50 insertions(+), 81 deletions(-) diff --git a/src/app/components/pab-table/pab-table.component.ts b/src/app/components/pab-table/pab-table.component.ts index ead6072f1..8f1e259ff 100644 --- a/src/app/components/pab-table/pab-table.component.ts +++ b/src/app/components/pab-table/pab-table.component.ts @@ -540,58 +540,58 @@ 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 i = 0; i < maxNbParams; i++) { + for (let r = 0; r < maxNbParams; r++) { // build device params row const deviceParamRow = { selectable: cloison, cells: [] }; - // basin number and ZRAM - if (i === 0) { + // basin number, LB, BB, ZRMB and ZRAM + if (r === 0) { // basin number deviceParamRow.cells.push({ value: childIndex + 1, - rowspan: maxNbParams + 1, + rowspan: maxNbParams, class: "basin_number", selectable: cloison }); - // 3 empty cells - deviceParamRow.cells.push({ - colspan: 3, - rowspan: maxNbParams - 1, - selectable: cloison - }); - // ZRAM - deviceParamRow.cells.push({ - model: cloison.prms.ZRAM, - title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "ZRAM") - }); - } - // basin cells on the last but 1 row - if (i === maxNbParams - 1) { + // Longueur bassin deviceParamRow.cells.push({ model: cloison.prms.LB, title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "LB") }); + // Largeur bassin deviceParamRow.cells.push({ model: cloison.prms.BB, title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "BB") }); + // Cote radier mi bassin deviceParamRow.cells.push({ model: cloison.prms.ZRMB, title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "ZRMB") }); + // ZRAM + deviceParamRow.cells.push({ + model: cloison.prms.ZRAM, + title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "ZRAM") + }); } - // 1 empty cell below ZRAM - if (i === 1) { + else if (r === 1) { + // 1 row for QA editor + const qaParam = new NgParameter(cloison.prms.QA, this.pabTable.form); + qaParam.radioConfig = ParamRadioConfig.VAR; deviceParamRow.cells.push({ - rowspan: maxNbParams, - selectable: cloison + model: qaParam, + colspan: 4, + rowspan: maxNbParams - 1, + 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(i); + 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 (i === 0) { // 1st row + if (r === 0) { // 1st row deviceParamRow.cells.push({ model: ouvrage, modelValue: ouvrage.getPropValue("loiDebit"), @@ -600,75 +600,42 @@ export class PabTableComponent implements AfterViewInit, AfterViewChecked, OnIni }); } // fill space below device type selector - if (i === 1) { + else if (r === 1) { deviceParamRow.cells.push({ rowspan: (maxNbParams - 1), selectable: ouvrage }); } - // cell 2 : param name if (nvParam) { + // cell 2 : param name deviceParamRow.cells.push({ value: nvParam.symbol, title: nvParamTitle, selectable: ouvrage }); - } else { - deviceParamRow.cells.push({ - selectable: ouvrage - }); - } - // cell 3 : param value - if (nvParam) { + // cell 3 : param value deviceParamRow.cells.push({ model: nvParam, title: nvParamTitle, selectable: ouvrage }); - } else { - deviceParamRow.cells.push({ - selectable: ouvrage - }); } - } - // fill horizontal space - const devDiff = (maxNbDevices - cloison.structures.length); - if (i === 0) { - for (let j = 0; j < devDiff; j++) { - deviceParamRow.cells.push({ - colspan: 3, - rowspan: maxNbParams, - selectable: cloison, - selectableColumn: cloison.structures.length + j - }); + 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); } - // 1 row for QA editor - const qaParam = new NgParameter(cloison.prms.QA, this.pabTable.form); - qaParam.radioConfig = ParamRadioConfig.VAR; - const qaRow: { selectable: any, cells: any[] } = { - selectable: undefined, - cells: [ - { - model: qaParam, - colspan: 3, - qa: true, - title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "QA") - } - ] - }; - // as many pairs of columns as the maximum number of devices - qaRow.cells.push({ - colspan: maxNbDevices * 3, - // selectable: cloison @TODO oui ou non ? - }); - // done ! - this.rows.push(qaRow); - - childIndex ++; + childIndex++; } // B.2 many rows for downwall @@ -790,18 +757,20 @@ export class PabTableComponent implements AfterViewInit, AfterViewChecked, OnIni return maxNbDevices; } + private nubVisibleParameterCount(n: Nub) { + let res = 0; + for (const p of n.parameterIterator) { + if (p.visible) { + res++; + } + } + return res; + } + private findMaxNumberOfDeviceParameters(struct: ParallelStructure): number { let maxNbParams = 1; - for (const d of struct.getChildren()) { - let nbParams = 0; - for (const p of d.parameterIterator) { - if (p.visible) { - // console.log("(counting)", p.symbol); - nbParams ++; - } - } - // console.log(">>> child params: ", nbParams); - maxNbParams = Math.max(maxNbParams, nbParams); + for (const child of struct.getChildren()) { + maxNbParams = Math.max(maxNbParams, this.nubVisibleParameterCount(child)); } return maxNbParams; } -- GitLab