Compare commits

..

11 Commits

8 changed files with 48 additions and 15 deletions

View File

@@ -1 +1,21 @@
source("renv/activate.R") source("renv/activate.R")
(function() {
paths <- c(
"FORM_AUTH_ENABLED",
"FORM_VERSION",
"FORM_TITLE"
)
lines <- paths[Sys.getenv(paths) == ""]
if (length(lines) > 0) {
cli::cli_h3("Настройка путей окружения")
cli::cli_code(paste0(lines, "="))
cli::cli_inform(c(
"i" = "Для нормальной работы скриптов добавьте в {.file .Renviron}:"
))
}
})()

3
.gitignore vendored
View File

@@ -2,7 +2,8 @@
/temp /temp
scheme.rds scheme.rds
configs/schemas/d2tra_t.xlsx
configs/schemas/antifib.xlsx
.Renviron .Renviron
.DS_Store .DS_Store
.lintr .lintr

25
app.R
View File

@@ -118,9 +118,9 @@ server <- function(input, output, session) {
if (AUTH_ENABLED) { if (AUTH_ENABLED) {
reactiveValuesToList(res_auth) reactiveValuesToList(res_auth)
if (res_auth$admin) { if (res_auth$admin) {
print("admin") # print("admin")
} else { } else {
print("not_admin") # print("not_admin")
showing_buttons <- FALSE showing_buttons <- FALSE
} }
} }
@@ -234,8 +234,8 @@ server <- function(input, output, session) {
) { ) {
nested_key_id <- mhcs()$get_key_id(table_name) nested_key_id <- mhcs()$get_key_id(table_name)
input_types <- unname(id_and_types_list) input_types <- unname(id_and_types_list)
input_ids <- names(id_and_types_list) input_ids <- names(id_and_types_list)
if (missing(ns)) ns <- NULL if (missing(ns)) ns <- NULL
@@ -342,8 +342,13 @@ server <- function(input, output, session) {
this_nested_form_scheme <- mhcs()$get_scheme(values$nested_form_id) this_nested_form_scheme <- mhcs()$get_scheme(values$nested_form_id)
# мини-схема для ключа # мини-схема для ключа
this_nested_form_key_scheme <- subset(this_nested_form_scheme, form_id == key_id) this_nested_form_key_scheme <- this_nested_form_scheme |>
if (nrow(this_nested_form_key_scheme) > 1) cli::cli_abort("количество строк не может быть больше одного для ключа") dplyr::filter(form_id == {{key_id}})
this_nested_form_key_scheme_smoll <- this_nested_form_key_scheme |>
dplyr::distinct(form_id, form_label, form_type)
if (nrow(this_nested_form_key_scheme_smoll) > 1) cli::cli_abort("количество строк не может быть больше одного для ключа")
# выбираем все ключи из баз данных # выбираем все ключи из баз данных
kyes_for_this_table <- db$get_nested_keys_from_table(values$nested_form_id, mhcs(), values$main_key, con) kyes_for_this_table <- db$get_nested_keys_from_table(values$nested_form_id, mhcs(), values$main_key, con)
@@ -352,7 +357,7 @@ server <- function(input, output, session) {
values$nested_key <- if (length(kyes_for_this_table) == 0) NULL else kyes_for_this_table[[1]] values$nested_key <- if (length(kyes_for_this_table) == 0) NULL else kyes_for_this_table[[1]]
# если ключ в формате даты - дать человекочитаемые данные # если ключ в формате даты - дать человекочитаемые данные
if (this_nested_form_key_scheme$form_type == "date") { if (this_nested_form_key_scheme_smoll$form_type == "date") {
kyes_for_this_table <- setNames( kyes_for_this_table <- setNames(
kyes_for_this_table, kyes_for_this_table,
format(as.Date(kyes_for_this_table), "%d.%m.%Y") format(as.Date(kyes_for_this_table), "%d.%m.%Y")
@@ -390,7 +395,7 @@ server <- function(input, output, session) {
width = 300, width = 300,
selectizeInput( selectizeInput(
inputId = "nested_key_selector", inputId = "nested_key_selector",
label = strong(this_nested_form_key_scheme$form_label), label = strong(this_nested_form_key_scheme_smoll$form_label),
choices = kyes_for_this_table, choices = kyes_for_this_table,
selected = values$nested_key, selected = values$nested_key,
# options = list(placeholder = "действие комиссии", create = FALSE, onInitialize = I('function() { this.setValue(""); }')) # options = list(placeholder = "действие комиссии", create = FALSE, onInitialize = I('function() { this.setValue(""); }'))
@@ -589,6 +594,8 @@ server <- function(input, output, session) {
mhcs(), mhcs(),
ns = NS(values$nested_form_id) ns = NS(values$nested_form_id)
) )
} else {
utils$clean_forms(values$nested_form_id, mhcs(), NS(values$nested_form_id))
} }
}) })
@@ -1138,7 +1145,7 @@ server <- function(input, output, session) {
append = TRUE append = TRUE
) )
message <- glue::glue("Данные таблицы '{table_name}' успешно обновлены") message <- glue::glue("Данные таблицы '{table_name}' успешно обновлены (добавлено {nrow(df)} записей)")
showNotification( showNotification(
message, message,
type = "message" type = "message"

View File

@@ -5,7 +5,7 @@ set_global_options = function(
APP.DEBUG = FALSE, APP.DEBUG = FALSE,
# APP.FILE_DB = fs::path("data.sqlite"), # APP.FILE_DB = fs::path("data.sqlite"),
shiny.host = "127.0.0.1", shiny.host = "127.0.0.1",
shiny.port = 1337, shiny.port = 1338,
... ...
) { ) {
options( options(

View File

@@ -22,6 +22,10 @@ scheme_R6 <- R6::R6Class(
check <- private$reserved_table_names %in% private$nested_forms_names check <- private$reserved_table_names %in% private$nested_forms_names
if (any(check)) cli::cli_abort(c("нельзя использовать данные имена вложенных таблиц:", paste("- ", private$reserved_table_names[check]))) if (any(check)) cli::cli_abort(c("нельзя использовать данные имена вложенных таблиц:", paste("- ", private$reserved_table_names[check])))
# проверка на длину строк
check <- (nchar(private$nested_forms_names) > 31)
if (any(check)) cli::cli_abort(c("нельзя использовать имена длиной более 31 символа:", paste("- ", private$nested_forms_names[check])))
purrr::walk( purrr::walk(
.x = purrr::set_names(private$nested_forms_names), .x = purrr::set_names(private$nested_forms_names),
.f = \(nested_form_id) { .f = \(nested_form_id) {

View File

@@ -162,7 +162,7 @@ render_forms = function(
choices = choices, choices = choices,
selected = NULL, selected = NULL,
options = list( options = list(
create = FALSE, create = TRUE,
onInitialize = I('function() { this.setValue(""); }') onInitialize = I('function() { this.setValue(""); }')
) )
) )
@@ -177,7 +177,7 @@ render_forms = function(
selected = NULL, selected = NULL,
multiple = TRUE, multiple = TRUE,
options = list( options = list(
create = FALSE, create = TRUE,
onInitialize = I('function() { this.setValue(""); }') onInitialize = I('function() { this.setValue(""); }')
) )
) )
@@ -263,7 +263,8 @@ update_forms_with_data = function(
local_delimeter = getOption("SYMBOL_DELIM"), local_delimeter = getOption("SYMBOL_DELIM"),
ns ns
) { ) {
options(box.path = here::here())
box::use(modules/data_manipulations[is_this_empty_value]) box::use(modules/data_manipulations[is_this_empty_value])
# print("-----------------") # print("-----------------")

View File

@@ -3,7 +3,7 @@
# SETUP AUTH ============================= # SETUP AUTH =============================
# Init DB using credentials data # Init DB using credentials data
credentials <- data.frame( credentials <- data.frame(
user = c("admin", "user"), user = c("admin", "user"),
password = c("admin", "user"), password = c("admin", "user"),
# password will automatically be hashed # password will automatically be hashed
admin = c(TRUE, FALSE), admin = c(TRUE, FALSE),