2022-08-12 12:53:54 +00:00
|
|
|
package renderer
|
|
|
|
|
2022-10-30 19:11:36 +00:00
|
|
|
import (
|
2022-11-01 16:06:12 +00:00
|
|
|
"fmt"
|
2022-10-30 19:11:36 +00:00
|
|
|
"net/http"
|
|
|
|
|
2022-11-01 16:06:12 +00:00
|
|
|
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
2022-10-30 19:11:36 +00:00
|
|
|
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
|
|
|
)
|
2022-08-12 12:53:54 +00:00
|
|
|
|
|
|
|
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) {
|
2022-08-12 12:53:54 +00:00
|
|
|
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)
|
|
|
|
|
2022-08-12 12:53:54 +00:00
|
|
|
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),
|
2022-08-12 12:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2022-08-12 12:53:54 +00:00
|
|
|
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,
|
2022-08-12 12:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|