feat: возможность отражения информации действий по базам данных

This commit is contained in:
2026-06-13 18:26:53 +03:00
parent 835f053584
commit 0c9dda215d
4 changed files with 119 additions and 3 deletions

12
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,12 +165,16 @@ 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
)
)
}
@@ -1363,6 +1368,9 @@ server <- function(input, output, session) {
# TASKS ---------------------------------------
tasks$server("tasks", values, scheme, mhcs)
# SHOW LOGS -----------------------------------
logs$server("logs", values, scheme, mhcs)
}

View File

@@ -17,5 +17,113 @@ server <- function(id, values, scheme, mhcs) {
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

@@ -238,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,

View File

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