From 0c9dda215d6eeb4f83cf7875e7f7284f57f8e20f Mon Sep 17 00:00:00 2001 From: madeliri Date: Sat, 13 Jun 2026 18:26:53 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=BE=D1=82=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B4=D0=B5=D0=B9=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=BF=D0=BE=20=D0=B1=D0=B0=D0=B7=D0=B0=D0=BC=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.R | 12 +++++- app/logs.R | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++ app/tasks.R | 1 - modules/db.R | 1 + 4 files changed, 119 insertions(+), 3 deletions(-) diff --git a/app.R b/app.R index 14d5aac..0334fca 100644 --- a/app.R +++ b/app.R @@ -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) + } diff --git a/app/logs.R b/app/logs.R index 7745a0d..c8ec345 100644 --- a/app/logs.R +++ b/app/logs.R @@ -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( + "[%s %s] %s: %s (%s)", + format(date, "%d.%m.%y"), + format(date, "%H:%M"), + user, + action, + n_actions + )) |> + dplyr::pull(string_to_print) |> + paste(collapse = "
") + + } 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" +) diff --git a/app/tasks.R b/app/tasks.R index 4d50fc7..998fca2 100644 --- a/app/tasks.R +++ b/app/tasks.R @@ -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, diff --git a/modules/db.R b/modules/db.R index 1d8f0c5..67bc71c 100644 --- a/modules/db.R +++ b/modules/db.R @@ -10,6 +10,7 @@ make_db_connection = function(scheme, where = "") { scheme, ext = "sqlite" )) + } #' @export