From 71621ad8ac2c7dba84502f36c7f743a25901d88b Mon Sep 17 00:00:00 2001 From: Christian Oswald Date: Fri, 20 Mar 2026 17:32:13 +0100 Subject: [PATCH] Attachments Liste wird jetzt angezeigt und attachment in iframe --- .gitignore | 1 + R/buchungen_mod.R | 17 +++++++++++++++-- R/postings/buchungen.R | 39 +++++++++++++++++++++++++++++---------- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index ab618b4..32d201f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ .Rhistory .RData .Ruserdata +www/attachments/ diff --git a/R/buchungen_mod.R b/R/buchungen_mod.R index 9bfedcd..1ed0b9d 100644 --- a/R/buchungen_mod.R +++ b/R/buchungen_mod.R @@ -153,7 +153,6 @@ buchungenServer <- function(id, conn, aktiver_filter = reactive("alle")) { }) - ## * Attachments anzeigen ---- output$attachments_ui <- renderUI({ req(selected_trans_id()) att <- dbxSelect(conn, paste0( @@ -162,8 +161,22 @@ buchungenServer <- function(id, conn, aktiver_filter = reactive("alle")) { if (nrow(att) == 0) return(p("Keine Anhänge vorhanden.")) tagList(lapply(seq_len(nrow(att)), function(i) { + ext <- tools::file_ext(att$original_name[i]) + filename <- paste0("attachments/", att$id[i], ".", ext) + + # Observer direkt hier registrieren + observeEvent(input[[paste0("open_att_", att$id[i])]], { + showModal(modalDialog( + tags$iframe(src = filename, width = "100%", height = "600px", style = "border:none;"), + title = att$original_name[i], + size = "l", + easyClose = TRUE, + footer = modalButton("Schließen") + )) + }, ignoreInit = TRUE, once = FALSE) + div( - tags$a(att$original_name[i], href = att$path[i], target = "_blank"), + actionLink(ns(paste0("open_att_", att$id[i])), att$original_name[i]), actionLink(ns(paste0("del_att_", att$id[i])), "✕", style = "color:red; margin-left:8px;") ) diff --git a/R/postings/buchungen.R b/R/postings/buchungen.R index 78115e6..b1d0696 100644 --- a/R/postings/buchungen.R +++ b/R/postings/buchungen.R @@ -5,18 +5,29 @@ read_buch_tabelle <- function(conn, trans_id = NULL){ } else { postings <- tbl(conn, "postings") } - entries <- tbl(conn, "entries") - accounts <- tbl(conn, "accounts") - projects <- tbl(conn, "projects") - contacts <- tbl(conn, "contacts") + entries <- tbl(conn, "entries") + accounts <- tbl(conn, "accounts") + projects <- tbl(conn, "projects") + contacts <- tbl(conn, "contacts") + attachments <- tbl(conn, "attachments") + + # Anzahl Attachments pro entry_id vorberechnen + attachment_counts <- attachments %>% + group_by(entry_id) %>% + summarise(n_attachments = n(), .groups = "drop") + result <- postings |> - left_join(entries, by = c("entry_id" = "id")) |> - left_join(contacts, by = c("contact_id" = "id")) |> # contact_id jetzt verfügbar - left_join(accounts, by = c("account_id" = "id")) |> - left_join(projects, by = c("project_id" = "id")) |> - select(id, valuta, account_name, projektname, display_name, amount, entry_id) |> + left_join(entries, by = c("entry_id" = "id")) |> + left_join(contacts, by = c("contact_id" = "id")) |> + left_join(accounts, by = c("account_id" = "id")) |> + left_join(projects, by = c("project_id" = "id")) |> + left_join(attachment_counts, by = "entry_id") |> + select(id, valuta, account_name, projektname, display_name, amount, entry_id, n_attachments) |> collect() %>% - mutate(saldo = 0) %>% + mutate( + saldo = 0, + n_attachments = tidyr::replace_na(n_attachments, 0L) + ) %>% arrange(valuta, entry_id) } @@ -39,6 +50,14 @@ coldef_entries_tabelle <- list(color = color, fontWeight = "bold") # Gibt CSS-Styles zurück } ), + n_attachments = colDef( + name = "Anhänge", + filterMethod = JS("function(rows, columnId, filterValue) { + const val = parseFloat(filterValue); + if (isNaN(val)) return rows; // kein gültiger Wert → alles zeigen + return rows.filter(row => row.values[columnId] > val); + }") + ), entry_id = colDef(name ="trans_id", width = 120), saldo = colDef( name = "Saldo",