Compare commits

...

2 Commits

7 changed files with 154 additions and 14 deletions

View File

@@ -48,6 +48,7 @@ FORM_APP_LOCAL_DB_BACKUP_PATH="path_to_backups"
Проверка осуществляется при каждом запуске приложения, бэкапы создаются раз в день (при первом запуске).
Количество послдних сохраненных бэкапов:
```
FORM_APP_LOCAL_DB_BACKUP_LIMITS=3
```

22
app.R
View File

@@ -18,6 +18,7 @@ box::use(
modules/data_validation,
app/forms,
app/tasks,
app/logs,
modules/data_manipulations[is_this_empty_value]
)
@@ -65,8 +66,8 @@ ui <- page_sidebar(
# downloadButton("downloadDocx", "get .docx (test only)"),
uiOutput("status_message"),
textOutput("status_message2"),
uiOutput("display_log"),
actionButton("tasks-display_task_modal", "Задачи: нет активных", icon("list-check")),
uiOutput("logs-display_log"),
position = "left",
open = list(mobile = "always"),
popover(
@@ -164,18 +165,21 @@ server <- function(input, output, session) {
if (showing_buttons) {
tagList(
br(),
strong("Импорт и экспорт данных для выбранной схемы:"),
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
),
strong("Дополнительные опции:"),
verticalLayout(
actionButton("logs-show_last_actions", "Все действия", icon("scroll", lib = "font-awesome"), style = "width: 250px; margin-top: 10px"),
fluid = FALSE
)
)
}
})
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# REACTIVE VALUES =================================
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -253,7 +257,6 @@ server <- function(input, output, session) {
hr(),
"Для начала работы нужно создать новую запись или загрузить существующую!",
hr(),
# сво
# загрузка панели для работы с базой данных
uiOutput("admin_buttons_panel")
)
@@ -280,6 +283,7 @@ server <- function(input, output, session) {
output$base_data <- renderUI({
if (main_form_is_empty() == "main_menu") {
con <- db$make_db_connection(scheme(),"base_data")
on.exit(db$close_db_connection(con, "base_data"), add = TRUE)
@@ -292,13 +296,13 @@ server <- function(input, output, session) {
# задачи на сегодня
if ("tasks" %in% DBI::dbListTables(con)) {
tasks_count <- DBI::dbGetQuery(con, glue::glue("SELECT COUNT (task_id) FROM tasks WHERE task_status = 'active'")) |>
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())}")) |>
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())}")) |>
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()
} else {
@@ -713,6 +717,7 @@ server <- function(input, output, session) {
mhcs = mhcs,
ns = NS(values$nested_form_id)
)
} else {
utils$clean_forms(values$nested_form_id, mhcs(), NS(values$nested_form_id))
}
@@ -1363,6 +1368,9 @@ server <- function(input, output, session) {
# TASKS ---------------------------------------
tasks$server("tasks", values, scheme, mhcs)
# SHOW LOGS -----------------------------------
logs$server("logs", values, scheme, mhcs)
}

129
app/logs.R Normal file
View File

@@ -0,0 +1,129 @@
box::use(
shiny[...],
bslib[...]
)
options(box.path = here::here())
box::use(
modules/db,
modules/utils,
app/forms
)
#' @export
server <- function(id, values, scheme, mhcs) {
ns <- NS(id)
moduleServer(id, function(input, output, session) {
# отображение DT-таблицы со списком последних действий
observeEvent(input$show_last_actions, {
con <- db$make_db_connection(scheme(),"show_last_actions")
on.exit(db$close_db_connection(con, "show_last_actions"), add = TRUE)
log_df <- DBI::dbReadTable(con, "log")
# новые записи вначале, формат даты с временем
log_df <- log_df |>
dplyr::arrange(dplyr::desc(date)) |>
dplyr::mutate(date = format(as.POSIXct(date), "%d.%m.%Y %H:%M"))
output$dt_logs <- DT::renderDataTable(
DT::datatable(
log_df,
# caption = 'Table 1: This is a simple caption for the table.',
rownames = FALSE,
colnames = logs_colnames,
extensions = c('KeyTable', "FixedColumns"),
# editable = 'cell',
class = 'cell-border stripe',
selection = "single",
options = list(
# dom = 'tipf',
scrollX = TRUE,
fixedColumns = list(leftColumns = 1),
keys = TRUE,
autoWidth = TRUE,
columnDefs = list(
list(width = "150px", targets = c(0,6)),
list(width = "110px", targets = c(1:4))
)
)
)
)
showModal(modalDialog(
DT::dataTableOutput(ns("dt_logs")),
size = "xl",
# footer = tagList(
# actionButton("nested_form_dt_save", "сохранить изменения")
# ),
easyClose = TRUE
))
})
# observe({
# print(input$dt_logs_rows_selected)
# })
output$display_log <- renderUI({
req(values$main_key)
# получение логов
con <- db$make_db_connection(scheme(),"display_log")
on.exit(db$close_db_connection(con, "display_log"), add = TRUE)
query <- sprintf("SELECT * FROM \"log\" WHERE key = '%s'", values$main_key)
log_df_for_id <- DBI::dbGetQuery(con, query)
if (nrow(log_df_for_id) > 0) {
lines <- log_df_for_id |>
dplyr::mutate(
date = as.POSIXct(date),
date = date + lubridate::hours(3), # fix datetime
date_day = as.Date(date)
) |>
dplyr::mutate(cons_actions = dplyr::consecutive_id(action, user)) |>
dplyr::mutate(n_actions = dplyr::row_number(), .by = c(cons_actions, user, action, date_day)) |>
dplyr::slice(which.max(n_actions), .by = c(user, action, date_day)) |>
dplyr::arrange(date) |>
dplyr::mutate(string_to_print = sprintf(
"<b>[%s %s]</b> %s: %s (%s)",
format(date, "%d.%m.%y"),
format(date, "%H:%M"),
user,
action,
n_actions
)) |>
dplyr::pull(string_to_print) |>
paste(collapse = "</br>")
} else {
lines <- ""
}
div(
strong("Последние действия:"),
br(),
HTML(lines),
style = "font-size:10px;"
)
})
})
}
logs_colnames <- c(
"время" = "date",
"пользователь" = "user",
"приложение" = "app_id",
"версия" = "app_ver",
"ip" = "remote_addr",
"ID записи" = "key",
"действие" = "action"
)

View File

@@ -1,4 +1,3 @@
box::use(
shiny[...],
bslib[...]
@@ -239,7 +238,6 @@ server <- function(id, values, scheme, mhcs) {
date_cols <- c("task_datetime_created", "task_datetime_completed", "task_datetime_last_updated", "task_due_date")
date_cols <- which(colnames(values$tasks_data) %in% date_cols)
output$dt_tasks <- DT::renderDataTable(
DT::datatable(
values$tasks_data,
@@ -438,13 +436,11 @@ update_task_button_count <- function(con, values, ns) {
inputID <- "display_task_modal"
if (!missing(ns)) inputID <- ns(inputID)
# если ключ не определен - выход из функции
if (is.null(values$main_key)) {
updateActionButton(inputId = inputID, label = "Задачи")
return()
}
# при наличии таблицы - полу

View File

@@ -10,6 +10,7 @@ make_db_connection = function(scheme, where = "") {
scheme,
ext = "sqlite"
))
}
#' @export

View File

@@ -54,6 +54,11 @@ check_and_init_scheme = function() {
"modules/utils.R"
)
# проверка существования отслеживаемых файлов
if (!all(file.exists(files_to_watch))) {
cli::cli_abort("проверка схем: {files_to_watch[!file.exists(files_to_watch)]} is not exists")
}
scheme_names <- names(config::get()$form_schemes)
scheme_file <- paste0(config::get("form_app_configure_path"), "/schemas/", scheme_names, ".xlsx")
scheme_file <- stats::setNames(scheme_file, scheme_names)

BIN
test.xlsx Normal file

Binary file not shown.