Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for events from the filter panel #681

Merged
merged 12 commits into from
Jul 13, 2022
Merged
15 changes: 13 additions & 2 deletions R/module_tabs_with_filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ ui_tabs_with_filters <- function(id, modules, datasets) {
filter_panel_btn <- tags$li(
style = "flex-grow : 1;",
tags$a(
id = "filter_hamburger",
href = "javascript:void(0)",
class = "menubtn",
onclick = "toggle_sidebar();",
onclick = "handleHamburgerClick();",
Polkas marked this conversation as resolved.
Show resolved Hide resolved
title = "Toggle filter panels",
tags$span(icon("fas fa-bars"))
)
Expand Down Expand Up @@ -162,10 +163,20 @@ srv_tabs_with_filters <- function(id, datasets, modules, reporter = teal.reporte
"srv_tabs_with_filters@1 changing active module to: { deparse1(active_module()$label) }."
)
datasets$handle_active_datanames(datanames = active_module()$filters)
}
},
ignoreNULL = FALSE
)

datasets$srv_filter_panel(id = "filter_panel", active_datanames = active_datanames)
script <- paste0(
"document.getElementById('%s').addEventListener('noDatasetsEvent', handleNoActiveDatasets);",
"document.getElementById('%s').addEventListener('datasetsActiveEvent', handleActiveDatasetsPresent);"
)
shinyjs::runjs(sprintf(
script,
session$ns("filter_panel"),
session$ns("filter_panel")
))
Polkas marked this conversation as resolved.
Show resolved Hide resolved
teal.slice::set_filter_state(datasets = datasets, filter = filter)
showNotification("Data loaded - App fully started up")

Expand Down
6 changes: 6 additions & 0 deletions inst/css/sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
.nav {
display: flex;
}

a.disabled {
pointer-events: none;
cursor: default;
color: grey;
}
41 changes: 32 additions & 9 deletions inst/js/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
// used to collapse and expand the filter panel in teal apps
var filter_open = true;
function toggle_sidebar() {
if ($("#teal_secondary_col").css("display") == "none") {
$("#teal_primary_col").attr("class", "col-sm-9").resize();
$("#teal_secondary_col").delay(600).fadeIn(50);
filter_open = true;
} else {
$("#teal_secondary_col").fadeOut(1);
$("#teal_primary_col").attr("class", "col-sm-12").resize();
filter_open = false;
const hideSidebar = () => {
$("#teal_secondary_col").fadeOut(1);
$("#teal_primary_col").attr("class", "col-sm-12").resize();
};

const showSidebar = () => {
$("#teal_primary_col").attr("class", "col-sm-9").resize();
$("#teal_secondary_col").delay(600).fadeIn(50);
};

const handleHamburgerClick = () => {
console.log("Handling Filter Panel Hamburger click: " + filter_open);
Polkas marked this conversation as resolved.
Show resolved Hide resolved
if (
filter_open &&
getComputedStyle(document.getElementById("teal_secondary_col")).display ===
"none"
) {
showSidebar();
return;
}
filter_open = !filter_open;
if (filter_open) showSidebar();
else hideSidebar();
};

const handleNoActiveDatasets = () => {
$("#filter_hamburger").addClass("disabled");
hideSidebar();
};

const handleActiveDatasetsPresent = () => {
$("#filter_hamburger").removeClass("disabled");
if (filter_open) showSidebar();
}