Compare commits

...

4 Commits

Author SHA1 Message Date
Arnaud Delcasse 78877f139f Same vehicle type requested 2023-03-10 16:11:26 +01:00
Arnaud Delcasse 5476ea1c99 Merge 2023-03-10 13:18:31 +01:00
Arnaud Delcasse 59c6ce9da6 small updates 2023-03-10 12:16:12 +01:00
Arnaud Delcasse 439f819989 merge 2023-01-30 15:21:08 +01:00
11 changed files with 120 additions and 31 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 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 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

10
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/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/agenda => ../../coopgo-platform/agenda/
// replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/
// replace git.coopgo.io/coopgo-platform/emailing => ../../coopgo-platform/emailing/
@ -30,10 +30,10 @@ 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/fleets v0.0.0-20221205181518-91991789db9b
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221205161801-9705c8d898f0
git.coopgo.io/coopgo-platform/fleets v0.0.0-20230310144446-feb935f8bf4e
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20230310123255-5ef94ee0746c
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe
github.com/gorilla/securecookie v1.1.1
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-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-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/go.mod h1:rmbqiHVkONcECOoPlsXlxZnD315Tiz2oRnn1M7646Kg=
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-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-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/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/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/go.mod h1:1typNYtO+PQT6KG77vs/PUv0fO60/nbeSGZL2tt1LLg=
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])
}
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)
}

View File

@ -71,6 +71,41 @@ func (h *ApplicationHandler) AgendaHome(w http.ResponseWriter, r *http.Request)
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) {
if r.Method == "POST" {
// Get current group
@ -540,10 +575,10 @@ func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r
}
data := map[string]any{
"motif": r.FormValue("motif"),
"user": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
"motif": r.FormValue("motif"),
"user": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
"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

View File

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

View File

@ -42,24 +42,22 @@ func (h *ApplicationHandler) VehiclesManagementOverview(w http.ResponseWriter, r
for _, vehicle := range resp.Vehicles {
if filterVehicle(r, vehicle) {
v := vehicle.ToStorageType()
vehicles = append(vehicles, v)
vehicles_map[v.ID] = v
vehicleBookings := []fleetsstorage.Booking{}
for _, b := range v.Bookings {
if b.Status() != fleetsstorage.StatusOld {
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.BookingsByStartdate(bookings))
h.Renderer.VehiclesManagementOverview(w, r, vehicles, vehicles_map, bookings)
@ -329,6 +327,8 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite
alternativerequest := &fleets.GetVehiclesRequest{
Namespaces: []string{"parcoursmob"},
Types: []string{booking.Vehicle.Type},
Administrators: booking.Vehicle.Administrators,
AvailabilityFrom: timestamppb.New(booking.Startdate),
AvailabilityTo: timestamppb.New(booking.Enddate.Add(24 * time.Hour)),
}

View File

@ -26,6 +26,7 @@ func main() {
address = cfg.GetString("server.listen")
service_name = cfg.GetString("service_name")
templates_public_dir = cfg.GetString("templates.public_dir")
dev_env = cfg.GetBool("dev_env")
)
svc, err := services.NewServicesHandler(cfg)
@ -55,6 +56,9 @@ func main() {
authHandler, _ := auth.NewAuthHandler(cfg, idp, svc, kv, emailing)
fmt.Println("Running", service_name, ":")
if dev_env {
fmt.Printf("\033]0;%s\007", service_name)
}
r := mux.NewRouter()
@ -101,8 +105,10 @@ func main() {
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}/change-vehicle", applicationHandler.VehicleManagementBookingChangeVehicle)
application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload)
application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
application.HandleFunc("/agenda/history", applicationHandler.AgendaHistory)
application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent)
application.HandleFunc("/agenda/{eventid}", applicationHandler.AgendaDisplayEvent)
///////////////////////////////Code to modify event///////////////////////

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)
}
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) {
files := renderer.ThemeConfig.GetStringSlice("views.agenda.create_event.files")
state := NewState(r, renderer.ThemeConfig, agendaMenu)

View File

@ -1,9 +1,11 @@
package renderer
import (
"bytes"
"encoding/json"
"fmt"
"html/template"
"strings"
"time"
"gitlab.scity.coop/maas/navitia-golang/types"
@ -67,6 +69,22 @@ func JSON(v any) template.JS {
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{} {
dict := map[string]interface{}{}
lenv := len(v)

View File

@ -55,6 +55,8 @@ func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Req
"genderISO5218": GenderISO5218,
"dict": Dict,
"json": JSON,
"rawjson": RawJSON,
"unescapeHTML": UnescapeHTML,
"walkingLength": WalkingLength,
"divideFloat64": Divide[float64],
"divideInt": Divide[int],
@ -83,6 +85,8 @@ func (renderer *Renderer) RenderNoLayout(name string, w http.ResponseWriter, r *
"genderISO5218": GenderISO5218,
"dict": Dict,
"json": JSON,
"rawjson": RawJSON,
"unsescapeHTML": UnescapeHTML,
"divideFloat64": Divide[float64],
"divideInt": Divide[int],
},
@ -156,7 +160,6 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
Active: menuState == administrationMenu,
},
//TODO from configuration for icons at least
MenuItems: []MenuItem{
{
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) {
ls.MenuItems = append(ls.MenuItems, MenuItem{
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) {
ls.MenuItems = append(ls.MenuItems, MenuItem{
Title: "Répertoire solutions",