From 59f7f40344127435e046dea1ec30d7dc8cc4c091 Mon Sep 17 00:00:00 2001 From: madeliri Date: Sat, 11 Apr 2026 15:17:21 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BE?= =?UTF-8?q?=D1=87=D0=BD=D0=B8=D0=BA=D0=B0=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20=D0=B4=D0=BB=D1=8F=20=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=20(select=5Fone,=20select=5Fmultiple),=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=81=D1=82=D0=B2=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=81=D1=85=D0=B5=D0=BC=D0=B5=20(=D0=B2=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B4=D0=B0=D1=86=D0=B8=D1=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.R | 21 ++++++++++++++------- modules/data_validation.R | 16 ++++++++++++++++ modules/utils.R | 30 ++++++++++++++++++------------ 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/app.R b/app.R index 7607c5a..1222eee 100644 --- a/app.R +++ b/app.R @@ -165,10 +165,15 @@ server <- function(input, output, session) { # ========================================== ## перенос данных из датафрейма в форму ----------------------- - load_data_to_form <- function(df, id_and_types_list, ns) { + load_data_to_form <- function( + df, + table_name = "main", + schm, + ns + ) { - input_types <- unname(id_and_types_list) - input_ids <- names(id_and_types_list) + input_types <- unname(schm$get_id_type_list(table_name)) + input_ids <- names(schm$get_id_type_list(table_name)) if (missing(ns)) ns <- NULL # transform df to list @@ -186,6 +191,7 @@ server <- function(input, output, session) { form_id = x_id, form_type = x_type, value = df[[x_id]], + scheme = schm$get_schema(table_name), ns = ns ) } @@ -524,7 +530,8 @@ server <- function(input, output, session) { # загрузка данных в формы load_data_to_form( df = df, - id_and_types_list = values$nested_id_and_types, + table_name = values$nested_form_id, + schm, ns = NS(values$nested_form_id) ) } @@ -640,8 +647,7 @@ server <- function(input, output, session) { on.exit(db$close_db_connection(con, "confirm_create_new_key"), add = TRUE) existed_key <- db$get_keys_from_table("main", schm, con) - print(existed_key) - + # если введенный ключ уже есть в базе if (input[[schm$get_main_key_id]] %in% existed_key) { showNotification( @@ -760,7 +766,8 @@ server <- function(input, output, session) { load_data_to_form( df = df, - id_and_types_list = schm$get_id_type_list("main") + table_name = "main", + schm ) values$main_key <- input$load_data_key_selector diff --git a/modules/data_validation.R b/modules/data_validation.R index 89ca464..8255a8a 100644 --- a/modules/data_validation.R +++ b/modules/data_validation.R @@ -44,6 +44,7 @@ init_val <- function(scheme, ns) { } # хак для пропуска значений if (x == "NA") return(NULL) + # check for numeric # if (grepl("^[-]?(\\d*\\,\\d+|\\d+\\,\\d*|\\d+)$", x)) NULL else "Значение должно быть числом." if (grepl("^[+-]?\\d*[\\.|\\,]?\\d+$", x)) NULL else "Значение должно быть числом." @@ -84,6 +85,21 @@ init_val <- function(scheme, ns) { } } + if (form_type %in% c("select_multiple", "select_one")) { + iv$add_rule(x_input_id, function(x) { + + # проверка на соответствие вариантов схеме --------- + compare_to_dict <- (x %in% choices) + if (!all(compare_to_dict)) { + + text <- paste0("'",x[!compare_to_dict],"'", collapse = ", ") + glue::glue("Данные варианты, не соответствуют схеме: {text}") + } + }) + + } + + # if in `required` column value is `1` apply standart validation if (!is.na(val_required) && val_required == 1) { iv$add_rule(x_input_id, shinyvalidate::sv_required(message = "Необходимо заполнить.")) diff --git a/modules/utils.R b/modules/utils.R index de65346..4dcce8f 100644 --- a/modules/utils.R +++ b/modules/utils.R @@ -27,10 +27,11 @@ make_panels <- function(scheme) { ) # make page wrap - page_wrap <- bslib::layout_column_wrap( + bslib::layout_column_wrap( # width = "350px", height = NULL, #was 800 width = 1 / 4, height = NULL, # was 800 fixed_width = TRUE, + heights_equal = "row", # unpack list of cards !!!cards ) @@ -235,10 +236,14 @@ update_forms_with_data <- function( form_id, form_type, value, + scheme, local_delimeter = getOption("SYMBOL_DELIM"), ns ) { + filterd_line <- scheme |> + dplyr::filter(form_id == {{form_id}}) + # если передана ns() функция то подмеяем id для каждой формы в соответствии с пространством имен if (!missing(ns) & !is.null(ns)) { form_id <- ns(form_id) @@ -262,12 +267,13 @@ update_forms_with_data <- function( # select_one if (form_type == "select_one") { # update choices - # old_choices <- subset(scheme, form_id == form_id, choices) |> dplyr::pull() - # new_choices <- unique(c(old_choices, value)) - # new_choices <- new_choices[!is.na(new_choices)] + old_choices <- filterd_line$choices + new_choices <- unique(c(old_choices, value)) + new_choices <- new_choices[!is.na(new_choices)] - # shiny::updateSelectizeInput(inputId = form_id, selected = value, choices = new_choices) - shiny::updateSelectizeInput(inputId = form_id, selected = value) + + shiny::updateSelectizeInput(inputId = form_id, selected = value, choices = new_choices) + # shiny::updateSelectizeInput(inputId = form_id, selected = value) } # select_multiple @@ -276,12 +282,12 @@ update_forms_with_data <- function( vars <- stringr::str_split_1(value, local_delimeter) # update choices - # old_choices <- subset(scheme, form_id == form_id, choices) |> dplyr::pull() - # new_choices <- unique(c(old_choices, vars)) - # new_choices <- new_choices[!is.na(new_choices)] + old_choices <- filterd_line$choices + new_choices <- unique(c(old_choices, vars)) + new_choices <- new_choices[!is.na(new_choices)] - # shiny::updateSelectizeInput(inputId = form_id, selected = vars, choices = new_choices) - shiny::updateSelectizeInput(inputId = form_id, selected = vars) + shiny::updateSelectizeInput(inputId = form_id, selected = vars, choices = new_choices) + # shiny::updateSelectizeInput(inputId = form_id, selected = vars) } # in other case fill with `character(0)` to proper reseting form @@ -316,7 +322,7 @@ clean_forms <- function(id_and_types_list, ns) { # если передана ns() функция то подмеяем id для каждой формы в соответствии с пространством имен if (missing(ns)) ns <- NULL - + purrr::walk2( .x = id_and_types_list, .y = names(id_and_types_list),