Skip to content

Commit

Permalink
Added hold functionality
Browse files Browse the repository at this point in the history
Added ASM_onload() to updated docx placeholders in the UI with values in the state being loaded.
  • Loading branch information
john-harrold committed Jun 1, 2024
1 parent 777c308 commit 423b075
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
38 changes: 36 additions & 2 deletions R/ASM_Server.R
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ ASM_Server <- function(id,
uiele})
# rpt docx
output$ui_asm_rpt_docx_ph = renderUI({
react_state[[id]]
#req(input$X)
state = ASM_fetch_state(id = id,
input = input,
Expand Down Expand Up @@ -547,7 +548,26 @@ ASM_Server <- function(id,
FM_notify(state = state,
session = session)
})

#------------------------------------
# Removing holds
remove_hold_listen <- reactive({
list(react_state[[id]])
})
observeEvent(remove_hold_listen(), {
# Once the UI has been regenerated we
# remove any holds for this module
state = ASM_fetch_state(id = id,
input = input,
session = session,
FM_yaml_file = FM_yaml_file,
MOD_yaml_file = MOD_yaml_file)
formods::FM_le(state, "removing holds")
# Removing all holds
for(hname in names(state[["ASM"]][["ui_hold"]])){
remove_hold(state, session, hname)
}
}, priority = -100)
#------------------------------------
})

}
Expand Down Expand Up @@ -614,7 +634,9 @@ ASM_fetch_state = function(id, input, session, FM_yaml_file, MOD_yaml_file){
# Here we update the state based on user input
for(ui_name in state[["ASM"]][["ui_ids"]]){
if(!is.null(isolate(input[[ui_name]]))){
state[["ASM"]][["ui"]][[ui_name]] = isolate(input[[ui_name]])
if(!fetch_hold(state, ui_name)){
state[["ASM"]][["ui"]][[ui_name]] = isolate(input[[ui_name]])
}
} else {
state[["ASM"]][["ui"]][[ui_name]] = ""
}
Expand Down Expand Up @@ -782,6 +804,18 @@ ASM_fetch_state = function(id, input, session, FM_yaml_file, MOD_yaml_file){
# Returning the state
state}

#'@export
#'@title Updates ASM After State Load
#'@description Creates a list of the initialized module state
#'@param state ASM state object
#'@param session Shiny session variable
#'@return ASM state object
ASM_onload = function(state, session){
for(ph_ui in names(state[["ASM"]][["ph_uis"]])){
updateTextInput(session, inputId=ph_ui, value=state[["ASM"]][["ui"]][[ph_ui]])
}
state}

#'@export
#'@title Initialize ASM Module State
#'@description Creates a list of the initialized module state
Expand Down
1 change: 0 additions & 1 deletion R/formods.R
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,6 @@ FM_set_app_state <- function(session, app_state, set_holds = TRUE){
FM_message(line="Unable to find ASM state.")
}


# Replacing the app state in session:
session$userData[["FM"]] = app_state

Expand Down

0 comments on commit 423b075

Please sign in to comment.