Files
homekeeper/beekeeper/R/screen_harvest.R
T
2026-07-06 19:25:38 +02:00

60 lines
1.9 KiB
R

screen_harvest_ui <- function(id) {
ns <- NS(id)
shiny::div(
section_card(NULL,
shiny::div(class = "row g-2 py-2",
shiny::div(class = "col-6",
shiny::dateInput(ns("date"), "Datum", value = Sys.Date(), language = "de", weekstart = 1)
),
shiny::div(class = "col-6",
shiny::textInput(ns("time"), "Uhrzeit",
value = format(Sys.time(), "%H:%M"), placeholder = "HH:MM")
)
)
),
section_card(NULL,
shiny::div(
class = "d-flex justify-content-between align-items-center py-3 border-bottom",
shiny::span("Gewicht (kg) *", class = "fw-semibold"),
shiny::numericInput(ns("weight_kg"), NULL, value = NA, min = 0, step = 0.1, width = "110px")
),
btn_group_row(ns, "type", "Honigsorte", HONEY_TYPES)
),
section_card(NULL,
shiny::div(class = "py-2",
shiny::textAreaInput(ns("notes"), "Notizen", rows = 2, width = "100%")
)
),
shiny::div(class = "d-grid mt-2 mb-5",
shiny::actionButton(ns("save"), "Ernte speichern", class = "btn btn-success btn-lg")
)
)
}
screen_harvest_server <- function(id, db, nav) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
type_val <- btn_group_server("type", ns, input, output, HONEY_TYPES)
observeEvent(nav$screen, {
if (nav$screen == "harvest") {
type_val(NA)
shiny::updateTextInput(session, "time", value = format(Sys.time(), "%H:%M"))
}
}, ignoreInit = TRUE)
observeEvent(input$save, {
req(nav$colony_id, !is.na(input$weight_kg), input$weight_kg > 0)
db_harvests_insert(db,
date = input$date,
weight_kg = input$weight_kg,
colony_id = nav$colony_id,
type = type_val(),
notes = input$notes,
time = input$time %||% NA
)
nav$screen <- "colony"
})
})
}