From b596a3820cddc8bc74f2bd3c8aed632f515d24c3 Mon Sep 17 00:00:00 2001 From: lehmann Date: Fri, 22 Apr 2022 14:15:32 +0200 Subject: [PATCH] =?UTF-8?q?Sommes=20des=20coef=20+=20am=C3=A9lioration=20?= =?UTF-8?q?=C3=A9diteur=20coef?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/css/table_editor.css | 3 ++ app/static/js/table_editor.js | 75 ++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/app/static/css/table_editor.css b/app/static/css/table_editor.css index e3192d882..25d192c55 100644 --- a/app/static/css/table_editor.css +++ b/app/static/css/table_editor.css @@ -52,6 +52,9 @@ div.title_STANDARD, .champs_STANDARD { div.title_MALUS { background-color: #ff4700; } +.sums { + background: #ddd; +} /***************************/ /* Statut des cellules */ /***************************/ diff --git a/app/static/js/table_editor.js b/app/static/js/table_editor.js index 2af700a41..a4e8d27a7 100644 --- a/app/static/js/table_editor.js +++ b/app/static/js/table_editor.js @@ -4,8 +4,13 @@ /*****************************/ /* Mise en place des données */ /*****************************/ +let lastX; +let lastY; + function build_table(data) { let output = ""; + let sumsUE = {}; + let sumsRessources = {}; data.forEach((cellule) => { output += ` @@ -29,11 +34,61 @@ function build_table(data) { "> ${cellule.data} `; + + if (cellule.editable && cellule.data) { + sumsRessources[cellule.y] = (sumsRessources[cellule.y] ?? 0) + parseInt(cellule.data); + sumsUE[cellule.x] = (sumsUE[cellule.x] ?? 0) + parseInt(cellule.data); + } }) + + output += showSums(sumsRessources, sumsUE); document.querySelector(".tableau").innerHTML = output; installListeners(); } +function showSums(sumsRessources, sumsUE) { + lastX = Object.keys(sumsUE).length + 2; + lastY = Object.keys(sumsRessources).length + 2; + + let output = ""; + + Object.entries(sumsUE).forEach(([num, value]) => { + output += ` +
+ ${value} +
`; + }) + + Object.entries(sumsRessources).forEach(([num, value]) => { + output += ` +
+ ${value} +
`; + }) + + return output; +} + /*****************************/ /* Gestion des évènements */ /*****************************/ @@ -54,6 +109,7 @@ function installListeners() { } } }); + cellule.addEventListener("input", processSums); }); } @@ -120,11 +176,28 @@ function keyCell(event) { return } this.classList.remove("modifying"); + let selected = document.querySelector(".selected"); ArrowMove(0, 1); - modifCell(document.querySelector(".selected")); + if(selected != document.querySelector(".selected")){ + modifCell(document.querySelector(".selected")); + } } } +function processSums() { + let sum = 0; + document.querySelectorAll(`[data-editable="true"][data-x="${this.dataset.x}"]`).forEach(e => { + sum += parseInt(e.innerText) || 0; + }) + document.querySelector(`.sums[data-x="${this.dataset.x}"][data-y="${lastY}"]`).innerText = sum; + + sum = 0; + document.querySelectorAll(`[data-editable="true"][data-y="${this.dataset.y}"]`).forEach(e => { + sum += parseInt(e.innerText) || 0; + }) + document.querySelector(`.sums[data-x="${lastX}"][data-y="${this.dataset.y}"]`).innerText = sum; +} + /******************************/ /* Affichage d'un message */ /******************************/