package renderer import ( "fmt" "net/http" filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" ) const vehiclesMenu = "vehicles" 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 } 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) { files := renderer.ThemeConfig.GetStringSlice("views.vehicles.search.files") state := NewState(r, renderer.ThemeConfig, vehiclesMenu) viewstate := map[string]any{ "beneficiaries": beneficiaries, "searched": searched, } fmt.Println(mandatory_documents) if searched { viewstate["search"] = map[string]any{ "startdate": startdate, "enddate": enddate, "vehicles": vehicles, "beneficiary": beneficiary, "mandatory_documents": mandatory_documents, "file_types_map": file_types_map, "beneficiary_documents": beneficiarydocuments, "documents_defaults": selectDocumentsDefaults(beneficiarydocuments, mandatory_documents), } } state.ViewState = viewstate renderer.Render("vehicles search", w, r, files, state) } 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{ "booking": booking, "vehicle": vehicle, "beneficiary": beneficiary, "group": group, "documents": documents, "file_types_map": file_types_map, } renderer.Render("vehicles search", w, r, files, state) } func (renderer *Renderer) VehicleBookingsList(w http.ResponseWriter, r *http.Request, bookings []any) { 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) }