feat: vis update

This commit is contained in:
2026-04-23 18:04:53 +03:00
parent fd5a7927cb
commit c8da651e72
2 changed files with 184 additions and 59 deletions

View File

@@ -24,6 +24,27 @@ server <- function(id, values, scheme, mhcs) {
# })
# functions -------------------
## new tasks ----------------
get_default_task <- function() {
tibble::tibble(
task_id = paste0(format(Sys.time(), "%Y%m%d%H%M%S"), "_", values$main_key),
task_main_key = values$main_key,
task_status = "active",
task_title = "НОВАЯ ЗАДАЧА",
task_description = "",
task_due_date = NA,
task_user_created = values$current_user,
task_datetime_created = Sys.time(),
task_user_last_updated = NA,
task_datetime_last_updated = NA,
task_user_completed = NA,
task_datetime_completed = NA
)
}
# logic ---------------------
## modal fun -----
show_modal_for_tasks <- function() {
if (!is.null(values$tasks_data)) {
@@ -82,26 +103,6 @@ server <- function(id, values, scheme, mhcs) {
))
}
## new tasks ----------------
get_default_task <- function() {
tibble::tibble(
task_id = paste0(format(Sys.time(), "%Y%m%d%H%M%S"), "_", values$main_key),
task_main_key = values$main_key,
task_status = "active",
task_title = "НОВАЯ ЗАДАЧА",
task_description = "",
task_due_date = NA,
task_user_created = values$current_user,
task_datetime_created = Sys.time(),
task_user_last_updated = NA,
task_datetime_last_updated = NA,
task_user_completed = NA,
task_datetime_completed = NA
)
}
# button logic ---------------------
## отображение окна -----------------
observeEvent(input$display_task_modal, {
@@ -217,23 +218,41 @@ server <- function(id, values, scheme, mhcs) {
## show DT --------------------------
observeEvent(input$tasks_DT_VIEW, {
rename_cols <- tasks_colnames[tasks_colnames %in% colnames(values$tasks_data)]
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,
caption = 'Table 1: This is a simple caption for the table.',
rownames = FALSE,
# colnames = col_types |> dplyr::pull(form_id, form_label),
colnames = rename_cols,
extensions = c('KeyTable', "FixedColumns"),
# editable = 'cell',
class = 'cell-border stripe',
selection = "none",
options = list(
dom = 'tip',
scrollX = TRUE,
fixedColumns = list(leftColumns = 1),
keys = TRUE
keys = TRUE,
autoWidth = TRUE,
columnDefs = list(
list(
targets = 3:4,
width = '200px',
render = htmlwidgets::JS(
"function(data, type, row, meta) {",
"return type === 'display' && data.length > 20 ?",
"'<span title=\"' + data + '\">' + data.substr(0, 20) + '...</span>' : data;",
"}")
)
)
)
) |>
DT::formatDate(c("task_datetime_created", "task_datetime_completed", "task_datetime_last_updated", "task_due_date"), "toLocaleDateString", params = list('ru-RU'))
DT::formatDate(date_cols, "toLocaleDateString", params = list('ru-RU'))
)
showModal(modalDialog(
@@ -283,8 +302,9 @@ server <- function(id, values, scheme, mhcs) {
show_modal_for_tasks()
})
## отображение списка задач для текущего дня ------------
observeEvent(input$show_dt_today, {
# review задач ----------------
### все активные задачи ------------
observeEvent(input$show_dt_all, {
con <- db$make_db_connection(scheme(),"display_task_modal")
on.exit(db$close_db_connection(con, "display_task_modal"), add = TRUE)
@@ -293,23 +313,61 @@ server <- function(id, values, scheme, mhcs) {
dplyr::mutate(dplyr::across(c("task_datetime_created", "task_datetime_last_updated", "task_datetime_completed"), as.POSIXct)) |>
dplyr::mutate(dplyr::across(c("task_due_date"), as.Date))
display_tasks_dt_review()
})
### задачи для текущего дня ------------
observeEvent(input$show_dt_today, {
con <- db$make_db_connection(scheme(),"display_task_modal")
on.exit(db$close_db_connection(con, "display_task_modal"), add = TRUE)
values$tasks_data <- DBI::dbGetQuery(con, glue::glue("SELECT * FROM tasks WHERE task_status = 'active' AND task_due_date = {as.integer(Sys.Date())}")) |>
dplyr::mutate(dplyr::across(c("task_datetime_created", "task_datetime_last_updated", "task_datetime_completed"), as.POSIXct)) |>
dplyr::mutate(dplyr::across(c("task_due_date"), as.Date))
display_tasks_dt_review()
})
### modal -----
display_tasks_dt_review <- function() {
values$tasks_data <- values$tasks_data |>
dplyr::select(task_id:task_datetime_last_updated)
rename_cols <- tasks_colnames[tasks_colnames %in% colnames(values$tasks_data)]
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_todays_tasks <- DT::renderDataTable(
DT::datatable(
values$tasks_data,
caption = 'Table 1: This is a simple caption for the table.',
rownames = FALSE,
# colnames = col_types |> dplyr::pull(form_id, form_label),
extensions = c('KeyTable', "FixedColumns"),
colnames = rename_cols,
extensions = c("FixedColumns"),
# editable = 'cell',
selection = "single",
options = list(
dom = 'tip',
scrollX = TRUE,
fixedColumns = list(leftColumns = 1),
keys = TRUE
autoWidth = TRUE,
columnDefs = list(
list(
targets = 3:4,
width = '200px',
render = htmlwidgets::JS(
"function(data, type, row, meta) {",
"return type === 'display' && data.length > 20 ?",
"'<span title=\"' + data + '\">' + data.substr(0, 20) + '...</span>' : data;",
"}")
)
)
)
) |>
DT::formatDate(c("task_datetime_created", "task_datetime_completed", "task_datetime_last_updated", "task_due_date"), "toLocaleDateString", params = list('ru-RU'))
DT::formatDate(date_cols, "toLocaleDateString", params = list('ru-RU'))
)
showModal(modalDialog(
@@ -321,18 +379,19 @@ server <- function(id, values, scheme, mhcs) {
easyClose = TRUE
))
})
}
### jump to main_key ---------
observeEvent(input$jump_to_main_key, {
if (is.null(input$dt_todays_tasks_rows_selected)) {
showNotification("необходимо выбрать задачу", type = "error")
} else {
# get key
new_main_key <- values$tasks_data[input$dt_todays_tasks_rows_selected,]$task_main_key
values$main_key <- new_main_key
showNotification("TODO: если ключа нет в таблице?!", type = "warning", duration = NULL)
removeModal()
@@ -360,4 +419,19 @@ update_task_button_count <- function(con, values, ns) {
}
}
}
}
tasks_colnames <- c(
"id задачи" = "task_id",
"id записи" = "task_main_key",
"статус" = "task_status",
"задача" = "task_title",
"описание" = "task_description",
"срок выполнения" = "task_due_date",
"создана" = "task_user_created",
"дата создания" = "task_datetime_created",
"обновлено" = "task_user_last_updated",
"дата обновления" = "task_datetime_last_updated",
"завершено" = "task_user_completed",
"дата выполнения" = "task_datetime_completed"
)