fix: корректная проверка схем
This commit is contained in:
@@ -1,15 +1,3 @@
|
|||||||
.on_load = function(ns) {
|
|
||||||
|
|
||||||
check_and_init_scheme()
|
|
||||||
|
|
||||||
# set global settings:
|
|
||||||
set_global_options(
|
|
||||||
shiny.host = "0.0.0.0",
|
|
||||||
shiny.port = 1338,
|
|
||||||
APP.DEBUG = FALSE
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#' @export
|
#' @export
|
||||||
#' @description костыли для упрощения работы себе
|
#' @description костыли для упрощения работы себе
|
||||||
@@ -17,23 +5,6 @@ set_global_options = function(
|
|||||||
SYMBOL_DELIM = "; ",
|
SYMBOL_DELIM = "; ",
|
||||||
...
|
...
|
||||||
) {
|
) {
|
||||||
|
|
||||||
config_params_to_check <- c(
|
|
||||||
"form_app_version",
|
|
||||||
"form_id",
|
|
||||||
"form_name",
|
|
||||||
"form_app_configure_path",
|
|
||||||
"form_auth_enabled",
|
|
||||||
"form_schemes"
|
|
||||||
)
|
|
||||||
|
|
||||||
expected_params_in_config <- config_params_to_check %in% names(config::get())
|
|
||||||
if (!all(expected_params_in_config)) {
|
|
||||||
cli::cli_abort(c(
|
|
||||||
"Необходимо добавить в файл конфига {.file config.yml} следующие параметры:",
|
|
||||||
paste0(config_params_to_check[!expected_params_in_config], ":")
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
options(
|
options(
|
||||||
SYMBOL_DELIM = SYMBOL_DELIM,
|
SYMBOL_DELIM = SYMBOL_DELIM,
|
||||||
@@ -55,6 +26,27 @@ ENABLED_SCHEMES <- stats::setNames(names(ENABLED_SCHEMES), ENABLED_SCHEMES)
|
|||||||
#' @export
|
#' @export
|
||||||
check_and_init_scheme = function() {
|
check_and_init_scheme = function() {
|
||||||
|
|
||||||
|
cli::cli_inform(c("*" = "проверка файла конфигурации..."))
|
||||||
|
|
||||||
|
config_params_to_check <- c(
|
||||||
|
"form_app_version",
|
||||||
|
"form_id",
|
||||||
|
"form_name",
|
||||||
|
"form_app_configure_path",
|
||||||
|
"form_auth_enabled",
|
||||||
|
"form_schemes"
|
||||||
|
)
|
||||||
|
|
||||||
|
expected_params_in_config <- config_params_to_check %in% names(config::get())
|
||||||
|
|
||||||
|
if (!all(expected_params_in_config)) {
|
||||||
|
cli::cli_abort(c(
|
||||||
|
"Необходимо добавить в файл конфига {.file config.yml} следующие параметры:",
|
||||||
|
paste0(config_params_to_check[!expected_params_in_config], ":")
|
||||||
|
))
|
||||||
|
}
|
||||||
|
# -------------------
|
||||||
|
|
||||||
cli::cli_inform(c("*" = "проверка схемы..."))
|
cli::cli_inform(c("*" = "проверка схемы..."))
|
||||||
|
|
||||||
options(box.path = here::here())
|
options(box.path = here::here())
|
||||||
@@ -81,16 +73,17 @@ check_and_init_scheme = function() {
|
|||||||
if (!all(file.exists(scheme_file))) {
|
if (!all(file.exists(scheme_file))) {
|
||||||
cli::cli_abort(c("Отсутствуют файлы схем для следующих наименований:", paste("-", names(scheme_file)[!file.exists(scheme_file)])))
|
cli::cli_abort(c("Отсутствуют файлы схем для следующих наименований:", paste("-", names(scheme_file)[!file.exists(scheme_file)])))
|
||||||
}
|
}
|
||||||
|
|
||||||
db_files <- paste0(config::get("form_app_configure_path"), "/db/", scheme_names, ".sqlite")
|
db_files <- paste0(config::get("form_app_configure_path"), "/db/", scheme_names, ".sqlite")
|
||||||
|
|
||||||
|
if (!dir.exists("temp")) dir.create("temp")
|
||||||
hash_file <- "temp/schema_hash.rds"
|
hash_file <- "temp/schema_hash.rds"
|
||||||
|
|
||||||
#
|
#
|
||||||
exist_hash <- tools::md5sum(c(scheme_file, files_to_watch))
|
exist_hash <- tools::md5sum(c(scheme_file, files_to_watch))
|
||||||
|
|
||||||
# если первый запуск (нет файла с кешем) инициализация схемы
|
# если первый запуск (нет файла с кешем) инициализация схемы
|
||||||
if (!file.exists(hash_file) | !file.exists("temp/scheme.rds") | !all(file.exists(db_files))) {
|
if (!file.exists(hash_file) | !file.exists("temp/scheme.rds")) {
|
||||||
|
|
||||||
init_scheme(scheme_file)
|
init_scheme(scheme_file)
|
||||||
|
|
||||||
|
|||||||
10
app.R
10
app.R
@@ -19,9 +19,19 @@ box::use(
|
|||||||
|
|
||||||
# глобальные переменные и проверка/инициация схемы:
|
# глобальные переменные и проверка/инициация схемы:
|
||||||
box::use(
|
box::use(
|
||||||
|
R/modules/global_options[set_global_options, check_and_init_scheme],
|
||||||
R/modules/global_options[AUTH_ENABLED, ENABLED_SCHEMES],
|
R/modules/global_options[AUTH_ENABLED, ENABLED_SCHEMES],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# set global settings:
|
||||||
|
set_global_options(
|
||||||
|
shiny.host = "0.0.0.0",
|
||||||
|
# shiny.port = 1338,
|
||||||
|
APP.DEBUG = FALSE
|
||||||
|
)
|
||||||
|
|
||||||
|
check_and_init_scheme()
|
||||||
|
|
||||||
SCHMS <- readRDS("temp/scheme.rds")
|
SCHMS <- readRDS("temp/scheme.rds")
|
||||||
|
|
||||||
# CHECK FOR PANDOC ----------
|
# CHECK FOR PANDOC ----------
|
||||||
|
|||||||
Reference in New Issue
Block a user