diff --git a/handlers/application/vehicles-management.go b/handlers/application/vehicles-management.go index 761b127..79dc247 100644 --- a/handlers/application/vehicles-management.go +++ b/handlers/application/vehicles-management.go @@ -10,6 +10,7 @@ import ( "git.coopgo.io/coopgo-apps/parcoursmob/utils/identification" "git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting" + filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi" fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage" groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi" @@ -303,5 +304,8 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite return } - h.Renderer.VehicleManagementBookingDisplay(w, r, booking, booking.Vehicle, beneficiaryresp.Account.ToStorageType(), groupresp.Group.ToStorageType()) + documents := h.filestorage.List(filestorage.PREFIX_BOOKINGS + "/" + bookingid) + file_types_map := h.config.GetStringMapString("storage.files.file_types") + + h.Renderer.VehicleManagementBookingDisplay(w, r, booking, booking.Vehicle, beneficiaryresp.Account.ToStorageType(), groupresp.Group.ToStorageType(), documents, file_types_map) } diff --git a/handlers/application/vehicles.go b/handlers/application/vehicles.go index 5755614..5c4a501 100644 --- a/handlers/application/vehicles.go +++ b/handlers/application/vehicles.go @@ -3,16 +3,20 @@ package application import ( "context" "fmt" + "io" "net/http" "sort" + "strings" "time" "git.coopgo.io/coopgo-apps/parcoursmob/utils/identification" "git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting" + filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi" groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi" "git.coopgo.io/coopgo-platform/groups-management/storage" mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi" + mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" "github.com/coreos/go-oidc" "github.com/google/uuid" "github.com/gorilla/mux" @@ -23,7 +27,9 @@ import ( func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Request) { r.ParseForm() - var beneficiary any + var beneficiary mobilityaccountsstorage.Account + + beneficiarydocuments := []filestorage.FileInfo{} vehicles := []any{} searched := false @@ -65,6 +71,8 @@ func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Reques vehicles = append(vehicles, v) } } + + beneficiarydocuments = h.filestorage.List(filestorage.PREFIX_BENEFICIARIES + "/" + beneficiary.ID) } accounts, err := h.beneficiaries(r) @@ -76,7 +84,10 @@ func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Reques sort.Sort(sorting.BeneficiariesByName(accounts)) - h.Renderer.VehiclesSearch(w, r, accounts, searched, vehicles, beneficiary, r.FormValue("startdate"), r.FormValue("enddate")) + mandatory_documents := h.config.GetStringSlice("modules.fleets.booking_documents.mandatory") + file_types_map := h.config.GetStringMapString("storage.files.file_types") + + h.Renderer.VehiclesSearch(w, r, accounts, searched, vehicles, beneficiary, r.FormValue("startdate"), r.FormValue("enddate"), mandatory_documents, file_types_map, beneficiarydocuments) } func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) { @@ -111,7 +122,7 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) { vehicleid := vars["vehicleid"] beneficiaryid := vars["beneficiaryid"] - r.ParseForm() + r.ParseMultipartForm(10 * 1024 * 1024) start := r.FormValue("startdate") end := r.FormValue("enddate") @@ -153,6 +164,42 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) { Booking: booking, } + fmt.Println(r.FormFile("doc-identity_proof")) + for _, v := range h.config.GetStringSlice("modules.fleets.booking_documents.mandatory") { + existing_file := r.FormValue("type-" + v) + if existing_file == "" { + file, header, err := r.FormFile("doc-" + v) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusBadRequest) + w.Write([]byte("Document manquant : " + v)) + return + } + defer file.Close() + + fileid := uuid.NewString() + + metadata := map[string]string{ + "type": v, + "name": header.Filename, + } + + if err := h.filestorage.Put(file, filestorage.PREFIX_BOOKINGS, fmt.Sprintf("%s/%s_%s", booking.Id, fileid, header.Filename), header.Size, metadata); err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } + } else { + path := strings.Split(existing_file, "/") + + if err := h.filestorage.Copy(existing_file, fmt.Sprintf("%s/%s/%s", filestorage.PREFIX_BOOKINGS, booking.Id, path[len(path)-1])); err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } + } + } + _, err = h.services.GRPC.Fleets.CreateBooking(context.TODO(), request) if err != nil { fmt.Println(err) @@ -202,7 +249,10 @@ func (h ApplicationHandler) VehicleBookingDisplay(w http.ResponseWriter, r *http return } - h.Renderer.VehicleBookingDisplay(w, r, booking, booking.Vehicle, beneficiaryresp.Account.ToStorageType(), groupresp.Group.ToStorageType()) + documents := h.filestorage.List(filestorage.PREFIX_BOOKINGS + "/" + bookingid) + file_types_map := h.config.GetStringMapString("storage.files.file_types") + + h.Renderer.VehicleBookingDisplay(w, r, booking, booking.Vehicle, beneficiaryresp.Account.ToStorageType(), groupresp.Group.ToStorageType(), documents, file_types_map) } func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.Request) { @@ -222,3 +272,28 @@ func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http. h.Renderer.VehicleBookingsList(w, r, bookings) } + +func (h *ApplicationHandler) BookingDocumentDownload(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + bookingid := vars["bookingid"] + document := vars["document"] + + fmt.Println(fmt.Sprintf("%s/%s", bookingid, document)) + + file, info, err := h.filestorage.Get(filestorage.PREFIX_BOOKINGS, fmt.Sprintf("%s/%s", bookingid, document)) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", info.ContentType) + if _, err = io.Copy(w, file); err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } + + http.Redirect(w, r, fmt.Sprintf("/app/vehicles/bookings/%s", bookingid), http.StatusFound) + +} diff --git a/main.go b/main.go index d158e04..e01324d 100644 --- a/main.go +++ b/main.go @@ -89,12 +89,14 @@ func main() { application.HandleFunc("/vehicles/bookings/", applicationHandler.VehiclesBookingsList) application.HandleFunc("/vehicles/bookings/{bookingid}", applicationHandler.VehicleBookingDisplay) application.HandleFunc("/vehicles/v/{vehicleid}/b/{beneficiaryid}", applicationHandler.Book) + application.HandleFunc("/vehicles/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload) application.HandleFunc("/vehicles-management/", applicationHandler.VehiclesManagementOverview) application.HandleFunc("/vehicles-management/fleet/add", applicationHandler.VehiclesFleetAdd) application.HandleFunc("/vehicles-management/fleet/{vehicleid}", applicationHandler.VehiclesFleetDisplay) application.HandleFunc("/vehicles-management/fleet/{vehicleid}/update", applicationHandler.VehiclesFleetUpdate) application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList) application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay) + application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload) application.HandleFunc("/agenda/", applicationHandler.AgendaHome) application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent) application.HandleFunc("/agenda/{eventid}", applicationHandler.AgendaDisplayEvent) diff --git a/renderer/vehicle-management.go b/renderer/vehicle-management.go index 7b7533f..3dbd057 100644 --- a/renderer/vehicle-management.go +++ b/renderer/vehicle-management.go @@ -3,6 +3,7 @@ package renderer import ( "net/http" + filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage" ) @@ -59,14 +60,16 @@ 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) { +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) { 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, + "booking": booking, + "vehicle": vehicle, + "beneficiary": beneficiary, + "group": group, + "documents": documents, + "file_types_map": file_types_map, } renderer.Render("vehicles search", w, r, files, state) diff --git a/renderer/vehicles.go b/renderer/vehicles.go index 4ec0184..945f04a 100644 --- a/renderer/vehicles.go +++ b/renderer/vehicles.go @@ -1,14 +1,28 @@ 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 (renderer *Renderer) VehiclesSearch(w http.ResponseWriter, r *http.Request, beneficiaries []mobilityaccountsstorage.Account, searched bool, vehicles []any, beneficiary any, startdate any, enddate any) { +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{ @@ -16,12 +30,18 @@ func (renderer *Renderer) VehiclesSearch(w http.ResponseWriter, r *http.Request, "searched": searched, } + fmt.Println(mandatory_documents) + if searched { viewstate["search"] = map[string]any{ - "startdate": startdate, - "enddate": enddate, - "vehicles": vehicles, - "beneficiary": beneficiary, + "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), } } @@ -30,14 +50,16 @@ func (renderer *Renderer) VehiclesSearch(w http.ResponseWriter, r *http.Request, 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) { +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, + "booking": booking, + "vehicle": vehicle, + "beneficiary": beneficiary, + "group": group, + "documents": documents, + "file_types_map": file_types_map, } renderer.Render("vehicles search", w, r, files, state) diff --git a/themes/default/web/layouts/support/support.html b/themes/default/web/layouts/support/support.html index d54ece2..224bd63 100644 --- a/themes/default/web/layouts/support/support.html +++ b/themes/default/web/layouts/support/support.html @@ -1,10 +1,10 @@ {{define "content"}}
- Le support PARCOURSMOB est ouvert les jours ouvrés de 9h à 18h. Vous pouvez également nous joindre par email à support@parcoursmob.fr, par exemple pour nous envoyez des copies d'écran du problème que vous rencontrez. + Le support technique PARCOURSMOB est ouvert les jours ouvrés de 9h à 18h. Vous pouvez également nous joindre par email à support@parcoursmob.fr, par exemple pour nous envoyez des copies d'écran du problème que vous rencontrez.
Documents
+ {{if eq (len .ViewState.documents) 0}} +Aucun document
+ {{end}} + + + {{if gt (len .ViewState.documents) 0}} + +Type | +Nom du document | +Ajouté le | ++ Actions + | +
---|---|---|---|
+
+ {{index $.ViewState.file_types_map .Metadata.Type}}
+
+ |
+
+ {{.Metadata.Name}} + |
+ {{.LastModified.Format "02/01/2006"}} | ++ + + + | +
Ajoutez des documents pour finaliser
+Documents
+ {{if eq (len .ViewState.documents) 0}} +Aucun document
+ {{end}} + + + {{if gt (len .ViewState.documents) 0}} + +Type | +Nom du document | +Ajouté le | ++ Actions + | +
---|---|---|---|
+
+ {{index $.ViewState.file_types_map .Metadata.Type}}
+
+ |
+
+ {{.Metadata.Name}} + |
+ {{.LastModified.Format "02/01/2006"}} | ++ + + + | +