8 Commits

12 changed files with 264 additions and 57 deletions

View File

@@ -9,4 +9,5 @@ This new version of PARCOURSMOB brings :
- A delegation on authentication and identification to an external OpenID Connect Provider like [COOPGO Mobility Accounts](https://git.coopgo.io/coopgo-platform/mobility-accounts) - A delegation on authentication and identification to an external OpenID Connect Provider like [COOPGO Mobility Accounts](https://git.coopgo.io/coopgo-platform/mobility-accounts)
- A configurable and themeable approach of rendering web pages : the default theme is located in the folder [themes/default/](themes/default/) - A configurable and themeable approach of rendering web pages : the default theme is located in the folder [themes/default/](themes/default/)
- A modular architecture based on groups and access rights, using [COOPGO Groups Management](https://git.coopgo.io/coopgo-groups-management) - A modular architecture based on groups and access rights, using [COOPGO Groups Management](https://git.coopgo.io/coopgo-groups-management)
- A distributed cache system through [etcd](https://etcd.io/) to handle distributed state management like pagination in a cloud native way - A distributed cache system through [etcd](https://etcd.io/) to handle distributed state management like pagination in a cloud native way

12
go.mod
View File

@@ -4,11 +4,11 @@ go 1.18
// replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/ // replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/
replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/ // replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/
// replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/ replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/
replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/ // replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/
// replace git.coopgo.io/coopgo-platform/emailing => ../../coopgo-platform/emailing/ // replace git.coopgo.io/coopgo-platform/emailing => ../../coopgo-platform/emailing/
@@ -30,10 +30,10 @@ require (
) )
require ( require (
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221205162112-5feb1b720ef9 git.coopgo.io/coopgo-platform/agenda v0.0.0-20230310121901-ef3add576f86
git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15 git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205181518-91991789db9b git.coopgo.io/coopgo-platform/fleets v0.0.0-20230310144446-feb935f8bf4e
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221205161801-9705c8d898f0 git.coopgo.io/coopgo-platform/groups-management v0.0.0-20230310123255-5ef94ee0746c
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe
github.com/gorilla/securecookie v1.1.1 github.com/gorilla/securecookie v1.1.1
github.com/minio/minio-go/v7 v7.0.43 github.com/minio/minio-go/v7 v7.0.43

6
go.sum
View File

@@ -40,6 +40,8 @@ git.coopgo.io/coopgo-platform/agenda v0.0.0-20221017030035-4a26fc791c5b h1:7kLW1
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221017030035-4a26fc791c5b/go.mod h1:wqPvfYmzGF2cfXbs8XE1P2j5UYqZwp/La0llkl7dUkc= git.coopgo.io/coopgo-platform/agenda v0.0.0-20221017030035-4a26fc791c5b/go.mod h1:wqPvfYmzGF2cfXbs8XE1P2j5UYqZwp/La0llkl7dUkc=
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221205162112-5feb1b720ef9 h1:aP/OxSxOUM7D5PcIs+VSU90Pyy+SSUOOM54FZvPmZ8w= git.coopgo.io/coopgo-platform/agenda v0.0.0-20221205162112-5feb1b720ef9 h1:aP/OxSxOUM7D5PcIs+VSU90Pyy+SSUOOM54FZvPmZ8w=
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221205162112-5feb1b720ef9/go.mod h1:wqPvfYmzGF2cfXbs8XE1P2j5UYqZwp/La0llkl7dUkc= git.coopgo.io/coopgo-platform/agenda v0.0.0-20221205162112-5feb1b720ef9/go.mod h1:wqPvfYmzGF2cfXbs8XE1P2j5UYqZwp/La0llkl7dUkc=
git.coopgo.io/coopgo-platform/agenda v0.0.0-20230310121901-ef3add576f86 h1:pSNHhPU8NB35G14QsSyw/XwsTWZo0qGB0U0X0gzqR1s=
git.coopgo.io/coopgo-platform/agenda v0.0.0-20230310121901-ef3add576f86/go.mod h1:7jVyZSz//VW5+jlLeuwc+JJawNUhJZ7Vima+TdVwKfs=
git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15 h1:+ZI4nGE6mqZ6pc7N/BizheEPRXn6Z84Sj7ikwfP2ZcU= git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15 h1:+ZI4nGE6mqZ6pc7N/BizheEPRXn6Z84Sj7ikwfP2ZcU=
git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15/go.mod h1:rmbqiHVkONcECOoPlsXlxZnD315Tiz2oRnn1M7646Kg= git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15/go.mod h1:rmbqiHVkONcECOoPlsXlxZnD315Tiz2oRnn1M7646Kg=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221101232521-da16c90fc3ba h1:clfkgihzYa3xWKSY/Sn6VUSydOReh7cpuihvYNkWjNk= git.coopgo.io/coopgo-platform/fleets v0.0.0-20221101232521-da16c90fc3ba h1:clfkgihzYa3xWKSY/Sn6VUSydOReh7cpuihvYNkWjNk=
@@ -48,10 +50,14 @@ git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205162030-cecdcb20e1d5 h1:HL/M6
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205162030-cecdcb20e1d5/go.mod h1:s9OIFCNcjBAbBzRNHwoCTYV6kAntPG9CpT3GVweGdTY= git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205162030-cecdcb20e1d5/go.mod h1:s9OIFCNcjBAbBzRNHwoCTYV6kAntPG9CpT3GVweGdTY=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205181518-91991789db9b h1:wvK1V8fFmHgnzVyleEF6Jq0Jcp5cVpPfW7WjMYiTTrE= git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205181518-91991789db9b h1:wvK1V8fFmHgnzVyleEF6Jq0Jcp5cVpPfW7WjMYiTTrE=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205181518-91991789db9b/go.mod h1:s9OIFCNcjBAbBzRNHwoCTYV6kAntPG9CpT3GVweGdTY= git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205181518-91991789db9b/go.mod h1:s9OIFCNcjBAbBzRNHwoCTYV6kAntPG9CpT3GVweGdTY=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20230310144446-feb935f8bf4e h1:eHahRTKlC8aBWYCd6LbXNcX8HoQhuZj31OFWrw0EL0U=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20230310144446-feb935f8bf4e/go.mod h1:s9OIFCNcjBAbBzRNHwoCTYV6kAntPG9CpT3GVweGdTY=
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221017025751-671dc9a2c544 h1:rMLP77uIEequVXXZ0X9G1iK2k+xvW/+58ggwxxI6gqY= git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221017025751-671dc9a2c544 h1:rMLP77uIEequVXXZ0X9G1iK2k+xvW/+58ggwxxI6gqY=
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221017025751-671dc9a2c544/go.mod h1:lozSy6qlIIYhvKKXscZzz28HAtS0qBDUTv5nofLRmYA= git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221017025751-671dc9a2c544/go.mod h1:lozSy6qlIIYhvKKXscZzz28HAtS0qBDUTv5nofLRmYA=
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221205161801-9705c8d898f0 h1:CnLKO1kzoGtaqPhDqfOX3WPRFRcJVJZdGzPdBE4X//w= git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221205161801-9705c8d898f0 h1:CnLKO1kzoGtaqPhDqfOX3WPRFRcJVJZdGzPdBE4X//w=
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221205161801-9705c8d898f0/go.mod h1:lozSy6qlIIYhvKKXscZzz28HAtS0qBDUTv5nofLRmYA= git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221205161801-9705c8d898f0/go.mod h1:lozSy6qlIIYhvKKXscZzz28HAtS0qBDUTv5nofLRmYA=
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20230310123255-5ef94ee0746c h1:bY7PyrAgYY02f5IpDyf1WVfRqvWzivu31K6aEAYbWCw=
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20230310123255-5ef94ee0746c/go.mod h1:lozSy6qlIIYhvKKXscZzz28HAtS0qBDUTv5nofLRmYA=
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe h1:4OKwfKybR0VsIw2dSM9RtqGWveWPt+JjtiiMIBrg/w0= git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe h1:4OKwfKybR0VsIw2dSM9RtqGWveWPt+JjtiiMIBrg/w0=
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe/go.mod h1:1typNYtO+PQT6KG77vs/PUv0fO60/nbeSGZL2tt1LLg= git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe/go.mod h1:1typNYtO+PQT6KG77vs/PUv0fO60/nbeSGZL2tt1LLg=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=

View File

@@ -413,6 +413,15 @@ func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Req
administrators = append(administrators, v.Administrators[0]) administrators = append(administrators, v.Administrators[0])
} }
vehicleBookings := []fleetsstorage.Booking{}
for _, b := range v.Bookings {
if b.Unavailableto.After(time.Now()) {
vehicleBookings = append(vehicleBookings, b)
}
}
v.Bookings = vehicleBookings
vehicles = append(vehicles, v) vehicles = append(vehicles, v)
} }

