From cf8992ebced4af95b6d2cca943f1156c48b488c6 Mon Sep 17 00:00:00 2001 From: Jean-Marie Place Date: Wed, 22 Feb 2023 15:05:54 +0100 Subject: [PATCH] proposition ihm groupe+rang --- app/static/js/table_recap.js | 108 ++++++++++++++++++++++++++++++++--- 1 file changed, 99 insertions(+), 9 deletions(-) diff --git a/app/static/js/table_recap.js b/app/static/js/table_recap.js index 56d43e3d9..360ddf459 100644 --- a/app/static/js/table_recap.js +++ b/app/static/js/table_recap.js @@ -27,6 +27,64 @@ $(function () { } } + const GROUP_RANK_NONE = 0; + const GROUP_RANK_GROUP_ONLY = 1; + const GROUP_RANK_ALL =2; + + function button_on(but) { + but.classList.add("but_on"); + but.classList.remove("but_off") + } + function button_off(but) { + but.classList.add("but_off"); + but.classList.remove("but_on") + } + function update_buttons_group_rank(dt, status, group, but) { + console.log(" >>>> " + status + " => " + group); + if (status == GROUP_RANK_NONE) { + console.log("off"); + button_off(but); + } else if (status == GROUP_RANK_ALL) { + console.log("on"); + button_on(but); + } else { // GROUP_RANK_GROUP_ONLY + if (group == "partition_aux") { + console.log("on"); + button_on(but); + } else { + console.log("off"); + button_off(but); + } + } + } + function test_group_rank_visibility(dt) { + if (! dt.columns(".partition_aux").visible()[0]) { + return GROUP_RANK_NONE; + } + if (dt.columns(".partition_rangs").visible()[0]) { + return GROUP_RANK_ALL + } + return GROUP_RANK_GROUP_ONLY; + } + function set_group_rank_visibility(dt, status) { + let group_but = document.querySelector("button.dt-button.partition_aux"); + let rang_but = document.querySelector("button.dt-button.partition_rangs"); + switch (status) { + case GROUP_RANK_ALL: + dt.columns('.partition_aux').visible(true); + dt.columns('.partition_rangs').visible(true); + break; + case GROUP_RANK_GROUP_ONLY: + dt.columns('.partition_aux').visible(true); + dt.columns('.partition_rangs').visible(false); + break; + case GROUP_RANK_NONE: + dt.columns('.partition_aux').visible(false); + dt.columns('.partition_rangs').visible(false); + break; + } + } + // Les colonnes visibles sont mémorisées, il faut initialiser l'état des boutons function update_buttons_labels(dt) { // chaque bouton controle une classe stockée dans le data-group du span @@ -35,13 +93,15 @@ $(function () { if (g_span) { let group = g_span.dataset["group"]; if (group) { - // si le group (= la 1ere col.) est visible, but_on - if (dt.columns("." + group).visible()[0]) { - but.classList.add("but_on"); - but.classList.remove("but_off"); + if ((group == "partition_aux") || (group == "partition_rangs")) { + status = test_group_rank_visibility(dt); + console.log("update: " + group + "(" + status + ")"); + update_buttons_group_rank(dt, status, group, but); + // group hors partition/rang => si le group (= la 1ere col.) est visible, but_on + } else if (dt.columns("." + group).visible()[0]) { + button_on(but); } else { - but.classList.add("but_off"); - but.classList.remove("but_on"); + button_off(but); } } } @@ -72,6 +132,36 @@ $(function () { } update_buttons_labels(dt); } + function toggle_col_partition_group_visibility(e, dt, node, config) { + let status = test_group_rank_visibility(dt); + switch (status) { + case GROUP_RANK_NONE: + set_group_rank_visibility(dt, GROUP_RANK_GROUP_ONLY); + break; + case GROUP_RANK_ALL: + set_group_rank_visibility(dt, GROUP_RANK_GROUP_ONLY) + break; + case GROUP_RANK_GROUP_ONLY: + set_group_rank_visibility(dt, GROUP_RANK_NONE); + break; + } + update_buttons_labels(dt); + } + function toggle_col_partition_rank_visibility(e, dt, node, config) { + let status = test_group_rank_visibility(dt); + switch (status) { + case GROUP_RANK_NONE: + set_group_rank_visibility(dt, GROUP_RANK_ALL); + break; + case GROUP_RANK_ALL: + set_group_rank_visibility(dt, GROUP_RANK_NONE) + break; + case GROUP_RANK_GROUP_ONLY: + set_group_rank_visibility(dt, GROUP_RANK_ALL); + break; + } + update_buttons_labels(dt); + } // Definition des boutons au dessus de la table: let buttons = [ { @@ -107,11 +197,11 @@ $(function () { }, { text: 'Groupes', - action: toggle_col_but_visibility, + action: toggle_col_partition_group_visibility, }, { - text: 'Rg', - action: toggle_col_but_visibility, + text: 'Groupes et Rg', + action: toggle_col_partition_rank_visibility, }, ]; // fin des boutons communs à toutes les tables recap