Compare commits
5 Commits
f26d792b8b
...
b5154bf9be
Author | SHA1 | Date |
---|---|---|
soukainna | b5154bf9be | |
soukainna | 96823f3289 | |
soukainna | 93cab33fb9 | |
soukainna | d5bc764ef3 | |
soukainna | 1aeb6d50ef |
|
@ -59,7 +59,10 @@ func (h *ApplicationHandler) VehiclesManagementOverview(w http.ResponseWriter, r
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> modifyVehicle
|
||||||
sort.Sort(sorting.VehiclesByLicencePlate(vehicles))
|
sort.Sort(sorting.VehiclesByLicencePlate(vehicles))
|
||||||
sort.Sort(sorting.BookingsByStartdate(bookings))
|
sort.Sort(sorting.BookingsByStartdate(bookings))
|
||||||
h.Renderer.VehiclesManagementOverview(w, r, vehicles, vehicles_map, bookings)
|
h.Renderer.VehiclesManagementOverview(w, r, vehicles, vehicles_map, bookings)
|
||||||
|
@ -190,36 +193,10 @@ func (h *ApplicationHandler) VehiclesFleetDisplay(w http.ResponseWriter, r *http
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
|
|
||||||
// fmt.Println("lol")
|
|
||||||
// }
|
|
||||||
// fmt.Println(resp.Vehicle.ToStorageType().Bookings)
|
|
||||||
h.Renderer.VehiclesFleetDisplay(w, r, resp.Vehicle.ToStorageType())
|
h.Renderer.VehiclesFleetDisplay(w, r, resp.Vehicle.ToStorageType())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request) {
|
|
||||||
vars := mux.Vars(r)
|
|
||||||
vehicleid := vars["vehicleid"]
|
|
||||||
|
|
||||||
if r.Method == "POST" {
|
|
||||||
w.WriteHeader(http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
request := &fleets.GetVehicleRequest{
|
|
||||||
Vehicleid: vehicleid,
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := h.services.GRPC.Fleets.GetVehicle(context.TODO(), request)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
h.Renderer.VehiclesFleetUpdate(w, r, resp.Vehicle.ToStorageType())
|
|
||||||
}
|
|
||||||
|
|
||||||
func filterVehicle(r *http.Request, v *fleets.Vehicle) bool {
|
func filterVehicle(r *http.Request, v *fleets.Vehicle) bool {
|
||||||
g := r.Context().Value(identification.GroupKey)
|
g := r.Context().Value(identification.GroupKey)
|
||||||
if g == nil {
|
if g == nil {
|
||||||
|
@ -593,3 +570,87 @@ func (h *ApplicationHandler) UnbookingVehicle(w http.ResponseWriter, r *http.Req
|
||||||
}
|
}
|
||||||
h.Renderer.UnbookingVehicle(w, r, resp.Booking.ToStorageType())
|
h.Renderer.UnbookingVehicle(w, r, resp.Booking.ToStorageType())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////UpdateVehicle///////////////////////
|
||||||
|
|
||||||
|
func (h *ApplicationHandler) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
vehicleID := vars["vehicleid"]
|
||||||
|
request := &fleets.GetVehicleRequest{
|
||||||
|
Vehicleid: vehicleID,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.Fleets.GetVehicle(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
namespaceV := resp.Vehicle.Namespace
|
||||||
|
//typeV := resp.Vehicle.Type
|
||||||
|
administratorsV := resp.Vehicle.Administrators
|
||||||
|
|
||||||
|
if r.Method == "POST" {
|
||||||
|
fmt.Print(r.FormValue("vehicle_type"))
|
||||||
|
if err := r.ParseForm(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dataMap := map[string]any{}
|
||||||
|
if v := r.FormValue("name"); v != "" {
|
||||||
|
dataMap["name"] = v
|
||||||
|
}
|
||||||
|
if v := r.FormValue("address"); v != "" {
|
||||||
|
var address map[string]any
|
||||||
|
err := json.Unmarshal([]byte(v), &address)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dataMap["address"] = address
|
||||||
|
}
|
||||||
|
if v := r.FormValue("informations"); v != "" {
|
||||||
|
dataMap["informations"] = v
|
||||||
|
}
|
||||||
|
if v := r.FormValue("licence_plate"); v != "" {
|
||||||
|
dataMap["licence_plate"] = v
|
||||||
|
}
|
||||||
|
if v := r.FormValue("automatic"); v != "" {
|
||||||
|
fmt.Println(v)
|
||||||
|
dataMap["automatic"] = (v == "on")
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := structpb.NewValue(dataMap)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
request := &fleets.UpdateVehicleRequest{
|
||||||
|
Vehicle: &fleets.Vehicle{
|
||||||
|
Id: vehicleID,
|
||||||
|
Namespace: namespaceV,
|
||||||
|
Type: r.FormValue("type"),
|
||||||
|
Administrators: administratorsV,
|
||||||
|
Data: data.GetStructValue(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.Fleets.UpdateVehicle(context.TODO(), request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/fleet/%s", resp.Vehicle.Id), http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
vehicles_types := h.config.GetStringSlice("modules.fleets.vehicle_types")
|
||||||
|
h.Renderer.VehiclesFleetUpdate(w, r, resp.Vehicle.ToStorageType(), vehicles_types)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,12 @@ func (renderer *Renderer) VehiclesFleetDisplay(w http.ResponseWriter, r *http.Re
|
||||||
renderer.Render("fleet display vehicle", w, r, files, state)
|
renderer.Render("fleet display vehicle", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request, vehicle any) {
|
func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request, vehicle any, vehicle_types []string) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.fleet_update.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.fleet_update.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
||||||
state.ViewState = map[string]any{
|
state.ViewState = map[string]any{
|
||||||
"vehicle": vehicle,
|
"vehicle": vehicle,
|
||||||
|
"vehicle_types": vehicle_types,
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.Render("fleet display vehicle", w, r, files, state)
|
renderer.Render("fleet display vehicle", w, r, files, state)
|
||||||
|
|
Loading…
Reference in New Issue