feat: bring config file back
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user