View File

@@ -71,6 +71,41 @@ func (h *ApplicationHandler) AgendaHome(w http.ResponseWriter, r *http.Request)
h.Renderer.AgendaHome(w, r, responses, groups) h.Renderer.AgendaHome(w, r, responses, groups)
} }
func (h *ApplicationHandler) AgendaHistory(w http.ResponseWriter, r *http.Request) {
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
Namespaces: []string{"parcoursmob_dispositifs"},
//Maxdate: timestamppb.New(time.Now().Add(24 * time.Hour)),
})
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
responses := []agendastorage.Event{}
groupids := []string{}
for _, e := range resp.Events {
groupids = append(groupids, e.Owners...)
responses = append(responses, e.ToStorageType())
}
sort.Sort(sorting.EventsByStartdate(responses))
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
Groupids: groupids,
})
groups := map[string]any{}
if err == nil {
for _, g := range groupsresp.Groups {
groups[g.Id] = g.ToStorageType()
}
}
h.Renderer.AgendaHistory(w, r, responses, groups)
}
func (h *ApplicationHandler) AgendaCreateEvent(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) AgendaCreateEvent(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" { if r.Method == "POST" {
// Get current group // Get current group
@@ -540,10 +575,10 @@ func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r
} }
data := map[string]any{ data := map[string]any{
"motif": r.FormValue("motif"), "motif": r.FormValue("motif"),
"user": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string), "user": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
"subscriber": fmt.Sprintf("http://localhost:9000/app/beneficiaries/%s", subscribeid), "subscriber": fmt.Sprintf("http://localhost:9000/app/beneficiaries/%s", subscribeid),
"link": fmt.Sprintf("http://localhost:9000/app/agenda/%s", eventId), "link": fmt.Sprintf("http://localhost:9000/app/agenda/%s", eventId),
} }
// récupérer l'adresse mail de l'utilisateur qui a créé l'événement // récupérer l'adresse mail de l'utilisateur qui a créé l'événement

