feat: bring config file back
This commit is contained in:
@@ -4,9 +4,8 @@ source("renv/activate.R")
|
||||
(function() {
|
||||
|
||||
paths <- c(
|
||||
"FORM_AUTH_ENABLED",
|
||||
"FORM_VERSION",
|
||||
"FORM_TITLE"
|
||||
"R_CONFIG_ACTIVE",
|
||||
"AUTH_DB_KEY"
|
||||
)
|
||||
|
||||
lines <- paths[Sys.getenv(paths) == ""]
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@
|
||||
scheme.rds
|
||||
configs/schemas/d2tra_t.xlsx
|
||||
configs/schemas/antifib.xlsx
|
||||
/_devel
|
||||
.Renviron
|
||||
.DS_Store
|
||||
.lintr
|
||||
|
||||
41
app.R
41
app.R
@@ -9,12 +9,9 @@ suppressPackageStartupMessages({
|
||||
library(shinymanager)
|
||||
})
|
||||
|
||||
# КАК ЗАПРЯТЯАТЬ ID
|
||||
|
||||
# SOURCE FILES ============================
|
||||
box::purge_cache()
|
||||
box::use(
|
||||
configs/enabled_schemes[enabled_schemes],
|
||||
modules/utils,
|
||||
modules/global_options,
|
||||
modules/db,
|
||||
@@ -22,17 +19,25 @@ box::use(
|
||||
modules/scheme_generator[scheme_R6]
|
||||
)
|
||||
|
||||
# SETTINGS ================================
|
||||
FILE_SCHEME <- fs::path("configs/schemas", "schema.xlsx")
|
||||
AUTH_ENABLED <- Sys.getenv("FORM_AUTH_ENABLED", FALSE)
|
||||
HEADER_TEXT <- sprintf("%s (%s)", Sys.getenv("FORM_TITLE", "NA"), Sys.getenv("FORM_VERSION", "NA"))
|
||||
|
||||
global_options$set_global_options(
|
||||
shiny.host = "0.0.0.0"
|
||||
# enabled_schemes = "example_of_scheme"
|
||||
)
|
||||
|
||||
global_options$check_and_init_scheme()
|
||||
|
||||
# global vars
|
||||
box::use(
|
||||
modules/global_options[AUTH_ENABLED]
|
||||
)
|
||||
|
||||
# SETTINGS ================================
|
||||
HEADER_TEXT <- sprintf("%s (%s)", config::get("form_name"), config::get("form_app_version"))
|
||||
|
||||
# sadasdasdasdasdas
|
||||
options(box.path = config::get("form_configs_path"))
|
||||
box::use(enabled/enabled_schemes[enabled_schemes])
|
||||
|
||||
|
||||
# CHECK FOR PANDOC
|
||||
# TEMP ! NEED TO HANDLE
|
||||
rmarkdown::find_pandoc(dir = "/opt/homebrew/bin/")
|
||||
@@ -45,7 +50,14 @@ schms <- readRDS("scheme.rds")
|
||||
|
||||
# UI =======================
|
||||
ui <- page_sidebar(
|
||||
title = HEADER_TEXT,
|
||||
# title = HEADER_TEXT,
|
||||
title = tagList(
|
||||
h4(HEADER_TEXT, style = "margin-top: .5rem"),
|
||||
tooltip(
|
||||
span("about", icon("circle-info", lib = "font-awesome")),
|
||||
"Данный функционал позволяет обрабатывать информацию о пациентах на комиссию, используя Excel (обновление данных возможно через окно формирования списка пациентов)"
|
||||
)
|
||||
),
|
||||
theme = bs_theme(version = 5, preset = "bootstrap"),
|
||||
sidebar = sidebar(
|
||||
actionButton("add_new_main_key_button", "Добавить новую запись", icon("plus", lib = "font-awesome")),
|
||||
@@ -59,12 +71,9 @@ ui <- page_sidebar(
|
||||
position = "left",
|
||||
open = list(mobile = "always")
|
||||
),
|
||||
as_fill_carrier(uiOutput("main_ui_navset"))
|
||||
as_fill_carrier(uiOutput("main_ui_navset")),
|
||||
)
|
||||
|
||||
# MODALS ========================
|
||||
# окно для подвтерждения очищения данных
|
||||
|
||||
# init auth =======================
|
||||
if (AUTH_ENABLED) {
|
||||
# shinymanager::set_labels("en", "Please authenticate" = "scheme()")
|
||||
@@ -898,6 +907,8 @@ server <- function(input, output, session) {
|
||||
"Пользователь" , ifelse(AUTH_ENABLED, res_auth$user, "anonymous"),
|
||||
"Название базы" , names(enabled_schemes)[enabled_schemes == scheme()],
|
||||
"id базы" , scheme(),
|
||||
"id формы" , config::get("form_id"),
|
||||
"ver формы" , config::get("form_app_version"),
|
||||
"Время выгрузки" , format(Sys.time(), "%d.%m.%Y %H:%M:%S"),
|
||||
)
|
||||
|
||||
@@ -1196,6 +1207,8 @@ server <- function(input, output, session) {
|
||||
action_row <- tibble(
|
||||
date = Sys.time(),
|
||||
user = ifelse(AUTH_ENABLED, res_auth$user, "anonymous"),
|
||||
app_id = config::get("form_id"),
|
||||
app_ver = config::get("form_app_version"),
|
||||
remote_addr = session$request$REMOTE_ADDR,
|
||||
key = key,
|
||||
action = action,
|
||||
|
||||
17
config.yml
Normal file
17
config.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
default:
|
||||
form_app_version: 0.15.0
|
||||
|
||||
prod:
|
||||
form_db_path: db
|
||||
form_configs_path: configs
|
||||
form_auth_enabled: true
|
||||
form_id: new_form
|
||||
form_name: NEW FORMY
|
||||
|
||||
devel:
|
||||
form_db_path: _devel/db
|
||||
form_configs_path: _devel/configs
|
||||
form_auth_enabled: false
|
||||
form_id: new_form
|
||||
form_name: NEW FORMY
|
||||
form_app_version: 0.15.0 dev
|
||||
@@ -1,5 +1,4 @@
|
||||
#' @export
|
||||
enabled_schemes <- c(
|
||||
`Тестовая база данных` = "example_of_scheme"
|
||||
# `D2TRA (для отладки)` = "d2tra_t"
|
||||
)
|
||||
@@ -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)
|
||||
|
||||
# замена разделителя десятичных цифр
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -54,6 +72,8 @@ 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