Files
gemfin-shiny/server.R
T

57 lines
3.1 KiB
R

# server.R
server <- function(input, output, session) {
# ── Globaler Navigations-Bus ───────────────────────────────────────────────
r_global <- reactiveValues(
active_tab = NULL,
nav_history = list(),
buchungen_filter = "alle",
umsatz_zeige_alle = FALSE,
umsatz_refresh = 0,
jump_to_entry_id = NULL,
jump_to_account_id = NULL,
jump_to_contact_id = NULL,
jump_to_project_id = NULL
)
# ── Tab-Wechsel ────────────────────────────────────────────────────────────
observeEvent(r_global$active_tab, ignoreInit = TRUE, {
req(r_global$active_tab)
updateTabItems(session, "tabs", selected = r_global$active_tab)
r_global$active_tab <- NULL
})
# ── Back-Button ────────────────────────────────────────────────────────────
observeEvent(input$back_btn, {
req(length(r_global$nav_history) > 0)
last <- tail(r_global$nav_history, 1)[[1]]
r_global$nav_history <- head(r_global$nav_history, -1)
updateTabItems(session, "tabs", selected = last$tab)
})
# ── Filter Buchungen ───────────────────────────────────────────────────────
observeEvent(input$filter_alle, { r_global$buchungen_filter <- "alle" })
observeEvent(input$filter_giro, { r_global$buchungen_filter <- "giro" })
observeEvent(input$filter_monat, { r_global$buchungen_filter <- "monat" })
# ── Filter Umsätze ─────────────────────────────────────────────────────────
observeEvent(input$umsatz_filter_ungebucht, { r_global$umsatz_zeige_alle <- FALSE })
observeEvent(input$umsatz_filter_alle, { r_global$umsatz_zeige_alle <- TRUE })
# ── Sync Hibiscus ──────────────────────────────────────────────────────────
observeEvent(input$umsatz_sync, {
showNotification("Sync läuft...", type = "message", duration = 3)
tryCatch({
source("sync_hibiscus.R", local = TRUE)
r_global$umsatz_refresh <- isolate(r_global$umsatz_refresh) + 1
showNotification("✓ Sync abgeschlossen", type = "message")
}, error = function(e) {
showNotification(paste("Fehler:", e$message), type = "error")
})
})
# ── Module ─────────────────────────────────────────────────────────────────
accountsServer("accounts_tab", conn, r_global)
buchungenServer("buchungen_tab", conn, r_global)
umsatzServer("umsatz_tab", conn, r_global)
}