refactor: cleaning and polishing
This commit is contained in:
75
app.R
75
app.R
@@ -16,40 +16,35 @@ box::use(
|
||||
modules/global_options,
|
||||
modules/db,
|
||||
modules/data_validation,
|
||||
modules/scheme_generator[scheme_R6]
|
||||
app/forms,
|
||||
app/tasks
|
||||
)
|
||||
|
||||
# global settings:
|
||||
global_options$set_global_options(
|
||||
shiny.host = "0.0.0.0"
|
||||
# APP.DEBUG = TRUE
|
||||
shiny.host = "0.0.0.0",
|
||||
APP.DEBUG = FALSE
|
||||
)
|
||||
|
||||
# init:
|
||||
global_options$check_and_init_scheme()
|
||||
|
||||
# global vars
|
||||
# global vars:
|
||||
box::use(
|
||||
modules/global_options[AUTH_ENABLED]
|
||||
)
|
||||
enabled_schemes <- unlist(config::get()$form_schemes)
|
||||
enabled_schemes <- setNames(names(enabled_schemes), enabled_schemes)
|
||||
|
||||
# MODULES
|
||||
box::use(app/forms)
|
||||
box::use(app/tasks)
|
||||
# load schemes object:
|
||||
schms <- readRDS("scheme.rds")
|
||||
|
||||
# refactor LATER ---------
|
||||
vv <- unlist(config::get()$form_schemes)
|
||||
enabled_schemes <- names(vv)
|
||||
vvvv <- unname(vv)
|
||||
names(enabled_schemes) <- vvvv
|
||||
# ------------------------
|
||||
|
||||
# CHECK FOR PANDOC
|
||||
# TEMP ! NEED TO HANDLE
|
||||
# CHECK FOR PANDOC ----------
|
||||
rmarkdown::find_pandoc(dir = "/opt/homebrew/bin/")
|
||||
|
||||
# TODO: dynamic button render depend on pandoc installation
|
||||
if (!rmarkdown::pandoc_available()) warning("Can't find pandoc!")
|
||||
|
||||
# SCHEME_MAIN UNPACK ==========================
|
||||
schms <- readRDS("scheme.rds")
|
||||
|
||||
# UI =======================
|
||||
ui <- page_sidebar(
|
||||
@@ -76,7 +71,7 @@ ui <- page_sidebar(
|
||||
uiOutput("status_message"),
|
||||
textOutput("status_message2"),
|
||||
uiOutput("display_log"),
|
||||
actionButton("tasks-display_task_modal", "Задачи: нет активных"),
|
||||
actionButton("tasks-display_task_modal", "Задачи: нет активных", icon("list-check")),
|
||||
position = "left",
|
||||
open = list(mobile = "always")
|
||||
),
|
||||
@@ -137,9 +132,7 @@ server <- function(input, output, session) {
|
||||
if (AUTH_ENABLED) {
|
||||
reactiveValuesToList(res_auth)
|
||||
if (res_auth$admin) {
|
||||
# print("admin")
|
||||
} else {
|
||||
# print("not_admin")
|
||||
showing_buttons <- FALSE
|
||||
}
|
||||
}
|
||||
@@ -160,8 +153,10 @@ server <- function(input, output, session) {
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# REACTIVE VALUES =================================
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
# Create a reactive values object to store the input data
|
||||
values <- reactiveValues(
|
||||
data = NULL,
|
||||
@@ -182,7 +177,7 @@ server <- function(input, output, session) {
|
||||
validator_nested <- reactiveVal(NULL)
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# ГЛАВНАЯ СТРАНИЦА -------------------------------
|
||||
# reactive ui -------------------------------
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
## reactive ui -----------------------------------
|
||||
@@ -221,10 +216,9 @@ server <- function(input, output, session) {
|
||||
### bases info ----------------
|
||||
observeEvent(main_form_is_empty(), {
|
||||
|
||||
if (main_form_is_empty() == TRUE) {
|
||||
|
||||
output$base_data <- renderUI({
|
||||
output$base_data <- renderUI({
|
||||
|
||||
if (main_form_is_empty() == TRUE) {
|
||||
con <- db$make_db_connection(scheme(),"base_data")
|
||||
on.exit(db$close_db_connection(con, "base_data"), add = TRUE)
|
||||
|
||||
@@ -239,8 +233,10 @@ server <- function(input, output, session) {
|
||||
|
||||
tasks_count <- DBI::dbGetQuery(con, glue::glue("SELECT COUNT (task_id) FROM tasks WHERE task_status = 'active'")) |>
|
||||
dplyr::pull()
|
||||
|
||||
tasks_today_count <- DBI::dbGetQuery(con, glue::glue("SELECT COUNT (task_id) FROM tasks WHERE task_status = 'active' AND task_due_date = {as.integer(Sys.Date())}")) |>
|
||||
dplyr::pull()
|
||||
|
||||
tasks_overdue_count <- DBI::dbGetQuery(con, glue::glue("SELECT COUNT (task_id) FROM tasks WHERE task_status = 'active' AND task_due_date < {as.integer(Sys.Date())}")) |>
|
||||
dplyr::pull()
|
||||
|
||||
@@ -261,15 +257,16 @@ server <- function(input, output, session) {
|
||||
span(strong("Активных на сегодня:"), if (tasks_today_count > 0) actionLink("tasks-show_dt_today", tasks_today_count) else "0", br()),
|
||||
span(strong("Просроченных:"), if (tasks_overdue_count > 0) actionLink("tasks-show_dt_overdue", tasks_overdue_count) else "0", br())
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
# обновление данных схем ------
|
||||
observeEvent(input$schmes_selector, {
|
||||
|
||||
scheme(input$schmes_selector)
|
||||
mhcs(schms[[input$schmes_selector]])
|
||||
|
||||
})
|
||||
|
||||
# ==========================================
|
||||
@@ -422,6 +419,7 @@ server <- function(input, output, session) {
|
||||
|
||||
# nested ui
|
||||
nested_form_panels <- if (!is.null(values$nested_key)) {
|
||||
|
||||
purrr::map(
|
||||
.x = unique(this_nested_form_scheme$subgroup),
|
||||
.f = \(subgroup) {
|
||||
@@ -442,7 +440,9 @@ server <- function(input, output, session) {
|
||||
}
|
||||
)
|
||||
} else {
|
||||
|
||||
list(bslib::nav_panel("", div("Нет доступных записей.", br(), "Необходимо создать новую запись.")))
|
||||
|
||||
}
|
||||
|
||||
# ui для всплывающего окна
|
||||
@@ -507,7 +507,7 @@ server <- function(input, output, session) {
|
||||
output$dt_nested <- DT::renderDataTable(
|
||||
DT::datatable(
|
||||
values$data,
|
||||
caption = 'Table 1: This is a simple caption for the table.',
|
||||
caption = 'В данной таблице можно изменять данные',
|
||||
rownames = FALSE,
|
||||
colnames = col_types |> dplyr::pull(form_id, form_label),
|
||||
extensions = c('KeyTable', "FixedColumns"),
|
||||
@@ -528,7 +528,7 @@ server <- function(input, output, session) {
|
||||
DT::dataTableOutput("dt_nested"),
|
||||
size = "xl",
|
||||
footer = tagList(
|
||||
actionButton("nested_form_dt_save", "сохранить изменения")
|
||||
actionButton("nested_form_dt_save", "Сохранить изменения", icon("floppy-disk"))
|
||||
),
|
||||
easyClose = TRUE
|
||||
))
|
||||
@@ -542,8 +542,9 @@ server <- function(input, output, session) {
|
||||
|
||||
### кнопка: отображение DT -----------------------------
|
||||
observeEvent(input$nested_form_dt_button, {
|
||||
con <- db$make_db_connection(scheme(),"nested_form_save_button")
|
||||
on.exit(db$close_db_connection(con, "nested_form_save_button"), add = TRUE)
|
||||
|
||||
con <- db$make_db_connection(scheme(),"nested_form_dt_button")
|
||||
on.exit(db$close_db_connection(con, "nested_form_dt_button"), add = TRUE)
|
||||
|
||||
removeModal()
|
||||
show_modal_for_nested_form_dt(con)
|
||||
@@ -627,8 +628,8 @@ server <- function(input, output, session) {
|
||||
|
||||
observeEvent(values$nested_key, {
|
||||
|
||||
con <- db$make_db_connection(scheme(),"nested_tables")
|
||||
on.exit(db$close_db_connection(con, "nested_tables"), add = TRUE)
|
||||
con <- db$make_db_connection(scheme(),"nested_key")
|
||||
on.exit(db$close_db_connection(con, "nested_key"), add = TRUE)
|
||||
|
||||
kyes_for_this_table <- db$get_nested_keys_from_table(values$nested_form_id, mhcs(), values$main_key, con)
|
||||
|
||||
@@ -685,8 +686,8 @@ server <- function(input, output, session) {
|
||||
observeEvent(input$confirm_create_new_nested_key, {
|
||||
req(input[[mhcs()$get_key_id(values$nested_form_id)]])
|
||||
|
||||
con <- db$make_db_connection(scheme(),"confirm_create_new_key")
|
||||
on.exit(db$close_db_connection(con, "confirm_create_new_key"), add = TRUE)
|
||||
con <- db$make_db_connection(scheme(),"confirm_create_new_nested_key")
|
||||
on.exit(db$close_db_connection(con, "confirm_create_new_nested_key"), add = TRUE)
|
||||
|
||||
existed_key <- db$get_nested_keys_from_table(
|
||||
table_name = values$nested_form_id,
|
||||
|
||||
Reference in New Issue
Block a user