feat: корректная работа с главным экраном
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,8 @@
|
|||||||
/renv
|
/renv
|
||||||
/temp
|
/temp
|
||||||
|
|
||||||
|
scheme.rds
|
||||||
|
|
||||||
.Renviron
|
.Renviron
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.lintr
|
.lintr
|
||||||
|
|||||||
63
app.R
63
app.R
@@ -16,6 +16,7 @@ box::purge_cache()
|
|||||||
box::use(
|
box::use(
|
||||||
modules/utils,
|
modules/utils,
|
||||||
modules/global_options,
|
modules/global_options,
|
||||||
|
modules/global_options[enabled_schemas],
|
||||||
modules/db,
|
modules/db,
|
||||||
modules/data_validation,
|
modules/data_validation,
|
||||||
modules/scheme_generator[scheme_R6]
|
modules/scheme_generator[scheme_R6]
|
||||||
@@ -28,6 +29,7 @@ HEADER_TEXT <- sprintf("%s (%s)", Sys.getenv("FORM_TITLE", "NA"), Sys.getenv("F
|
|||||||
|
|
||||||
global_options$set_global_options(
|
global_options$set_global_options(
|
||||||
shiny.host = "0.0.0.0"
|
shiny.host = "0.0.0.0"
|
||||||
|
# enabled_schemas = "example_of_scheme"
|
||||||
)
|
)
|
||||||
global_options$check_and_init_scheme()
|
global_options$check_and_init_scheme()
|
||||||
|
|
||||||
@@ -48,12 +50,11 @@ ui <- page_sidebar(
|
|||||||
sidebar = sidebar(
|
sidebar = sidebar(
|
||||||
actionButton("add_new_main_key_button", "Добавить новую запись", icon("plus", lib = "font-awesome")),
|
actionButton("add_new_main_key_button", "Добавить новую запись", icon("plus", lib = "font-awesome")),
|
||||||
actionButton("save_data_button", "Сохранить данные", icon("floppy-disk", lib = "font-awesome")),
|
actionButton("save_data_button", "Сохранить данные", icon("floppy-disk", lib = "font-awesome")),
|
||||||
actionButton("clean_data_button", "Очистить данные", icon("user-plus", lib = "font-awesome")),
|
actionButton("clean_data_button", "Главная страница", icon("house", lib = "font-awesome")),
|
||||||
actionButton("load_data_button", "Загрузить данные", icon("pencil", lib = "font-awesome")),
|
actionButton("load_data_button", "Загрузить данные", icon("pencil", lib = "font-awesome")),
|
||||||
downloadButton("downloadDocx", "get .docx (test only)"),
|
downloadButton("downloadDocx", "get .docx (test only)"),
|
||||||
textOutput("status_message"),
|
textOutput("status_message"),
|
||||||
textOutput("status_message2"),
|
textOutput("status_message2"),
|
||||||
uiOutput("admin_buttons_panel"),
|
|
||||||
uiOutput("display_log"),
|
uiOutput("display_log"),
|
||||||
position = "left",
|
position = "left",
|
||||||
open = list(mobile = "always")
|
open = list(mobile = "always")
|
||||||
@@ -93,7 +94,7 @@ if (AUTH_ENABLED) {
|
|||||||
# SERVER LOGIC =============================
|
# SERVER LOGIC =============================
|
||||||
server <- function(input, output, session) {
|
server <- function(input, output, session) {
|
||||||
|
|
||||||
# AUTH SETUP ========================================
|
# AUTH SETUP =============================================
|
||||||
res_auth <- if (AUTH_ENABLED) {
|
res_auth <- if (AUTH_ENABLED) {
|
||||||
# check_credentials directly on sqlite db
|
# check_credentials directly on sqlite db
|
||||||
shinymanager::secure_server(
|
shinymanager::secure_server(
|
||||||
@@ -125,10 +126,14 @@ server <- function(input, output, session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (showing_buttons) {
|
if (showing_buttons) {
|
||||||
fluidRow(
|
tagList(
|
||||||
downloadButton("downloadData", "Экспорт в .xlsx"),
|
br(),
|
||||||
p(""), # separate buttons
|
strong("Импорт и экспорт данных для выбранной схемы:"),
|
||||||
actionButton("button_upload_data_from_xlsx", "импорт!", icon("file-import", lib = "font-awesome"))
|
verticalLayout(
|
||||||
|
downloadButton("downloadData", "Экспорт в .xlsx", style = "width: 250px; margin-top: 5px"),
|
||||||
|
actionButton("button_upload_data_from_xlsx", "импорт!", icon("file-import", lib = "font-awesome"), style = "width: 250px; margin-top: 10px"),
|
||||||
|
fluid = FALSE
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -141,29 +146,32 @@ server <- function(input, output, session) {
|
|||||||
nested_key = NULL,
|
nested_key = NULL,
|
||||||
nested_form_id = NULL
|
nested_form_id = NULL
|
||||||
)
|
)
|
||||||
scheme <- reactiveVal("schema_example") # наименование выбранной схемы
|
|
||||||
mhcs <- reactiveVal(schms[["schema_example"]]) # объект для выбранной схемы
|
scheme <- reactiveVal(enabled_schemas[1]) # наименование выбранной схемы
|
||||||
|
mhcs <- reactiveVal(schms[[enabled_schemas[1]]]) # объект для выбранной схемы
|
||||||
observers_started <- reactiveVal(NULL)
|
observers_started <- reactiveVal(NULL)
|
||||||
|
|
||||||
main_form_is_empty <- reactiveVal(TRUE)
|
main_form_is_empty <- reactiveVal(TRUE)
|
||||||
validator_main <- reactiveVal(NULL)
|
validator_main <- reactiveVal(NULL)
|
||||||
validator_nested <- reactiveVal(NULL)
|
validator_nested <- reactiveVal(NULL)
|
||||||
|
|
||||||
# динамический рендеринг --------------------------
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# ГЛАВНАЯ СТРАНИЦА ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
output$main_ui_navset <- renderUI({
|
output$main_ui_navset <- renderUI({
|
||||||
|
|
||||||
if (main_form_is_empty()) {
|
if (main_form_is_empty()) {
|
||||||
validator_main(NULL)
|
validator_main(NULL)
|
||||||
|
|
||||||
div(
|
div(
|
||||||
"Для начала работы нужно создать новую запись или загрузить существующую!",
|
|
||||||
paste(getOption("enabled_schemas"), collapse = ", "),
|
|
||||||
shiny::radioButtons(
|
shiny::radioButtons(
|
||||||
"schmes_selector",
|
"schmes_selector",
|
||||||
label = "Выбрать базу данных для работы",
|
label = strong("Выбрать базу данных для работы:"),
|
||||||
choices = getOption("enabled_schemas"),
|
choices = enabled_schemas,
|
||||||
selected = scheme()
|
selected = scheme()
|
||||||
)
|
),
|
||||||
|
"Для начала работы нужно создать новую запись или загрузить существующую!",
|
||||||
|
# загрузка панели для работы с базой данных
|
||||||
|
uiOutput("admin_buttons_panel")
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -639,6 +647,7 @@ server <- function(input, output, session) {
|
|||||||
# STATUSES ===============================
|
# STATUSES ===============================
|
||||||
# вывести отображение что что-то не так
|
# вывести отображение что что-то не так
|
||||||
output$status_message <- renderText({
|
output$status_message <- renderText({
|
||||||
|
scheme()
|
||||||
shiny::validate(
|
shiny::validate(
|
||||||
need(values$main_key, "⚠️ Необходимо указать id пациента!")
|
need(values$main_key, "⚠️ Необходимо указать id пациента!")
|
||||||
)
|
)
|
||||||
@@ -829,7 +838,27 @@ server <- function(input, output, session) {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
## export to .xlsx ====
|
## export to .xlsx ======================
|
||||||
|
observeEvent(input$export_to_xlsx, {
|
||||||
|
|
||||||
|
ui <- shiny::radioButtons(
|
||||||
|
"export_scheme_selector",
|
||||||
|
label = strong("Выбрать базу данных для работы:"),
|
||||||
|
choices = enabled_schemas,
|
||||||
|
selected = scheme()
|
||||||
|
)
|
||||||
|
|
||||||
|
showModal(modalDialog(
|
||||||
|
title = "чего учидил",
|
||||||
|
ui,
|
||||||
|
footer = tagList(
|
||||||
|
actionButton("one", "one"),
|
||||||
|
actionButton("close_modal_button", "Отмена")
|
||||||
|
)
|
||||||
|
))
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
output$downloadData <- downloadHandler(
|
output$downloadData <- downloadHandler(
|
||||||
filename = paste0(isolate(scheme()), "_", format(Sys.time(), "%Y%m%d_%H%M%S"), ".xlsx"),
|
filename = paste0(isolate(scheme()), "_", format(Sys.time(), "%Y%m%d_%H%M%S"), ".xlsx"),
|
||||||
content = function(file) {
|
content = function(file) {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ set_global_options = function(
|
|||||||
# APP.FILE_DB = fs::path("data.sqlite"),
|
# APP.FILE_DB = fs::path("data.sqlite"),
|
||||||
shiny.host = "127.0.0.1",
|
shiny.host = "127.0.0.1",
|
||||||
shiny.port = 1337,
|
shiny.port = 1337,
|
||||||
enabled_schemas = c("schema", "schema_example"),
|
|
||||||
...
|
...
|
||||||
) {
|
) {
|
||||||
options(
|
options(
|
||||||
@@ -15,20 +14,23 @@ set_global_options = function(
|
|||||||
# APP.FILE_DB = APP.FILE_DB,
|
# APP.FILE_DB = APP.FILE_DB,
|
||||||
shiny.host = shiny.host,
|
shiny.host = shiny.host,
|
||||||
shiny.port = shiny.port,
|
shiny.port = shiny.port,
|
||||||
enabled_schemas = enabled_schemas,
|
|
||||||
...
|
...
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#' @export
|
||||||
|
enabled_schemas <- c(`Тестовая база данных` = "example_of_scheme")
|
||||||
|
|
||||||
#' @export
|
#' @export
|
||||||
check_and_init_scheme = function() {
|
check_and_init_scheme = function() {
|
||||||
|
|
||||||
cli::cli_inform(c("*" = "проверка схемы..."))
|
cli::cli_inform(c("*" = "проверка схемы..."))
|
||||||
|
|
||||||
# scheme_file <- fs::path("configs/schemas", "schema.xlsx")
|
scheme_names <- enabled_schemas
|
||||||
scheme_names <- getOption("enabled_schemas")
|
|
||||||
scheme_file <- paste0("configs/schemas/", scheme_names, ".xlsx")
|
scheme_file <- paste0("configs/schemas/", scheme_names, ".xlsx")
|
||||||
scheme_file <- stats::setNames(scheme_file, scheme_names)
|
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("db/", scheme_names, ".sqlite")
|
||||||
|
|
||||||
@@ -71,6 +73,8 @@ init_scheme = function(scheme_file) {
|
|||||||
modules/scheme_generator[scheme_R6]
|
modules/scheme_generator[scheme_R6]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!dir.exists("db")) dir.create("db")
|
||||||
|
|
||||||
cli::cli_h1("Инициализация схемы")
|
cli::cli_h1("Инициализация схемы")
|
||||||
schms <- purrr::map2(
|
schms <- purrr::map2(
|
||||||
.x = scheme_file,
|
.x = scheme_file,
|
||||||
|
|||||||
Reference in New Issue
Block a user