parcoursmob/renderer/vehicles.go

77 lines
2.6 KiB
Go
Raw Normal View History

package renderer
import (
2022-11-01 16:06:12 +00:00
"fmt"
"net/http"
2022-11-01 16:06:12 +00:00
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/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
}
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,
}
2022-11-01 16:06:12 +00:00
fmt.Println(mandatory_documents)
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,
"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 []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)
}