From 34bcc163d56706c70de3cc36ab7d6ce9d12323ee Mon Sep 17 00:00:00 2001 From: elaouniyassine Date: Sun, 24 Nov 2024 02:09:44 +0100 Subject: [PATCH 1/4] Improve UI feedback for disabled columns in scenario --- R/30_mod_scenario_fct.R | 36 ++++++++++++++++++++++++++++++++++++ R/30_mod_scenario_server.R | 24 ++++++++++++++++-------- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/R/30_mod_scenario_fct.R b/R/30_mod_scenario_fct.R index 0e57181..cb14663 100644 --- a/R/30_mod_scenario_fct.R +++ b/R/30_mod_scenario_fct.R @@ -54,6 +54,9 @@ js <- function(ns) { disable_specific_rows_edit_js <- function(rows_to_disable) { glue('function (td, cellData, rowData, row, col) {{ if ([{paste(rows_to_disable, collapse = ", ")}].includes(row)) {{ + // Add cursor style to indicate disabled state + $(td).css("cursor", "not-allowed"); + $(td).on("dblclick", function(e) {{ e.stopPropagation(); $(td).addClass("disabled-cell"); @@ -77,6 +80,39 @@ disable_all_rows_edit_js <- function() { }' } +# Disable editing and add "not-allowed" cursor to the entire column +disable_and_add_cursor_js <- function() { + 'function (td, cellData, rowData, row, col) { + // Disable double-click editing for all cells + $(td).on("dblclick", function(e) { + e.stopPropagation(); + $(td).addClass("disabled-cell"); + setTimeout(function() { + $(td).removeClass("disabled-cell"); + }, 250); + }); + + // Add "not-allowed" cursor style to all cells + $(td).css("cursor", "not-allowed"); + }' +} + +# Disable editing for all column cells and conditionally add "not-allowed" cursor +disable_with_conditional_cursor_js <- function(rows_to_highlight) { + glue('function (td, cellData, rowData, row, col) {{ + // Always disable editing + $(td).off("dblclick").on("dblclick", function(e) {{ + e.stopPropagation(); + }}); + + // Check if the cell row index is in the rows_to_highlight array + if ([{paste(rows_to_highlight, collapse = ", ")}].includes(row)) {{ + // Add "not-allowed" cursor for these specific rows + $(td).css("cursor", "not-allowed"); + }} +}}') +} + # Define a function to click on elements with a specific prefix in their ID click_by_prefix <- function(prefix) { js_code <- sprintf(" diff --git a/R/30_mod_scenario_server.R b/R/30_mod_scenario_server.R index 57ec3d8..7cbf767 100644 --- a/R/30_mod_scenario_server.R +++ b/R/30_mod_scenario_server.R @@ -1429,6 +1429,21 @@ scenario_server <- function( createdCell = JS(disable_specific_rows_edit_js(rows_not_contains_rice)), searchable = FALSE ), + list( + targets = get_column_indices( + feedtype_dt, c("water_regime", "ecosystem_type", "organic_amendment") + ) - 1, + createdCell = JS(disable_with_conditional_cursor_js(rows_not_contains_rice)), + searchable = FALSE + ), + list( + targets = get_column_indices( + feedtype_dt, + c("landcover_c_factor", "slope_p_factor", "grassman_change_factor") + ) - 1, + createdCell = JS(disable_and_add_cursor_js()), + searchable = FALSE + ), list( targets = get_column_indices( feedtype_dt, @@ -1439,14 +1454,7 @@ scenario_server <- function( "land_cover_desc", "slope_desc", "grassman_desc", - "water_regime", - "ecosystem_type", - "organic_amendment", - "category", - "landcover_c_factor", - "slope_p_factor", - "grassman_change_factor" - ) + "category") ) - 1, # - 1 Added because rownames = FALSE createdCell = JS(disable_all_rows_edit_js()), searchable = FALSE From 1db8b3bd040f16f96a88f36b10b0a164960f4db5 Mon Sep 17 00:00:00 2001 From: elaouniyassine Date: Sun, 24 Nov 2024 02:34:33 +0100 Subject: [PATCH 2/4] Improve UI feedback for disabled columns in params DT --- R/40_mod_params_db_fct.R | 8 ++++++++ R/40_mod_params_db_server.R | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/R/40_mod_params_db_fct.R b/R/40_mod_params_db_fct.R index 9d2598d..37664f5 100644 --- a/R/40_mod_params_db_fct.R +++ b/R/40_mod_params_db_fct.R @@ -28,3 +28,11 @@ checkbox_link_multi <- function(id, ns, table_name) { ) ) } + +# Add "cursor: not-allowed" to an entire disabled column +add_cursor_to_disabled_column_js <- function() { + 'function (td, cellData, rowData, row, col) { + // Add "not-allowed" cursor style + $(td).css("cursor", "not-allowed"); + }' +} diff --git a/R/40_mod_params_db_server.R b/R/40_mod_params_db_server.R index 60a8ebe..a937942 100644 --- a/R/40_mod_params_db_server.R +++ b/R/40_mod_params_db_server.R @@ -564,7 +564,7 @@ params_db_server <- function( "livetype_desc", "ipcc_meth_ef_t1", "ipcc_meth_ef_t2", "ipcc_meth_man", "ipcc_meth_exc") ) - 1, - createdCell = JS(disable_all_rows_edit_js()), + createdCell = JS(disable_and_add_cursor_js()), searchable = FALSE ) )) @@ -580,6 +580,15 @@ params_db_server <- function( "lkp_grassinputlevel", "lkp_landcover", "lkp_slope")) { editablity <- FALSE + + column_defs <- list( + list( + targets = "_all", # Apply to all cells + createdCell = JS(add_cursor_to_disabled_column_js()), + searchable = FALSE + ) + ) + # Disable add and delete rows buttons shinyjs::disable(id = paste0("add_rows_", name)) shinyjs::disable(id = paste0("delete_rows_", name)) From 768243224d320bdaf46ce58c0c4cc5214e373d2b Mon Sep 17 00:00:00 2001 From: elaouniyassine Date: Sun, 24 Nov 2024 02:44:14 +0100 Subject: [PATCH 3/4] cleanup: remove obsolete CSS logic in row disabling --- R/30_mod_scenario_fct.R | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/R/30_mod_scenario_fct.R b/R/30_mod_scenario_fct.R index cb14663..412e81f 100644 --- a/R/30_mod_scenario_fct.R +++ b/R/30_mod_scenario_fct.R @@ -59,10 +59,6 @@ disable_specific_rows_edit_js <- function(rows_to_disable) { $(td).on("dblclick", function(e) {{ e.stopPropagation(); - $(td).addClass("disabled-cell"); - setTimeout(function() {{ - $(td).removeClass("disabled-cell"); - }}, 250); }}); }} }}') @@ -72,10 +68,6 @@ disable_all_rows_edit_js <- function() { 'function (td, cellData, rowData, row, col) { $(td).on("dblclick", function(e) { e.stopPropagation(); - $(td).addClass("disabled-cell"); - setTimeout(function() { - $(td).removeClass("disabled-cell"); - }, 250); }); }' } @@ -86,10 +78,6 @@ disable_and_add_cursor_js <- function() { // Disable double-click editing for all cells $(td).on("dblclick", function(e) { e.stopPropagation(); - $(td).addClass("disabled-cell"); - setTimeout(function() { - $(td).removeClass("disabled-cell"); - }, 250); }); // Add "not-allowed" cursor style to all cells From c865bda7912b3da8ff312ebecebcb5351c204647 Mon Sep 17 00:00:00 2001 From: elaouniyassine Date: Sun, 24 Nov 2024 02:48:31 +0100 Subject: [PATCH 4/4] Remove unnecessary title in fertilizer pickerinput --- R/30_mod_scenario_server.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/30_mod_scenario_server.R b/R/30_mod_scenario_server.R index 7cbf767..797e1c5 100644 --- a/R/30_mod_scenario_server.R +++ b/R/30_mod_scenario_server.R @@ -729,7 +729,6 @@ scenario_server <- function( h2("Choose a Fertilizer", class = "mb-3"), shinyWidgets::pickerInput( ns("fertilizer_code"), - "Fertilizer", choices = setNames( lkp_orgfertilizer()$fertilizer_code, lkp_orgfertilizer()$fertilizer_desc