feat: bring config file back

This commit is contained in:
2026-04-20 18:50:40 +03:00
parent 7a006f6d6b
commit ac75ab08c2
8 changed files with 84 additions and 35 deletions

View File

@@ -70,10 +70,7 @@ init_val = function(scheme, ns) {
val_is_a_number = function(x) {
# exit if empty
if (is_this_empty_value(x)) {
return(NULL)
}
if (is_this_empty_value(x)) return(NULL)
# хак для пропуска значений
if (x == "NA") return(NULL)
@@ -87,10 +84,7 @@ val_is_a_number = function(x) {
val_number_within_a_range = function(x, ranges) {
# exit if empty
if (is_this_empty_value(x)) {
return(NULL)
}
if (is_this_empty_value(x)) return(NULL)
if (x == "NA") return(NULL)
# замена разделителя десятичных цифр

View File

@@ -4,7 +4,11 @@
#' @param where text mark to distingiush calss
make_db_connection = function(scheme, where = "") {
if (getOption("APP.DEBUG", FALSE)) message("=== DB CONNECT ", where)
DBI::dbConnect(RSQLite::SQLite(), fs::path("db", scheme, ext = "sqlite"))
DBI::dbConnect(RSQLite::SQLite(), fs::path(
config::get("form_db_path"),
scheme,
ext = "sqlite"
))
}
#' @export
@@ -12,12 +16,14 @@ make_db_connection = function(scheme, where = "") {
#' Function to close connection to db, disigned to easy dubugging and
#' hide warnings.
close_db_connection = function(con, where = "") {
tryCatch(
expr = DBI::dbDisconnect(con),
error = function(e) print(e),
warning = function(w) if (getOption("APP.DEBUG", FALSE)) message("=!= ALREADY DISCONNECTED ", where),
finally = if (getOption("APP.DEBUG", FALSE)) message("=/= DB DISCONNECT ", where)
)
}
#' @export

View File

@@ -3,13 +3,28 @@
set_global_options = function(
SYMBOL_DELIM = "; ",
APP.DEBUG = FALSE,
# APP.FILE_DB = fs::path("data.sqlite"),
shiny.host = "127.0.0.1",
shiny.port = 1338,
...
) {
config_params_to_check <- c(
"form_app_version",
"form_db_path",
"form_configs_path",
"form_auth_enabled",
"form_id",
"form_name"
)
expected_params_in_config <- config_params_to_check %in% names(config::get())
if (!all(expected_params_in_config)) {
cli::cli_abort(c("ну так не пойдет:", paste("-", config_params_to_check[!expected_params_in_config])))
}
options(
SYMBOL_DELIM = SYMBOL_DELIM,
# form.db_path = config::get("form_db_path"),
APP.DEBUG = APP.DEBUG,
# APP.FILE_DB = APP.FILE_DB,
shiny.host = shiny.host,
@@ -18,27 +33,30 @@ set_global_options = function(
)
}
#' @export
AUTH_ENABLED <- Sys.getenv("FORM_AUTH_ENABLED", FALSE)
#' @export
check_and_init_scheme = function() {
cli::cli_inform(c("*" = "проверка схемы..."))
options(box.path = here::here())
box::use(configs/enabled_schemes[enabled_schemes])
options(box.path = config::get("form_configs_path"))
box::use(enabled/enabled_schemes[enabled_schemes])
files_to_watch <- c(
"configs/enabled_schemes.R",
fs::path(config::get("form_configs_path"), "enabled", "enabled_schemes.R"),
"modules/scheme_generator.R",
"modules/utils.R"
)
scheme_names <- enabled_schemes
scheme_file <- paste0("configs/schemas/", scheme_names, ".xlsx")
scheme_file <- paste0(config::get("form_configs_path"), "/schemas/", scheme_names, ".xlsx")
scheme_file <- stats::setNames(scheme_file, scheme_names)
if (!all(file.exists(scheme_file))) cli::cli_abort(c("Отсутствуют файлы схем для следующих наименований:", paste("-", names(scheme_file)[!file.exists(scheme_file)])))
db_files <- paste0("db/", scheme_names, ".sqlite")
db_files <- paste0(config::get("form_db_path"), "/", scheme_names, ".sqlite")
hash_file <- "temp/schema_hash.rds"
@@ -52,8 +70,10 @@ check_and_init_scheme = function() {
# в ином случае - проверяем кэш
} else {
saved_hash <- readRDS(hash_file)
print(exist_hash)
print(saved_hash)
# если данные были изменены проводим реинициализацию таблицы и схемы
if (!all(exist_hash == saved_hash)) {
@@ -79,7 +99,7 @@ init_scheme = function(scheme_file) {
modules/scheme_generator[scheme_R6]
)
if (!dir.exists("db")) dir.create("db")
if (!dir.exists(config::get("form_db_path"))) dir.create(config::get("form_db_path"))
cli::cli_h1("Инициализация схемы")
schms <- purrr::map2(