diff --git a/app/main.R b/app/main.R index 9aa1ef4..aee9854 100644 --- a/app/main.R +++ b/app/main.R @@ -4,6 +4,7 @@ box::use( box::use( app/view/mod_add_selector, + app/view/mod_add, app/view/mod_view, app/view/mod_view_selector, app/view/mod_edit, @@ -39,7 +40,8 @@ server <- function(id) { table_name = NULL, row = NULL, operation = NULL, - table_data = NULL + table_data = NULL, + user_input = NULL ) shiny$observeEvent( @@ -71,7 +73,9 @@ server <- function(id) { ) } }) - }, ignoreNULL = TRUE, ignoreInit = TRUE + }, + ignoreNULL = TRUE, + ignoreInit = TRUE ) shiny$observeEvent(input$app_mode, @@ -97,6 +101,18 @@ server <- function(id) { mod_add_selector$ui( ns("selector") ) + + }) + + output$data_area_ui <- shiny$renderUI({ + mod_add$server( + "data_area", + selected + ) + + mod_add$ui( + ns("data_area") + ) }) } }, diff --git a/app/view/mod_add.R b/app/view/mod_add.R new file mode 100644 index 0000000..f9918cb --- /dev/null +++ b/app/view/mod_add.R @@ -0,0 +1,93 @@ +box::use( + glue[ + glue + ], + shiny, + stats[ + setNames + ], + tools[ + toTitleCase + ], +) + +#' @export +ui <- function(id) { + ns <- shiny$NS(id) + shiny$div( + class = "argus-data-area", + shiny$uiOutput(ns("argus_data")) + ) +} + +#' @export +server <- function(id, selected) { + shiny$moduleServer(id, function(input, output, session) { + + ns <- session$ns + + empty_dataframe <- shiny$reactive({ + data.frame( + selected$table_data()[0, ] + ) + }) + + max_id <- shiny$reactive({ + selected$table_data()$id |> + unlist() |> + max() + }) + + shiny$observeEvent(selected$table_data, { + + output$argus_data <- shiny$renderUI({ + + keys <- names(empty_dataframe()) + labels <- gsub( + "_", + " ", + names(empty_dataframe()) + ) |> + toTitleCase() + + keys <- setNames(as.list(labels), keys) + total <- length(keys) + + shiny$div( + class = "argus-data-grid", + lapply( + names(keys), + function(key) { + if (key == "id") { + class <- "argus-field-block is-id-block" + element <- shiny$p( + class = "argus-field-value", + max_id() + 1 + ) + } else { + class <- "argus-field-block" + element <- shiny$textInput( + inputId = ns(key), + label = NULL, + value = "" + ) |> + shiny$tagAppendAttributes( + class = "argus-field-input" + ) + } + shiny$div( + class = class, + shiny$p( + class = "argus-field-heading", + keys[key] + ), + element + ) + } + ) + ) + }) + }, ignoreNULL = TRUE) + + }) +}