diff --git a/server.R b/server.R index e5f650a7..c6702476 100644 --- a/server.R +++ b/server.R @@ -112,7 +112,7 @@ shinyServer(function(input, output, session) { shinyjs::hide("box_preview") shinyjs::hide("box_validate") shinyjs::hide("box_submit") - + # initial loading page observeEvent(input$cookie, { # login and update session @@ -459,14 +459,6 @@ shinyServer(function(input, output, session) { dcWaiter("hide") }) - observeEvent(input$dropdown_template, { - shinyjs::enable("btn_template") - shinyjs::enable("btn_template_select") - updateSelectInput(session, "header_dropdown_template", - choices = input$dropdown_template - ) - }) - # Goal of this button is to get the files within a folder the user selects observeEvent(input$btn_folder, { dcWaiter("show", msg = paste0("Getting data"), color = primary_col()) @@ -482,7 +474,7 @@ shinyServer(function(input, output, session) { sapply(clean_tags[1:2], FUN = hide) - if (selected$schema_type() %in% c("record", "file")) { + # if (selected$schema_type() %in% c("record", "file")) { # check number of files if it's file-based template # This gets files using the synapse REST API # get file list in selected folder @@ -512,7 +504,7 @@ shinyServer(function(input, output, session) { # update files list in the folder data_list$files(list2Vector(file_list)) } - } + # } }) observeEvent(input$dropdown_folder, { @@ -526,34 +518,6 @@ shinyServer(function(input, output, session) { }) observeEvent(data_list$files(), ignoreInit = TRUE, { - warn_text <- NULL - if (length(data_list$folders()) == 0) { - # add warning if there is no folder in the selected project - warn_text <- paste0( - "please create a folder in the ", - strong(sQuote(input$dropdown_project)), - " prior to submitting templates." - ) - } - if (is.null(data_list$files())) { - # display warning message if folder is empty and data type is file-based - warn_text <- paste0( - strong(sQuote(input$dropdown_folder)), " folder is empty, - please upload your data before generating manifest.", - "
", strong(sQuote(input$dropdown_template)), - " requires data files to be uploaded prior to generating and submitting templates.", - "
", "Filling in a template before uploading your data, - may result in errors and delays in your data submission later." - ) - } - - # if there is warning from above checks - if (!is.null(warn_text)) { - # display warnings - output$text_template_warn <- renderUI(tagList(br(), span(class = "warn_msg", HTML(warn_text)))) - show("div_template_warn") - } - dcWaiter("hide") }) @@ -579,6 +543,8 @@ shinyServer(function(input, output, session) { # update selected schema template name observeEvent(input$dropdown_template, { + req(input$tabs %in% "tab_template_select") + warn_text <- reactiveVal(NULL) shinyjs::enable("btn_template_select") # update reactive selected values for schema selected$schema(data_list$template()[input$dropdown_template]) @@ -594,6 +560,43 @@ shinyServer(function(input, output, session) { # clean all tags related with selected template sapply(clean_tags, FUN = hide) + + if (length(data_list$folders()) == 0) { + # add warning if there is no folder in the selected project + warn_text(paste0( + "please create a folder in the ", + strong(sQuote(input$dropdown_project)), + " prior to submitting templates." + )) + } + if (all(is.na(data_list$files())) & selected$schema_type() == "file") { + # display warning message if folder is empty and data type is file-based + warn_text(paste0( + strong(sQuote(input$dropdown_folder)), " folder is empty, + please upload your data before generating manifest.", + "
", strong(sQuote(input$dropdown_template)), + " requires data files to be uploaded prior to generating and submitting templates.", + "
", "Filling in a template before uploading your data, + may result in errors and delays in your data submission later." + )) + } + + # if there is warning from above checks + if (!is.null(warn_text())) { + # display warnings + output$text_template_warn <- renderUI(tagList(br(), span(class = "warn_msg", HTML(warn_text())))) + show("div_template_warn") + # nx_report_warning( + # title = "No data uploaded in folder", + # HTML(warn_text()) + # ) + } + + shinyjs::enable("btn_template") + shinyjs::enable("btn_template_select") + updateSelectInput(session, "header_dropdown_template", + choices = input$dropdown_template + ) }, ignoreInit = TRUE ) diff --git a/ui.R b/ui.R index e62af869..83cfefe2 100644 --- a/ui.R +++ b/ui.R @@ -203,6 +203,11 @@ ui <- shinydashboardPlus::dashboardPage( label = NULL, choices = "Generating..." ), + hidden(div( + id = "div_template_warn", + height = "100%", + htmlOutput("text_template_warn") + )), actionButton("btn_template_select", "Download template", class = "btn-primary-color" ),