feat: корректное обновление счетчика задач на кнопке + список просроченных задач
This commit is contained in:
34
app.R
34
app.R
@@ -222,15 +222,16 @@ server <- function(input, output, session) {
|
||||
observeEvent(main_form_is_empty(), {
|
||||
|
||||
if (main_form_is_empty() == TRUE) {
|
||||
print("fired!")
|
||||
|
||||
output$base_data <- renderUI({
|
||||
|
||||
con <- db$make_db_connection(scheme(),"base_data")
|
||||
on.exit(db$close_db_connection(con, "base_data"), add = TRUE)
|
||||
|
||||
tasks$update_task_button_count(con, values, NS("tasks"))
|
||||
|
||||
# записей в базе всего
|
||||
query <- glue::glue("SELECT COUNT ({mhcs()$get_main_key_id}) FROM main")
|
||||
records_count <- DBI::dbGetQuery(con, query) |>
|
||||
records_count <- DBI::dbGetQuery(con, glue::glue("SELECT COUNT ({mhcs()$get_main_key_id}) FROM main")) |>
|
||||
dplyr::pull()
|
||||
|
||||
# задачи на сегодня
|
||||
@@ -260,27 +261,9 @@ 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())
|
||||
)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
# buttons_to_toggle <- c(
|
||||
# "save_data_button",
|
||||
# "clean_data_button",
|
||||
# "downloadDocx",
|
||||
# "tasks-display_task_modal"
|
||||
# )
|
||||
|
||||
# purrr::walk(
|
||||
# buttons_to_toggle,
|
||||
# \(x) {
|
||||
# updateActionButton(
|
||||
# inputId = x,
|
||||
# disabled = main_form_is_empty()
|
||||
# )
|
||||
# }
|
||||
# )
|
||||
|
||||
})
|
||||
|
||||
# обновление данных схем ------
|
||||
@@ -907,11 +890,11 @@ server <- function(input, output, session) {
|
||||
|
||||
## логика: смена ключа -------
|
||||
observeEvent(values$main_key, {
|
||||
req(values$main_key)
|
||||
|
||||
con <- db$make_db_connection(scheme(),"load_data")
|
||||
on.exit(db$close_db_connection(con, "load_data"), add = TRUE)
|
||||
|
||||
if (!is.null(values$main_key)) {
|
||||
existed_main_keys <- db$get_keys_from_table("main", mhcs(), con)
|
||||
|
||||
if (values$main_key %in% existed_main_keys) {
|
||||
@@ -937,10 +920,11 @@ server <- function(input, output, session) {
|
||||
|
||||
}
|
||||
|
||||
# обновление счетичка задач
|
||||
tasks$update_task_button_count(con, values, NS("tasks"))
|
||||
|
||||
main_form_is_empty(FALSE)
|
||||
|
||||
}
|
||||
|
||||
tasks$update_task_button_count(con, values, NS("tasks"))
|
||||
removeModal()
|
||||
|
||||
})
|
||||
|
||||
24
app/tasks.R
24
app/tasks.R
@@ -329,6 +329,19 @@ server <- function(id, values, scheme, mhcs) {
|
||||
display_tasks_dt_review()
|
||||
})
|
||||
|
||||
### просроченные ------------
|
||||
observeEvent(input$show_dt_overdue, {
|
||||
|
||||
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() {
|
||||
|
||||
@@ -409,13 +422,24 @@ 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()
|
||||
}
|
||||
|
||||
if ("tasks" %in% DBI::dbListTables(con)) {
|
||||
|
||||
tasks_num <- DBI::dbGetQuery(con, glue::glue("SELECT COUNT ('task_id') FROM tasks WHERE task_main_key = '{values$main_key}' AND task_status = 'active'")) |>
|
||||
dplyr::pull()
|
||||
|
||||
if (tasks_num > 0) {
|
||||
|
||||
updateActionButton(inputId = inputID, label = paste("активных задач:", tasks_num))
|
||||
|
||||
} else {
|
||||
|
||||
updateActionButton(inputId = inputID, label = "Задачи: нет активных")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user