From 094439eb7364ae4dc69a772dba0a915617246aee Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Sun, 18 Feb 2024 17:11:48 +0100 Subject: [PATCH] dropdown menu, only refresh graphs on filter changes + don't close when clicking inside --- web/app.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/web/app.js b/web/app.js index e19b2b3..1983109 100644 --- a/web/app.js +++ b/web/app.js @@ -54,6 +54,12 @@ render_graphs_wrapper(); // filters checkboxes function filters_checkboxes() { fetch_list().then(function(data){ + { + const node = document.getElementById("filters_checkboxes"); + while (node.firstChild) { + node.removeChild(node.lastChild); + } + } const node = d3.select("#filters_checkboxes"); for (const itemlist of data) { var label = node.append("label"); @@ -69,14 +75,18 @@ function filters_checkboxes() { } filters_checkboxes() // listen to filters changes +var checkedBefore = getCheckedCheckboxIds('.checkbox-filters'); $(document).ready(function(){ - $('#filters').on('show.bs.dropdown', function () { - console.log("Opening dropdown"); - }); - $('#filters').on('hidden.bs.dropdown', function () { - // console.log("Dropdown hidden"); - refresh_graphs(); + const checkedAfter = getCheckedCheckboxIds('.checkbox-filters'); + if (!(checkedAfter.every(item => checkedBefore.includes(item)) && checkedBefore.every(item => checkedAfter.includes(item)))) { + refresh_graphs(); + } + checkedBefore = checkedAfter; + }); + // prevent dropdown menu from closing when clicking inside + $('#filters_checkboxes').on('click', function (e) { + e.stopPropagation(); }); });