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:
@@ -170,6 +170,14 @@ func IsGuaranteedTripMotivation(globalConfig *viper.Viper) func(string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// IsPast returns true if the given time is before the current time
|
||||
func IsPast(d any) bool {
|
||||
if date, ok := d.(time.Time); ok {
|
||||
return date.Before(time.Now())
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetTemplateFuncMap returns the common template functions for rendering
|
||||
func GetTemplateFuncMap(group groupsstorage.Group, globalConfig *viper.Viper, fileStorage filestorage.FileStorage) template.FuncMap {
|
||||
return template.FuncMap{
|
||||
@@ -191,6 +199,7 @@ func GetTemplateFuncMap(group groupsstorage.Group, globalConfig *viper.Viper, fi
|
||||
"beneficiaryValidatedProfile": validatedprofile.ValidateProfile(globalConfig.Sub("modules.beneficiaries.validated_profile")),
|
||||
"solidarityDriverValidatedProfile": validatedprofile.ValidateProfile(globalConfig.Sub("modules.solidarity_transport.drivers.validated_profile")),
|
||||
"carpoolDriverValidatedProfile": validatedprofile.ValidateProfile(globalConfig.Sub("modules.organized_carpool.drivers.validated_profile")),
|
||||
"isPast": IsPast,
|
||||
"isGuaranteedTripMotivation": IsGuaranteedTripMotivation(globalConfig),
|
||||
"beneficiaryDocuments": func(id string) []filestorage.FileInfo {
|
||||
return fileStorage.List(filestorage.PREFIX_BENEFICIARIES + "/" + id)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
const vehiclesmanagementMenu = "vehicles_management"
|
||||
|
||||
func (renderer *Renderer) VehiclesManagementOverview(w http.ResponseWriter, r *http.Request, vehicles []fleetsstorage.Vehicle, vehicles_map map[string]fleetsstorage.Vehicle, driversMap map[string]mobilityaccountsstorage.Account, bookings []fleetsstorage.Booking) {
|
||||
func (renderer *Renderer) VehiclesManagementOverview(w http.ResponseWriter, r *http.Request, vehicles []fleetsstorage.Vehicle, vehicles_map map[string]fleetsstorage.Vehicle, driversMap map[string]mobilityaccountsstorage.Account, bookings []fleetsstorage.Booking, filters map[string]string, vehicleTypes []string, tab string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.overview.files")
|
||||
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
||||
state.ViewState = map[string]any{
|
||||
@@ -18,6 +18,10 @@ func (renderer *Renderer) VehiclesManagementOverview(w http.ResponseWriter, r *h
|
||||
"bookings": bookings,
|
||||
"vehicles_map": vehicles_map,
|
||||
"drivers_map": driversMap,
|
||||
"tab": tab,
|
||||
"filters": filters,
|
||||
"vehicle_types": vehicleTypes,
|
||||
"hide_date_filters": false,
|
||||
"status_management": renderer.GlobalConfig.GetString("modules.vehicles.status_management"),
|
||||
"status_options": renderer.GlobalConfig.Get("modules.vehicles.status_options"),
|
||||
}
|
||||
@@ -25,7 +29,7 @@ func (renderer *Renderer) VehiclesManagementOverview(w http.ResponseWriter, r *h
|
||||
renderer.Render("fleet overview", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) VehiclesManagementBookingsList(w http.ResponseWriter, r *http.Request, vehiclesMap map[string]fleetsstorage.Vehicle, driversMap map[string]mobilityaccountsstorage.Account, bookings []fleetsstorage.Booking, cacheid string, filters map[string]string) {
|
||||
func (renderer *Renderer) VehiclesManagementBookingsList(w http.ResponseWriter, r *http.Request, vehiclesMap map[string]fleetsstorage.Vehicle, driversMap map[string]mobilityaccountsstorage.Account, bookings []fleetsstorage.Booking, cacheid string, filters map[string]string, vehicleTypes []string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.bookings_list.files")
|
||||
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
||||
state.ViewState = map[string]any{
|
||||
@@ -34,6 +38,7 @@ func (renderer *Renderer) VehiclesManagementBookingsList(w http.ResponseWriter,
|
||||
"drivers_map": driversMap,
|
||||
"cacheid": cacheid,
|
||||
"filters": filters,
|
||||
"vehicle_types": vehicleTypes,
|
||||
"status_management": renderer.GlobalConfig.GetString("modules.vehicles.status_management"),
|
||||
"status_options": renderer.GlobalConfig.Get("modules.vehicles.status_options"),
|
||||
}
|
||||
@@ -82,19 +87,21 @@ func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Req
|
||||
renderer.Render("fleet display vehicle", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter, r *http.Request, booking any, vehicle any, beneficiary any, group any, documents []filestorage.FileInfo, file_types_map map[string]string, alternative_vehicles []any) {
|
||||
func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter, r *http.Request, booking any, vehicle any, beneficiary any, group any, documents []filestorage.FileInfo, file_types_map map[string]string, alternative_vehicles []any, computed_extra_properties map[string]string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.booking_display.files")
|
||||
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"booking": booking,
|
||||
"vehicle": vehicle,
|
||||
"beneficiary": beneficiary,
|
||||
"group": group,
|
||||
"documents": documents,
|
||||
"file_types_map": file_types_map,
|
||||
"alternative_vehicles": alternative_vehicles,
|
||||
"status_management": renderer.GlobalConfig.GetString("modules.vehicles.status_management"),
|
||||
"status_options": renderer.GlobalConfig.Get("modules.vehicles.status_options"),
|
||||
"booking": booking,
|
||||
"vehicle": vehicle,
|
||||
"beneficiary": beneficiary,
|
||||
"group": group,
|
||||
"documents": documents,
|
||||
"file_types_map": file_types_map,
|
||||
"alternative_vehicles": alternative_vehicles,
|
||||
"status_management": renderer.GlobalConfig.GetString("modules.vehicles.status_management"),
|
||||
"status_options": renderer.GlobalConfig.Get("modules.vehicles.status_options"),
|
||||
"booking_extra_properties": renderer.GlobalConfig.Get("modules.vehicles.booking_extra_properties"),
|
||||
"computed_extra_properties": computed_extra_properties,
|
||||
}
|
||||
|
||||
renderer.Render("vehicles search", w, r, files, state)
|
||||
|
||||
@@ -10,6 +10,31 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// resolveStatusLabel returns the display label for a manual status name
|
||||
func resolveStatusLabel(statusOptions interface{}, manualStatus string) string {
|
||||
switch opts := statusOptions.(type) {
|
||||
case []map[string]any:
|
||||
for _, opt := range opts {
|
||||
if name, _ := opt["name"].(string); name == manualStatus {
|
||||
if label, ok := opt["label"].(string); ok {
|
||||
return label
|
||||
}
|
||||
}
|
||||
}
|
||||
case []interface{}:
|
||||
for _, opt := range opts {
|
||||
if optMap, ok := opt.(map[string]interface{}); ok {
|
||||
if name, _ := optMap["name"].(string); name == manualStatus {
|
||||
if label, ok := optMap["label"].(string); ok {
|
||||
return label
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return manualStatus
|
||||
}
|
||||
|
||||
func (r *XLSXRenderer) VehicleBookings(w http.ResponseWriter, bookings []fleetsstorage.Booking, vehiclesMap map[string]fleetsstorage.Vehicle, driversMap map[string]mobilityaccountsstorage.Account) {
|
||||
// Create Excel spreadsheet
|
||||
spreadsheet := r.NewSpreadsheet("Réservations véhicules")
|
||||
@@ -55,6 +80,10 @@ func (r *XLSXRenderer) VehicleBookings(w http.ResponseWriter, bookings []fleetss
|
||||
|
||||
spreadsheet.SetHeaders(headers)
|
||||
|
||||
// Read status management config
|
||||
isManualStatus := r.Config.GetString("modules.vehicles.status_management") == "manual"
|
||||
statusOptions := r.Config.Get("modules.vehicles.status_options")
|
||||
|
||||
// Add data rows
|
||||
for _, booking := range bookings {
|
||||
vehicle := vehiclesMap[booking.Vehicleid]
|
||||
@@ -69,6 +98,8 @@ func (r *XLSXRenderer) VehicleBookings(w http.ResponseWriter, bookings []fleetss
|
||||
status := ""
|
||||
if booking.Deleted {
|
||||
status = "Annulé"
|
||||
} else if isManualStatus {
|
||||
status = resolveStatusLabel(statusOptions, booking.ManualStatus)
|
||||
} else {
|
||||
switch booking.Status() {
|
||||
case 1:
|
||||
@@ -216,6 +247,10 @@ func (r *XLSXRenderer) VehicleBookingsAdmin(w http.ResponseWriter, bookings []fl
|
||||
|
||||
spreadsheet.SetHeaders(headers)
|
||||
|
||||
// Read status management config
|
||||
isManualStatusAdmin := r.Config.GetString("modules.vehicles.status_management") == "manual"
|
||||
statusOptionsAdmin := r.Config.Get("modules.vehicles.status_options")
|
||||
|
||||
// Add data rows
|
||||
for _, booking := range bookings {
|
||||
// Get vehicle from map
|
||||
@@ -243,6 +278,8 @@ func (r *XLSXRenderer) VehicleBookingsAdmin(w http.ResponseWriter, bookings []fl
|
||||
status := ""
|
||||
if booking.Deleted {
|
||||
status = "Annulé"
|
||||
} else if isManualStatusAdmin {
|
||||
status = resolveStatusLabel(statusOptionsAdmin, booking.ManualStatus)
|
||||
} else {
|
||||
switch booking.Status() {
|
||||
case 1:
|
||||
|
||||
Reference in New Issue
Block a user