feat: extra properties dynamiques, filtrage meta_status et alertes retard
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 2m37s
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 2m37s
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/core/utils/identification"
|
||||
@@ -22,14 +23,37 @@ func (h *Handler) VehiclesManagementOverviewHTTPHandler() http.HandlerFunc {
|
||||
groupID = group.ID
|
||||
}
|
||||
|
||||
result, err := h.applicationHandler.GetVehiclesManagementOverview(r.Context(), groupID)
|
||||
// Extract tab and filter parameters from query
|
||||
tab := r.URL.Query().Get("tab")
|
||||
vehicleType := r.URL.Query().Get("vehicle_type")
|
||||
status := r.URL.Query().Get("status")
|
||||
if _, hasStatus := r.URL.Query()["status"]; !hasStatus {
|
||||
status = "meta:open,active"
|
||||
}
|
||||
dateStart := r.URL.Query().Get("date_start")
|
||||
dateEnd := r.URL.Query().Get("date_end")
|
||||
vType := r.URL.Query().Get("v_type")
|
||||
vStatus := r.URL.Query().Get("v_status")
|
||||
|
||||
result, err := h.applicationHandler.GetVehiclesManagementOverview(r.Context(), groupID, vehicleType, status, dateStart, dateEnd, vType, vStatus)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error retrieving vehicles management overview")
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
h.renderer.VehiclesManagementOverview(w, r, result.Vehicles, result.VehiclesMap, result.DriversMap, result.Bookings)
|
||||
filters := map[string]string{
|
||||
"vehicle_type": vehicleType,
|
||||
"status": status,
|
||||
"date_start": dateStart,
|
||||
"date_end": dateEnd,
|
||||
"v_type": vType,
|
||||
"v_status": vStatus,
|
||||
}
|
||||
|
||||
vehicleTypes, _ := h.applicationHandler.GetVehicleTypes(r.Context())
|
||||
|
||||
h.renderer.VehiclesManagementOverview(w, r, result.Vehicles, result.VehiclesMap, result.DriversMap, result.Bookings, filters, vehicleTypes, tab)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +70,7 @@ func (h *Handler) VehiclesManagementBookingsListHTTPHandler() http.HandlerFunc {
|
||||
status := r.URL.Query().Get("status")
|
||||
dateStart := r.URL.Query().Get("date_start")
|
||||
dateEnd := r.URL.Query().Get("date_end")
|
||||
vehicleType := r.URL.Query().Get("vehicle_type")
|
||||
|
||||
// Default to last month if no dates specified
|
||||
if dateStart == "" {
|
||||
@@ -55,7 +80,7 @@ func (h *Handler) VehiclesManagementBookingsListHTTPHandler() http.HandlerFunc {
|
||||
dateEnd = time.Now().Format("2006-01-02")
|
||||
}
|
||||
|
||||
result, err := h.applicationHandler.GetVehiclesManagementBookingsList(r.Context(), groupID, status, dateStart, dateEnd)
|
||||
result, err := h.applicationHandler.GetVehiclesManagementBookingsList(r.Context(), groupID, status, dateStart, dateEnd, vehicleType)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error retrieving vehicles management bookings list")
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
@@ -64,12 +89,15 @@ func (h *Handler) VehiclesManagementBookingsListHTTPHandler() http.HandlerFunc {
|
||||
|
||||
// Prepare filters map for template
|
||||
filters := map[string]string{
|
||||
"status": status,
|
||||
"date_start": dateStart,
|
||||
"date_end": dateEnd,
|
||||
"status": status,
|
||||
"date_start": dateStart,
|
||||
"date_end": dateEnd,
|
||||
"vehicle_type": vehicleType,
|
||||
}
|
||||
|
||||
h.renderer.VehiclesManagementBookingsList(w, r, result.VehiclesMap, result.DriversMap, result.Bookings, result.CacheID, filters)
|
||||
vehicleTypes, _ := h.applicationHandler.GetVehicleTypes(r.Context())
|
||||
|
||||
h.renderer.VehiclesManagementBookingsList(w, r, result.VehiclesMap, result.DriversMap, result.Bookings, result.CacheID, filters, vehicleTypes)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +251,7 @@ func (h *Handler) VehicleManagementBookingDisplayHTTPHandler() http.HandlerFunc
|
||||
return
|
||||
}
|
||||
|
||||
h.renderer.VehicleManagementBookingDisplay(w, r, result.Booking, result.Vehicle, result.Beneficiary, result.Group, result.Documents, result.FileTypesMap, result.Alternatives)
|
||||
h.renderer.VehicleManagementBookingDisplay(w, r, result.Booking, result.Vehicle, result.Beneficiary, result.Group, result.Documents, result.FileTypesMap, result.Alternatives, result.ComputedExtraProperties)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,11 +392,19 @@ func (h *Handler) VehicleManagementUpdateBookingStatusHTTPHandler() http.Handler
|
||||
newStatus := r.FormValue("new_status")
|
||||
comment := r.FormValue("comment")
|
||||
|
||||
// Collect extra properties from prop_* form fields
|
||||
extraProperties := map[string]string{}
|
||||
for key, values := range r.Form {
|
||||
if strings.HasPrefix(key, "prop_") && len(values) > 0 {
|
||||
extraProperties[strings.TrimPrefix(key, "prop_")] = values[0]
|
||||
}
|
||||
}
|
||||
|
||||
currentUserToken := r.Context().Value(identification.IdtokenKey).(*oidc.IDToken)
|
||||
currentUserClaims := r.Context().Value(identification.ClaimsKey).(map[string]any)
|
||||
currentGroup := r.Context().Value(identification.GroupKey)
|
||||
|
||||
err := h.applicationHandler.UpdateBookingStatus(r.Context(), bookingID, newStatus, comment, currentUserToken.Subject, currentUserClaims, currentGroup)
|
||||
err := h.applicationHandler.UpdateBookingStatus(r.Context(), bookingID, newStatus, comment, currentUserToken.Subject, currentUserClaims, currentGroup, extraProperties)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error updating booking status")
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user