View File

@@ -268,7 +268,7 @@ func (h *ApplicationHandler) BeneficiaryDocuments(w http.ResponseWriter, r *http
beneficiaryID := vars["beneficiaryid"] beneficiaryID := vars["beneficiaryid"]
//r.ParseForm() //r.ParseForm()
r.ParseMultipartForm(10 * 1024 * 1024) r.ParseMultipartForm(100 * 1024 * 1024)
document_type := r.FormValue("type") document_type := r.FormValue("type")
document_name := r.FormValue("name") document_name := r.FormValue("name")

View File

@@ -42,24 +42,24 @@ func (h *ApplicationHandler) VehiclesManagementOverview(w http.ResponseWriter, r
for _, vehicle := range resp.Vehicles { for _, vehicle := range resp.Vehicles {
if filterVehicle(r, vehicle) { if filterVehicle(r, vehicle) {
v := vehicle.ToStorageType() v := vehicle.ToStorageType()
vehicles = append(vehicles, v) vehicleBookings := []fleetsstorage.Booking{}
vehicles_map[v.ID] = v
for _, b := range v.Bookings { for _, b := range v.Bookings {
if b.Status() != fleetsstorage.StatusOld { if b.Status() != fleetsstorage.StatusOld {
bookings = append(bookings, b) if deleted, ok := b.Data["Deleted"].(bool); !ok && !deleted {
bookings = append(bookings, b)
}
}
if b.Unavailableto.After(time.Now()) {
vehicleBookings = append(vehicleBookings, b)
} }
} }
v.Bookings = vehicleBookings
vehicles = append(vehicles, v)
vehicles_map[v.ID] = v
} }
} }
// vehiicles := []fleetsstorage.Vehicle{}
// for i, vehiicle := range resp.Vehicles {
// if len(resp.Vehicles[i].Bookings) == 0 {
// v := vehiicle.ToStorageType()
// vehiicles = append(vehiicles, v)
// }
// }
//fmt.Println(vehiicles)
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)
@@ -329,6 +329,8 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite
alternativerequest := &fleets.GetVehiclesRequest{ alternativerequest := &fleets.GetVehiclesRequest{
Namespaces: []string{"parcoursmob"}, Namespaces: []string{"parcoursmob"},
Types: []string{booking.Vehicle.Type},
Administrators: booking.Vehicle.Administrators,
AvailabilityFrom: timestamppb.New(booking.Startdate), AvailabilityFrom: timestamppb.New(booking.Startdate),
AvailabilityTo: timestamppb.New(booking.Enddate.Add(24 * time.Hour)), AvailabilityTo: timestamppb.New(booking.Enddate.Add(24 * time.Hour)),
} }
@@ -467,27 +469,127 @@ func (h ApplicationHandler) VehiclesFleetMakeUnavailable(w http.ResponseWriter,
http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/fleet/%s", vehicleid), http.StatusFound) http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/fleet/%s", vehicleid), http.StatusFound)
} }
// func (h *ApplicationHandler) UnbookingVehicles(w http.ResponseWriter, r *http.Request) { // func (h *ApplicationHandler) UnbookingVehicles(w http.ResponseWriter, r *http.Request) {
// request := &fleets.GetVehiclesRequest{ // request := &fleets.GetVehiclesRequest{
// Namespaces: []string{"parcoursmob"}, // Namespaces: []string{"parcoursmob"},
// } // }
// resp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), request) // resp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), request)
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// w.WriteHeader(http.StatusInternalServerError) // w.WriteHeader(http.StatusInternalServerError)
// } // }
// vehicles := []fleetsstorage.Vehicle{} // vehicles := []fleetsstorage.Vehicle{}
// fmt.Println(resp.Vehicles[0].Bookings) // fmt.Println(resp.Vehicles[0].Bookings)
// for i, vehicle := range resp.Vehicles { // for i, vehicle := range resp.Vehicles {
// if len(resp.Vehicles[i].Bookings) == 0 { // if len(resp.Vehicles[i].Bookings) == 0 {
// v := vehicle.ToStorageType() // v := vehicle.ToStorageType()
// vehicles = append(vehicles, v) // vehicles = append(vehicles, v)
// } // }
// } // }
// // if len(resp.Vehicle.ToStorageType().Bookings) == 0 { // // if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
// // h.Renderer.UnbookingVehicles(w, r, resp.Vehicle.ToStorageType()) // // h.Renderer.UnbookingVehicles(w, r, resp.Vehicle.ToStorageType())
// // } // // }
// // fmt.Println(resp.Vehicle.ToStorageType().Bookings) // // fmt.Println(resp.Vehicle.ToStorageType().Bookings)
// fmt.Println(vehicles) // fmt.Println(vehicles)
// h.Renderer.UnbookingVehicles(w, r, vehicles) // h.Renderer.UnbookingVehicles(w, r, vehicles)
// } // }
func (h *ApplicationHandler) UnbookingVehicle(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bookingid := vars["bookingid"]
request := &fleets.GetBookingRequest{
Bookingid: bookingid,
}
resp, err := h.services.GRPC.Fleets.GetBooking(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
now := time.Now()
date := now.Format("2006-01-02")
unavailableto, _ := time.Parse("2006-01-02", date)
current_group, err := h.currentGroup(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
current_user_token, current_user_claims, err := h.currentUser(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
booked_by_id := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["user"].GetStructValue().Fields["id"].GetStringValue()
booked_by_name := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["user"].GetStructValue().Fields["display_name"].GetStringValue()
booked_by_email := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["user"].GetStructValue().Fields["email"].GetStringValue()
booked_by_group_id := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["group"].GetStructValue().Fields["id"].GetStringValue()
booked_by_group_name := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["group"].GetStructValue().Fields["name"].GetStringValue()
data := map[string]any{
"booked_by": map[string]any{
"user": map[string]any{
"id": booked_by_id,
"display_name": booked_by_name,
"email": booked_by_email,
},
"group": map[string]any{
"id": booked_by_group_id,
"name": booked_by_group_name,
},
},
"unbooked_by": map[string]any{
"user": map[string]any{
"id": current_user_token.Subject,
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
"email": current_user_claims["email"],
},
"group": map[string]any{
"id": current_group.ID,
"name": current_group.Data["name"],
},
},
"Deleted": true,
"motif": r.FormValue("motif"),
}
datapb, err := structpb.NewStruct(data)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if r.Method == "POST" {
request := &fleets.UpdateBookingRequest{
Booking: &fleets.Booking{
Id: resp.Booking.Id,
Vehicleid: resp.Booking.Vehicleid,
Driver: resp.Booking.Driver,
Startdate: resp.Booking.Startdate,
Enddate: resp.Booking.Enddate,
Unavailablefrom: resp.Booking.Unavailablefrom,
Unavailableto: timestamppb.New(unavailableto),
Data: datapb,
},
}
_, err := h.services.GRPC.Fleets.UpdateBooking(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/app/vehicles-management/", http.StatusFound)
return
}
h.Renderer.UnbookingVehicle(w, r, resp.Booking.ToStorageType())
}

11
main.go
View File

@@ -26,6 +26,7 @@ func main() {
address = cfg.GetString("server.listen") address = cfg.GetString("server.listen")
service_name = cfg.GetString("service_name") service_name = cfg.GetString("service_name")
templates_public_dir = cfg.GetString("templates.public_dir") templates_public_dir = cfg.GetString("templates.public_dir")
dev_env = cfg.GetBool("dev_env")
) )
svc, err := services.NewServicesHandler(cfg) svc, err := services.NewServicesHandler(cfg)
@@ -55,6 +56,9 @@ func main() {
authHandler, _ := auth.NewAuthHandler(cfg, idp, svc, kv, emailing) authHandler, _ := auth.NewAuthHandler(cfg, idp, svc, kv, emailing)
fmt.Println("Running", service_name, ":") fmt.Println("Running", service_name, ":")
if dev_env {
fmt.Printf("\033]0;%s\007", service_name)
}
r := mux.NewRouter() r := mux.NewRouter()
@@ -101,8 +105,13 @@ func main() {
application.HandleFunc("/vehicles-management/fleet/{vehicleid}/update", applicationHandler.VehiclesFleetUpdate) application.HandleFunc("/vehicles-management/fleet/{vehicleid}/update", applicationHandler.VehiclesFleetUpdate)
application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList) application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList)
application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay) application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay)
application.HandleFunc("/vehicles-management/bookings/{bookingid}/change-vehicle", applicationHandler.VehicleManagementBookingChangeVehicle)
/////////////////////////////////////Remove booking vehicle/////////////////////////////////////////
application.HandleFunc("/vehicles-management/bookings/{bookingid}/delete", applicationHandler.UnbookingVehicle)
////////////////////////////////////////////////////////////////////////////////////////////////////
application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload) application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload)
application.HandleFunc("/agenda/", applicationHandler.AgendaHome) application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
application.HandleFunc("/agenda/history", applicationHandler.AgendaHistory)
application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent) application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent)
application.HandleFunc("/agenda/{eventid}", applicationHandler.AgendaDisplayEvent) application.HandleFunc("/agenda/{eventid}", applicationHandler.AgendaDisplayEvent)
///////////////////////////////Code to modify event/////////////////////// ///////////////////////////////Code to modify event///////////////////////
@@ -151,6 +160,8 @@ func main() {
application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent) application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent)
application.HandleFunc("/agenda/{eventid}/history", applicationHandler.AgendaHistoryEvent) application.HandleFunc("/agenda/{eventid}/history", applicationHandler.AgendaHistoryEvent)
///////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////
fmt.Println("-> HTTP server listening on", address) fmt.Println("-> HTTP server listening on", address)
srv := &http.Server{ srv := &http.Server{

View File

@@ -19,6 +19,17 @@ func (renderer *Renderer) AgendaHome(w http.ResponseWriter, r *http.Request, eve
renderer.Render("agenda home", w, r, files, state) renderer.Render("agenda home", w, r, files, state)
} }
func (renderer *Renderer) AgendaHistory(w http.ResponseWriter, r *http.Request, events []agendastorage.Event, groups map[string]any) {
files := renderer.ThemeConfig.GetStringSlice("views.agenda.history.files")
state := NewState(r, renderer.ThemeConfig, agendaMenu)
state.ViewState = map[string]any{
"events": events,
"groups": groups,
}
renderer.Render("agenda history", w, r, files, state)
}
func (renderer *Renderer) AgendaCreateEvent(w http.ResponseWriter, r *http.Request) { func (renderer *Renderer) AgendaCreateEvent(w http.ResponseWriter, r *http.Request) {
files := renderer.ThemeConfig.GetStringSlice("views.agenda.create_event.files") files := renderer.ThemeConfig.GetStringSlice("views.agenda.create_event.files")
state := NewState(r, renderer.ThemeConfig, agendaMenu) state := NewState(r, renderer.ThemeConfig, agendaMenu)

View File

@@ -1,9 +1,11 @@
package renderer package renderer
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"html/template" "html/template"
"strings"
"time" "time"
"gitlab.scity.coop/maas/navitia-golang/types" "gitlab.scity.coop/maas/navitia-golang/types"
@@ -67,6 +69,22 @@ func JSON(v any) template.JS {
return template.JS(result) return template.JS(result)
} }
func RawJSON(v any) string {
buf := new(bytes.Buffer)
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
err := enc.Encode(&v)
if err != nil {
return ""
}
return strings.TrimSuffix(buf.String(), "\n")
}
func UnescapeHTML(s string) template.HTML {
return template.HTML(s)
}
func Dict(v ...interface{}) map[string]interface{} { func Dict(v ...interface{}) map[string]interface{} {
dict := map[string]interface{}{} dict := map[string]interface{}{}
lenv := len(v) lenv := len(v)

View File

@@ -55,6 +55,8 @@ func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Req
"genderISO5218": GenderISO5218, "genderISO5218": GenderISO5218,
"dict": Dict, "dict": Dict,
"json": JSON, "json": JSON,
"rawjson": RawJSON,
"unescapeHTML": UnescapeHTML,
"walkingLength": WalkingLength, "walkingLength": WalkingLength,
"divideFloat64": Divide[float64], "divideFloat64": Divide[float64],
"divideInt": Divide[int], "divideInt": Divide[int],
@@ -83,6 +85,8 @@ func (renderer *Renderer) RenderNoLayout(name string, w http.ResponseWriter, r *
"genderISO5218": GenderISO5218, "genderISO5218": GenderISO5218,
"dict": Dict, "dict": Dict,
"json": JSON, "json": JSON,
"rawjson": RawJSON,
"unsescapeHTML": UnescapeHTML,
"divideFloat64": Divide[float64], "divideFloat64": Divide[float64],
"divideInt": Divide[int], "divideInt": Divide[int],
}, },
@@ -156,7 +160,6 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
Active: menuState == administrationMenu, Active: menuState == administrationMenu,
}, },
//TODO from configuration for icons at least
MenuItems: []MenuItem{ MenuItems: []MenuItem{
{ {
Title: "Tableau de bord", Title: "Tableau de bord",
@@ -212,16 +215,6 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
}) })
} }
if modules["support"] != nil && modules["support"].(bool) {
ls.MenuItems = append(ls.MenuItems, MenuItem{
Title: "Support",
Link: "/app/support/",
Active: menuState == commentMenu,
Icon: "hero:outline/support",
})
}
if modules["group_module"] != nil && modules["group_module"].(bool) { if modules["group_module"] != nil && modules["group_module"].(bool) {
ls.MenuItems = append(ls.MenuItems, MenuItem{ ls.MenuItems = append(ls.MenuItems, MenuItem{
Title: "Groupes / Communautés", Title: "Groupes / Communautés",
@@ -232,6 +225,16 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
} }
if modules["support"] != nil && modules["support"].(bool) {
ls.MenuItems = append(ls.MenuItems, MenuItem{
Title: "Support",
Link: "/app/support/",
Active: menuState == commentMenu,
Icon: "hero:outline/support",
})
}
if modules["directory"] != nil && modules["directory"].(bool) { if modules["directory"] != nil && modules["directory"].(bool) {
ls.MenuItems = append(ls.MenuItems, MenuItem{ ls.MenuItems = append(ls.MenuItems, MenuItem{
Title: "Répertoire solutions", Title: "Répertoire solutions",

View File

@@ -78,3 +78,14 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter,
renderer.Render("vehicles search", w, r, files, state) renderer.Render("vehicles search", w, r, files, state)
} }
func (renderer *Renderer) UnbookingVehicle(w http.ResponseWriter, r *http.Request, booking any) {
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.delete_booking.files")
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
state.ViewState = map[string]any{
"booking": booking,
}
renderer.Render("vehicule unbooking", w, r, files, state)
}