parcoursmob/renderer/vehicles.go

79 lines
2.9 KiB
Go
Raw Normal View History

package renderer
import (
"net/http"
2022-11-01 16:06:12 +00:00
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
"git.coopgo.io/coopgo-platform/fleets/storage"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
)
const vehiclesMenu = "vehicles"
2022-11-01 16:06:12 +00:00
func selectDocumentsDefaults(beneficiarydocuments []filestorage.FileInfo, mandatory_documents []string) map[string]string {
res := map[string]string{}
for _, v := range mandatory_documents {
for _, d := range beneficiarydocuments {
if d.Metadata["Type"] == v {
res[v] = d.Key
}
}
}
return res
}
2022-11-07 00:24:16 +00:00
func (renderer *Renderer) VehiclesSearch(w http.ResponseWriter, r *http.Request, beneficiaries []mobilityaccountsstorage.Account, searched bool, vehicles []any, beneficiary any, startdate any, enddate any, mandatory_documents []string, file_types_map map[string]string, beneficiarydocuments []filestorage.FileInfo, selected_type string, automatic bool, vehicles_types []string, admingroups map[string]any) {
files := renderer.ThemeConfig.GetStringSlice("views.vehicles.search.files")
state := NewState(r, renderer.ThemeConfig, vehiclesMenu)
viewstate := map[string]any{
2022-11-07 00:24:16 +00:00
"beneficiaries": beneficiaries,
"searched": searched,
"vehicles_types": vehicles_types,
}
if searched {
viewstate["search"] = map[string]any{
2022-11-01 16:06:12 +00:00
"startdate": startdate,
"enddate": enddate,
"vehicles": vehicles,
"beneficiary": beneficiary,
"mandatory_documents": mandatory_documents,
"file_types_map": file_types_map,
"beneficiary_documents": beneficiarydocuments,
2022-11-07 00:24:16 +00:00
"selected_type": selected_type,
"automatic": automatic,
"admingroups": admingroups,
2022-11-01 16:06:12 +00:00
"documents_defaults": selectDocumentsDefaults(beneficiarydocuments, mandatory_documents),
}
}
state.ViewState = viewstate
renderer.Render("vehicles search", w, r, files, state)
}
2022-11-01 16:06:12 +00:00
func (renderer *Renderer) VehicleBookingDisplay(w http.ResponseWriter, r *http.Request, booking any, vehicle any, beneficiary any, group any, documents []filestorage.FileInfo, file_types_map map[string]string) {
files := renderer.ThemeConfig.GetStringSlice("views.vehicles.booking_display.files")
state := NewState(r, renderer.ThemeConfig, vehiclesMenu)
state.ViewState = map[string]any{
2022-11-01 16:06:12 +00:00
"booking": booking,
"vehicle": vehicle,
"beneficiary": beneficiary,
"group": group,
"documents": documents,
"file_types_map": file_types_map,
}
renderer.Render("vehicles search", w, r, files, state)
}
2022-09-05 05:25:05 +00:00
func (renderer *Renderer) VehicleBookingsList(w http.ResponseWriter, r *http.Request, bookings []storage.Booking) {
2022-09-05 05:25:05 +00:00
files := renderer.ThemeConfig.GetStringSlice("views.vehicles.bookings_list.files")
state := NewState(r, renderer.ThemeConfig, vehiclesMenu)
state.ViewState = map[string]any{
"bookings": bookings,
}
renderer.Render("vehicles search", w, r, files, state)
}