Compare commits

...

3 Commits

14 changed files with 77 additions and 54 deletions

1
.gitignore vendored
View File

@@ -3,7 +3,6 @@
/_devel
/all_bases
scheme.rds
config.yml
.Renviron

View File

@@ -1,6 +1,6 @@
options(box.path = here::here())
box::use(
modules/utils,
R/modules/utils,
)
#' @export

View File

@@ -5,9 +5,9 @@ box::use(
options(box.path = here::here())
box::use(
modules/db,
modules/utils,
app/forms
R/modules/db,
R/modules/utils,
R/app/forms
)
#' @export

View File

@@ -5,9 +5,9 @@ box::use(
options(box.path = here::here())
box::use(
modules/db,
modules/utils,
app/forms
R/modules/db,
R/modules/utils,
R/app/forms
)
#' @export

View File

@@ -1,5 +1,5 @@
options(box.path = here::here())
box::use(modules/data_manipulations[is_this_empty_value])
box::use(R/modules/data_manipulations[is_this_empty_value])
#' @export
init_val = function(scheme, ns) {

View File

@@ -103,7 +103,7 @@ get_dummy_data = function(type) {
get_dummy_df = function(forms_id_type_list) {
options(box.path = here::here())
box::use(modules/utils)
box::use(R/modules/utils)
purrr::map(
.x = forms_id_type_list,
@@ -136,7 +136,7 @@ compare_existing_table_with_schema = function(
}
options(box.path = here::here())
box::use(modules/utils)
box::use(R/modules/utils)
# checking if db structure in form compatible with alrady writed data (in case on changig form)
if (identical(colnames(DBI::dbReadTable(con, table_name)), all_ids_from_schema)) {

View File

@@ -1,10 +1,16 @@
.on_load = function(ns) {
check_and_init_scheme()
}
#' @export
#' @description костыли для упрощения работы себе
set_global_options = function(
SYMBOL_DELIM = "; ",
APP.DEBUG = FALSE,
shiny.host = "127.0.0.1",
shiny.port = 1338,
# shiny.host = "127.0.0.1",
# shiny.port = 1338,
...
) {
@@ -29,9 +35,8 @@ set_global_options = function(
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,
shiny.port = shiny.port,
# shiny.host = shiny.host,
# shiny.port = shiny.port,
...
)
}
@@ -45,13 +50,15 @@ check_and_init_scheme = function() {
cli::cli_inform(c("*" = "проверка схемы..."))
options(box.path = here::here())
box::use(modules/db[local_db_backup])
box::use(
R/modules/db[local_db_backup]
)
# список файлов, изменение которых, приведут к переинициализиации схемы
files_to_watch <- c(
"config.yml",
"modules/scheme_generator.R",
"modules/utils.R"
"R/modules/scheme_generator.R",
"R/modules/utils.R"
)
# проверка существования отслеживаемых файлов
@@ -75,7 +82,7 @@ check_and_init_scheme = function() {
exist_hash <- tools::md5sum(c(scheme_file, files_to_watch))
# если первый запуск (нет файла с кешем) инициализация схемы
if (!file.exists(hash_file) | !file.exists("scheme.rds") | !all(file.exists(db_files))) {
if (!file.exists(hash_file) | !file.exists("temp/scheme.rds") | !all(file.exists(db_files))) {
init_scheme(scheme_file)
@@ -111,8 +118,8 @@ init_scheme = function(scheme_file) {
options(box.path = here::here())
box::use(
modules/db,
modules/scheme_generator[scheme_R6]
R/modules/db,
R/modules/scheme_generator[scheme_R6]
)
db_path <- fs::path(config::get("form_app_configure_path"), "db")
@@ -155,5 +162,5 @@ init_scheme = function(scheme_file) {
cli::cli_abort(c("В одной или нескольких схемах наименования вложенных форм совпадают:", paste("-", names(tab)[tab > 1])))
}
saveRDS(schms, "scheme.rds")
saveRDS(schms, "temp/scheme.rds")
}

View File

@@ -56,7 +56,7 @@ scheme_R6 <- R6::R6Class(
# extract main key
private$main_key_id <- self$get_key_id("main")
box::use(modules/utils)
box::use(R/modules/utils)
private$bslib_rendered_ui <- bslib::navset_card_underline(
id = "main",
!!!utils$make_list_of_pages(private$schemes_list[["main"]], private$main_key_id),

View File

@@ -266,7 +266,7 @@ update_forms_with_data = function(
) {
options(box.path = here::here())
box::use(modules/data_manipulations[is_this_empty_value])
box::use(R/modules/data_manipulations[is_this_empty_value])
# print("-----------------")
# cli::cli_inform("form_id: {form_id} | form_type: {form_type}")

49
app.R
View File

@@ -1,45 +1,39 @@
suppressPackageStartupMessages({
library(DBI)
library(tidyr)
library(dplyr)
library(purrr)
library(magrittr)
library(shiny)
library(bslib)
library(shinymanager)
})
# SOURCE FILES ============================
# packages
box::purge_cache()
box::use(
modules/utils,
modules/global_options,
modules/db,
modules/data_validation,
app/forms,
app/tasks,
app/logs,
modules/data_manipulations[is_this_empty_value]
bslib[...],
shiny[...]
)
# modules
box::use(
R/modules/utils,
R/modules/global_options,
R/modules/db,
R/modules/data_validation,
R/app/forms,
R/app/tasks,
R/app/logs,
R/modules/data_manipulations[is_this_empty_value]
)
# global settings:
# set global settings:
global_options$set_global_options(
shiny.host = "0.0.0.0",
shiny.port = 1338,
APP.DEBUG = FALSE
)
# init:
global_options$check_and_init_scheme()
# global vars:
box::use(
modules/global_options[AUTH_ENABLED]
R/modules/global_options[AUTH_ENABLED]
)
enabled_schemes <- unlist(config::get()$form_schemes)
enabled_schemes <- setNames(names(enabled_schemes), enabled_schemes)
# load schemes object:
schms <- readRDS("scheme.rds")
schms <- readRDS("temp/scheme.rds")
# CHECK FOR PANDOC ----------
# rmarkdown::find_pandoc(dir = "/opt/homebrew/bin/")
@@ -118,7 +112,7 @@ server <- function(input, output, session) {
res_auth <- if (AUTH_ENABLED) {
# check_credentials directly on sqlite db
shinymanager::secure_server(
check_credentials = check_credentials(
check_credentials = shinymanager::check_credentials(
db = "auth.sqlite",
passphrase = Sys.getenv("AUTH_DB_KEY")
),
@@ -1373,7 +1367,6 @@ server <- function(input, output, session) {
}
app <- shiny::shinyApp(ui = ui, server = server)
app <- shinyApp(ui = ui, server = server)
runApp(app, launch.browser = TRUE)
shiny::runApp(app, launch.browser = TRUE)

View File

@@ -1,6 +1,6 @@
{
"R": {
"Version": "4.3.1",
"Version": "4.3.2",
"Repositories": [
{
"Name": "CRAN",
@@ -717,6 +717,19 @@
],
"Hash": "b8552d117e1b808b09a832f589b79035"
},
"lubridate": {
"Package": "lubridate",
"Version": "1.9.5",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"generics",
"methods",
"timechange"
],
"Hash": "07061b348d057e8ac86771e0eff36b62"
},
"magrittr": {
"Package": "magrittr",
"Version": "2.0.3",
@@ -1203,6 +1216,17 @@
],
"Hash": "79540e5fcd9e0435af547d885f184fd5"
},
"timechange": {
"Package": "timechange",
"Version": "0.4.0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"cpp11"
],
"Hash": "39c40cb1ad47a4cc384a34a22a29463f"
},
"tinytex": {
"Package": "tinytex",
"Version": "0.46",

BIN
test.xlsx

Binary file not shown.