Skip to content

Commit

Permalink
Update tables from overall checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jthompson-arcus committed Dec 2, 2024
1 parent 2493779 commit 0cb8710
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ app_server <- function(
check_appdata(app_data, meta)

session$userData$review_records <- reactiveValues()
session$userData$update_checkboxes <- reactiveValues()

res_auth <- authenticate_server(
all_sites = app_vars$Sites$site_code,
Expand Down
7 changes: 7 additions & 0 deletions R/mod_common_forms.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ mod_common_forms_server <- function(
dplyr::arrange(id)
})

observeEvent(session$userData$update_checkboxes[[form]], {
checked <- session$userData$update_checkboxes[[form]]

shinyjs::runjs(sprintf("$(':checkbox', $('#%s .table').DataTable().rows().nodes()).prop('checked', %s)", ns("common_form_table"), tolower(checked)))
shinyjs::runjs(sprintf("$(':checkbox', $('#%s .table').DataTable().rows().nodes()).prop('checked', %s)", ns("SAE_table"), tolower(checked)))
})

observeEvent(input$SAE_table_review_selection, {
session$userData$review_records[[form]] <-
dplyr::rows_upsert(
Expand Down
32 changes: 15 additions & 17 deletions R/mod_review_forms.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ mod_review_forms_ui <- function(id){
inputId = ns("form_reviewed"),
label = "Reviewed",
value = FALSE
),
) |>
shiny::tagAppendAttributes(class = "cs_checkbox", .cssSelector = "input"),
"Mark as reviewed",
placement = "bottom"
),
Expand Down Expand Up @@ -129,16 +130,19 @@ mod_review_forms_server <- function(
dplyr::distinct(reviewed) |>
dplyr::pull()

if (length(review_status) == 1)
updateCheckboxInput(
inputId = "form_reviewed",
value = identical(review_status, "Yes")
)
shinyjs::runjs(sprintf("$('#%s').prop('checked', %s)", ns("form_reviewed"), tolower(identical(review_status, "Yes"))))
review_indeterminate(length(review_status) > 1)
}) |>
bindEvent(active_form(), session$userData$review_records[[active_form()]])

observeEvent(r$subject_id, {
session$userData$update_checkboxes[[active_form()]] <- NULL
session$userData$review_records[[active_form()]] <- NULL
})

observeEvent(input$form_reviewed, {
session$userData$update_checkboxes[[active_form()]] <- input$form_reviewed

session$userData$review_records[[active_form()]] <-
review_data_active() |>
dplyr::mutate(reviewed = ifelse(input$form_reviewed, "Yes", "No")) |>
Expand All @@ -148,7 +152,7 @@ mod_review_forms_server <- function(
by = c("id", "reviewed")
) |>
dplyr::arrange(id)
})
}, ignoreInit = TRUE)

observeEvent(c(active_form(), r$subject_id), {
cat("Update confirm review button\n\n\n")
Expand All @@ -169,16 +173,11 @@ mod_review_forms_server <- function(
# in this case get the reviewed = "No"
review_status <- unique(review_data_active()[["reviewed"]])
review_comment <- unique(review_data_active()[["comment"]])
if(length(review_status) != 1) {
if(length(review_status) != 1)
review_indeterminate(TRUE)
review_status <- "No"
}
}

updateCheckboxInput(
inputId = "form_reviewed",
value = identical(review_status, "Yes")
)
shinyjs::runjs(sprintf("$('#%s').prop('checked', %s)", ns("form_reviewed"), tolower(identical(review_status, "Yes"))))
shinyjs::runjs(sprintf("$('#%s').prop('indeterminate', %s)", ns("form_reviewed"), tolower(review_indeterminate())))

shinyWidgets::updatePrettySwitch(
Expand Down Expand Up @@ -221,7 +220,6 @@ mod_review_forms_server <- function(
req(
active_form(),
session$userData$review_records[[active_form()]],
is.logical(input$form_reviewed),
is.logical(enable_any_review())
)
if(!enable_any_review()) return(FALSE)
Expand Down Expand Up @@ -258,10 +256,10 @@ mod_review_forms_server <- function(

review_save_error <- reactiveVal(FALSE)
observeEvent(input$save_review, {
req(is.logical(input$form_reviewed), review_data_active())
req(review_data_active())
req(enable_save_review())
review_save_error(FALSE)
golem::cat_dev("Save review status reviewed:", input$form_reviewed, "\n")
# golem::cat_dev("Save review status reviewed:", input$form_reviewed, "\n")

review_records <- session$userData$review_records[[active_form()]][c("id", "reviewed")] |>
dplyr::mutate(
Expand Down
6 changes: 6 additions & 0 deletions R/mod_study_forms.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ mod_study_forms_server <- function(
dplyr::arrange(id)
})

observeEvent(session$userData$update_checkboxes[[form]], {
checked <- session$userData$update_checkboxes[[form]]

shinyjs::runjs(sprintf("$(':checkbox', $('#%s .table').DataTable().rows().nodes()).prop('checked', %s)", ns("table"), tolower(checked)))
})

############################### Outputs: ###################################
dynamic_figure <- reactive({
req(nrow(fig_data()) > 0, scaling_data())
Expand Down

0 comments on commit 0cb8710

Please sign in to comment.