4 Commits

Author SHA1 Message Date
soukainna
4c42d3efd3 Merge branch 'main' into groupsCovoiturage 2022-12-19 13:09:07 +01:00
soukainna
12a8a359ab create groups journeys 2022-12-07 11:12:43 +01:00
707d9c63aa merge with remote 2022-12-06 12:13:19 +01:00
a3ee210547 Release 5 december 2022 - Agenda and Fleets fixes 2022-12-05 20:06:22 +01:00
20 changed files with 846 additions and 83 deletions

6
go.mod
View File

@@ -30,10 +30,10 @@ require (
) )
require ( require (
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221017030035-4a26fc791c5b git.coopgo.io/coopgo-platform/agenda v0.0.0-20221205162112-5feb1b720ef9
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-20221101232521-da16c90fc3ba git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205181518-91991789db9b
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221017025751-671dc9a2c544 git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221205161801-9705c8d898f0
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

8
go.sum
View File

@@ -38,12 +38,20 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221017030035-4a26fc791c5b h1:7kLW1khfGguZ2aL+QpWFwZmAdEcY1MsUjLdiRufjr2s= git.coopgo.io/coopgo-platform/agenda v0.0.0-20221017030035-4a26fc791c5b h1:7kLW1khfGguZ2aL+QpWFwZmAdEcY1MsUjLdiRufjr2s=
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/go.mod h1:wqPvfYmzGF2cfXbs8XE1P2j5UYqZwp/La0llkl7dUkc=
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=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221101232521-da16c90fc3ba/go.mod h1:s9OIFCNcjBAbBzRNHwoCTYV6kAntPG9CpT3GVweGdTY= git.coopgo.io/coopgo-platform/fleets v0.0.0-20221101232521-da16c90fc3ba/go.mod h1:s9OIFCNcjBAbBzRNHwoCTYV6kAntPG9CpT3GVweGdTY=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205162030-cecdcb20e1d5 h1:HL/M681G9R1ZN8XPp4LvG9hcF20//R9yQmr5cdXwQaM=
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/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/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

@@ -22,6 +22,27 @@ import (
func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) {
accounts, err := h.services.GetAccounts()
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
beneficiaries, err := h.services.GetBeneficiaries()
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
bookings, err := h.services.GetBookings()
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
request := &groupsmanagement.GetGroupsRequest{ request := &groupsmanagement.GetGroupsRequest{
Namespaces: []string{"parcoursmob_organizations"}, Namespaces: []string{"parcoursmob_organizations"},
} }
@@ -42,7 +63,7 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque
sort.Sort(sorting.GroupsByName(groups)) sort.Sort(sorting.GroupsByName(groups))
h.Renderer.Administration(w, r, groups) h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings)
} }
func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r *http.Request) {
@@ -62,6 +83,8 @@ func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r
"vehicles": r.FormValue("modules.vehicles") == "on", "vehicles": r.FormValue("modules.vehicles") == "on",
"vehicles_management": r.FormValue("modules.vehicles_management") == "on", "vehicles_management": r.FormValue("modules.vehicles_management") == "on",
"events": r.FormValue("modules.events") == "on", "events": r.FormValue("modules.events") == "on",
"agenda": r.FormValue("modules.agenda") == "on",
"groups": r.FormValue("modules.groups") == "on",
"administration": r.FormValue("modules.administration") == "on", "administration": r.FormValue("modules.administration") == "on",
} }
@@ -130,30 +153,6 @@ func (h *ApplicationHandler) AdministrationGroupDisplay(w http.ResponseWriter, r
return return
} }
// members, err := h.members()
// if err != nil {
// if err != nil {
// fmt.Println(err)
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// }
// groupmembers := []any{}
// admins := []any{}
// for _, m := range members {
// mm := m.ToStorageType()
// for _, g := range mm.Data["groups"].([]any) {
// if g.(string) == groupid {
// groupmembers = append(groupmembers, mm)
// }
// if g.(string) == groupid+":admin" {
// admins = append(admins, mm)
// }
// }
// }
groupmembers, admins, err := h.groupmembers(groupid) groupmembers, admins, err := h.groupmembers(groupid)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

View File

@@ -205,6 +205,18 @@ func (h *ApplicationHandler) AgendaDisplayEvent(w http.ResponseWriter, r *http.R
} }
func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http.Request) {
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
}
vars := mux.Vars(r) vars := mux.Vars(r)
eventid := vars["eventid"] eventid := vars["eventid"]
@@ -215,13 +227,32 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http
} }
subscriber := r.FormValue("subscriber") subscriber := r.FormValue("subscriber")
data := map[string]any{
"subscribed_by": map[string]any{
"user": map[string]any{
"id": current_user_token.Subject,
"display_name": current_user_claims["display_name"],
},
"group": map[string]any{
"id": current_group.ID,
"name": current_group.Data["name"],
},
},
}
datapb, err := structpb.NewStruct(data)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
request := &agenda.SubscribeEventRequest{ request := &agenda.SubscribeEventRequest{
Eventid: eventid, Eventid: eventid,
Subscriber: subscriber, Subscriber: subscriber,
Data: datapb,
} }
_, err := h.services.GRPC.Agenda.SubscribeEvent(context.TODO(), request) _, err = h.services.GRPC.Agenda.SubscribeEvent(context.TODO(), request)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)

View File

@@ -1,12 +1,16 @@
package application package application
import ( import (
"errors"
"net/http" "net/http"
"git.coopgo.io/coopgo-apps/parcoursmob/renderer" "git.coopgo.io/coopgo-apps/parcoursmob/renderer"
"git.coopgo.io/coopgo-apps/parcoursmob/services" "git.coopgo.io/coopgo-apps/parcoursmob/services"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
cache "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" cache "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
"git.coopgo.io/coopgo-platform/emailing" "git.coopgo.io/coopgo-platform/emailing"
"git.coopgo.io/coopgo-platform/groups-management/storage"
"github.com/coreos/go-oidc"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@@ -39,3 +43,31 @@ func (h *ApplicationHandler) NotFound(w http.ResponseWriter, r *http.Request) {
func (h *ApplicationHandler) templateFile(file string) string { func (h *ApplicationHandler) templateFile(file string) string {
return h.config.GetString("templates.root") + file return h.config.GetString("templates.root") + file
} }
func (h *ApplicationHandler) currentGroup(r *http.Request) (current_group storage.Group, err error) {
g := r.Context().Value(identification.GroupKey)
if g == nil {
return storage.Group{}, errors.New("current group not found")
}
current_group = g.(storage.Group)
return current_group, nil
}
func (h *ApplicationHandler) currentUser(r *http.Request) (current_user_token *oidc.IDToken, current_user_claims map[string]any, err error) {
// Get current user ID
u := r.Context().Value(identification.IdtokenKey)
if u == nil {
return nil, nil, errors.New("current user not found")
}
current_user_token = u.(*oidc.IDToken)
// Get current user claims
c := r.Context().Value(identification.ClaimsKey)
if c == nil {
return current_user_token, nil, errors.New("current user claims not found")
}
current_user_claims = c.(map[string]any)
return current_user_token, current_user_claims, nil
}

View File

@@ -135,9 +135,6 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
return return
} }
//TODO filter namespaces
//TODO filter groups
bookingsrequest := &fleets.GetDriverBookingsRequest{ bookingsrequest := &fleets.GetDriverBookingsRequest{
Driver: beneficiaryID, Driver: beneficiaryID,
} }
@@ -154,10 +151,25 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
bookings = append(bookings, b.ToStorageType()) bookings = append(bookings, b.ToStorageType())
} }
groupsrequest := &groupsmanagement.GetGroupsRequest{
Namespaces: []string{"parcoursmob_organizations"},
Member: beneficiaryID,
}
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), groupsrequest)
if err != nil {
fmt.Println(err)
}
organizations := []any{}
for _, o := range groupsresp.Groups {
organizations = append(organizations, o.ToStorageType())
}
beneficiaries_file_types := h.config.GetStringSlice("modules.beneficiaries.documents_types") beneficiaries_file_types := h.config.GetStringSlice("modules.beneficiaries.documents_types")
file_types_map := h.config.GetStringMapString("storage.files.file_types") file_types_map := h.config.GetStringMapString("storage.files.file_types")
h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, beneficiaries_file_types, file_types_map, documents) h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents)
} }
func (h *ApplicationHandler) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request) {

View File

@@ -12,6 +12,7 @@ import (
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage" agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
"git.coopgo.io/coopgo-platform/groups-management/storage" "git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi" mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
"google.golang.org/protobuf/types/known/timestamppb"
) )
func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
@@ -51,7 +52,7 @@ func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
} }
} }
members, err := h.members() members, _, err := h.groupmembers(group.ID)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
@@ -64,6 +65,7 @@ func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
eventsresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{ eventsresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
Namespaces: []string{"parcoursmob_dispositifs"}, Namespaces: []string{"parcoursmob_dispositifs"},
Mindate: timestamppb.Now(),
}) })
for _, e := range eventsresp.Events { for _, e := range eventsresp.Events {

View File

@@ -5,14 +5,35 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"sort"
"strings"
"time" "time"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi" fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
"github.com/google/uuid"
"github.com/gorilla/mux"
geojson "github.com/paulmach/go.geojson" geojson "github.com/paulmach/go.geojson"
"gitlab.scity.coop/maas/navitia-golang" "gitlab.scity.coop/maas/navitia-golang"
"gitlab.scity.coop/maas/navitia-golang/types" "gitlab.scity.coop/maas/navitia-golang/types"
"google.golang.org/protobuf/types/known/structpb"
) )
var Depart any
var Arrive any
// type Typep string
// const (
// rec Typep = "rec"
// pon Typep = "pon"
// )
// var departdate string
// var departTime string
func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) {
r.ParseForm() r.ParseForm()
@@ -144,3 +165,334 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
h.Renderer.JourneysSearch(w, r, carpoolresults, journeys, vehicles, searched, departuregeo, destinationgeo, departuredate, departuretime) h.Renderer.JourneysSearch(w, r, carpoolresults, journeys, vehicles, searched, departuregeo, destinationgeo, departuredate, departuretime)
} }
type GroupsModule []groupstorage.Group
func (a GroupsModule) Len() int { return len(a) }
func (a GroupsModule) Less(i, j int) bool {
return strings.Compare(a[i].Data["name"].(string), a[j].Data["name"].(string)) < 0
}
func (a GroupsModule) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (h *ApplicationHandler) GroupsGestion(w http.ResponseWriter, r *http.Request) {
request := &groupsmanagement.GetGroupsRequest{
Namespaces: []string{"parcoursmob_groups_covoiturage"},
}
resp, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
var groups = []groupstorage.Group{}
for _, group := range resp.Groups {
g := group.ToStorageType()
groups = append(groups, g)
}
//////////////////
cacheid := uuid.NewString()
/////////////////
sort.Sort(GroupsModule(groups))
h.cache.PutWithTTL(cacheid, groups, 1*time.Hour)
h.Renderer.GroupsGestion(w, r, groups, cacheid)
}
func filterAcc(r *http.Request, a *mobilityaccounts.Account) bool {
searchFilter, ok := r.URL.Query()["search"]
if ok && len(searchFilter[0]) > 0 {
name := a.Data.AsMap()["first_name"].(string) + " " + a.Data.AsMap()["last_name"].(string)
if !strings.Contains(strings.ToLower(name), strings.ToLower(searchFilter[0])) {
return false
}
}
return true
}
func (h *ApplicationHandler) CreateGroup(w http.ResponseWriter, r *http.Request) {
var beneficiary any
var (
departurgeo *geojson.Feature
dstinationgeo *geojson.Feature
)
searched := false
// var accounts = []any{}
// cacheid := uuid.NewString()
// accountsBeneficaire, err := h.beneficiaries(r)
// if err != nil {
// fmt.Println(err)
// w.WriteHeader(http.StatusBadRequest)
// return
// }
if r.FormValue("beneficiaryid") != "" {
// Handler form
searched = true
requestbeneficiary := &mobilityaccounts.GetAccountRequest{
Id: r.FormValue("beneficiaryid"),
}
respbeneficiary, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), requestbeneficiary)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
beneficiary = respbeneficiary.Account.ToStorageType()
if r.Method == "POST" {
fmt.Println("herrre")
///////////////////////////////////////////
departure := r.FormValue("departure")
destination := r.FormValue("destination")
if departure != "" && destination != "" {
var err error
departurgeo, err = geojson.UnmarshalFeature([]byte(departure))
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
dstinationgeo, err = geojson.UnmarshalFeature([]byte(destination))
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
if r.FormValue("departure") != "" {
var a any
json.Unmarshal([]byte(r.FormValue("departure")), &a)
Depart = a
}
if r.FormValue("destination") != "" {
var a any
json.Unmarshal([]byte(r.FormValue("destination")), &a)
Arrive = a
}
r.ParseForm()
/////////////////
// locTime, errTime := time.LoadLocation("Europe/Paris")
// if errTime != nil {
// fmt.Println("Loading timezone location Europe/Paris error : ")
// fmt.Println("Missing zones in container ? ")
// panic(errTime)
// }
// departdate := r.FormValue("departuredate")
// departTime := r.FormValue("departuretime")
//departuredatetime, _ := time.ParseInLocation("2006-01-02 15:04", fmt.Sprintf("%s %s", departuredate, departuretime), locTime)
////////////////
if r.FormValue("name") == "" {
fmt.Println("invalid name")
w.WriteHeader(http.StatusBadRequest)
return
}
// if r.FormValue("driver") == "" {
// fmt.Println("invalid name")
// w.WriteHeader(http.StatusBadRequest)
// return
// }
if r.FormValue("number") == "" {
fmt.Println("invalid number of personne")
w.WriteHeader(http.StatusBadRequest)
return
}
// planType := map[string]any{
// "rrecurrent": r.FormValue("recurrent") == "on",
// "pponctuelle": r.FormValue("ponctuelle") == "on",
// }
planDays := map[string]any{
"lundi": r.FormValue("lundi") == "on",
"mardi": r.FormValue("mardi") == "on",
"mercredi": r.FormValue("mercredi") == "on",
"jeudi": r.FormValue("jeudi") == "on",
"vendredi": r.FormValue("vendredi") == "on",
"samedi": r.FormValue("samedi") == "on",
"dimanche": r.FormValue("dimanche") == "on",
}
// var rec bool = r.FormValue("recurrent")
// var ponc bool
groupidd := uuid.NewString()
fmt.Println("herrr&e")
dataMap := map[string]any{
"name": r.FormValue("name"),
"number": r.FormValue("number"),
"driver_first_name": respbeneficiary.Account.ToStorageType().Data["first_name"],
"driver_last_name": respbeneficiary.Account.ToStorageType().Data["last_name"],
"depart": Depart,
"arrive": Arrive,
"departdate": r.FormValue("departdate"),
"date": r.FormValue("date"),
"enddate": r.FormValue("enddate"),
"departtime": r.FormValue("departtime"),
"time": r.FormValue("time"),
// "ponctdate": r.FormValue("ponctdate"),
//"planType": planType,
"planDays": planDays,
"recurrent": r.FormValue("recurrent"),
"pontuelle": r.FormValue("ponctuelle"),
// "r": rec,
// "p": pon,
}
fmt.Println(dataMap["ponctuelle"])
data, err := structpb.NewValue(dataMap)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
request_organization := &groupsmanagement.AddGroupRequest{
Group: &groupsmanagement.Group{
Id: groupidd,
Namespace: "parcoursmob_groups_covoiturage",
Data: data.GetStructValue(),
},
}
_, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_organization)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
//////////////////////////////////////////////////
// request_organizatio := &groupsmanagement.AddGroupMemberRequest{
// Group: &groupsmanagement.GroupMember{
// Id: groupidd,
// //Namespace: "parcoursmob_groups_covoiturage",
// Data: data.GetStructValue(),
// },
// }
// _, err = h.services.GRPC.GroupsManagement.AddGroupMember(context.TODO(), request_organizatio)
// if err != nil {
// fmt.Println(err)
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
////////////////////////////////////////////////
http.Redirect(w, r, fmt.Sprintf("/app/journeys/groups_covoiturage/create/%s", request_organization.Group.ToStorageType().ID), http.StatusFound)
//http.Redirect(w, r, fmt.Print("/app/journeys"), http.StatusFound)
return
}
}
accountsBeneficaire, err := h.beneficiaries(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
h.Renderer.CreateGroup(w, r, Depart, Arrive, searched, beneficiary, accountsBeneficaire, departurgeo, dstinationgeo)
}
func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
groupid := vars["groupid"]
request := &groupsmanagement.GetGroupRequest{
Id: groupid,
}
resp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
var accounts = []any{}
requesst := &mobilityaccounts.GetAccountsBatchRequest{
Accountids: resp.Group.Members,
}
ressp, _ := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), requesst)
// if err != nil {
// return err
// }
for _, account := range ressp.Accounts {
if filterAcc(r, account) {
a := account.ToStorageType()
accounts = append(accounts, a)
}
}
cacheid := uuid.NewString()
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
r.ParseForm()
var beneficiary any
searched := false
// if r.Method == "POST" {
if r.FormValue("beneficiaryid") != "" {
// Handler form
searched = true
requestbeneficiary := &mobilityaccounts.GetAccountRequest{
Id: r.FormValue("beneficiaryid"),
}
respbeneficiary, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), requestbeneficiary)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
beneficiary = respbeneficiary.Account.ToStorageType()
subscribe := &groupsmanagement.SubscribeRequest{
Groupid: resp.Group.ToStorageType().ID,
Memberid: respbeneficiary.Account.Id,
}
_, err = h.services.GRPC.GroupsManagement.Subscribe(context.TODO(), subscribe)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
http.Redirect(w, r, fmt.Sprintf("/app/journeys/groups_covoiturage/create/%s", resp.Group.ToStorageType().ID), http.StatusFound)
return
}
accountsBeneficaire, err := h.beneficiaries(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
//h.Renderer.BeneficaireSearch(w, r, accounts, searched, beneficiary, resp.Group.ToStorageType())
h.Renderer.DisplayGroupCovoiturage(w, r, resp.Group.ToStorageType().ID, accounts, cacheid, searched, beneficiary, resp.Group.ToStorageType(), accountsBeneficaire)
}

View File

@@ -77,7 +77,12 @@ func (h *ApplicationHandler) VehiclesManagementBookingsList(w http.ResponseWrite
if filterVehicle(r, vehicle) { if filterVehicle(r, vehicle) {
v := vehicle.ToStorageType() v := vehicle.ToStorageType()
vehicles_map[v.ID] = v vehicles_map[v.ID] = v
bookings = append(bookings, v.Bookings...) // bookings = append(bookings, v.Bookings...)
for _, b := range v.Bookings {
if v, ok := b.Data["administrator_unavailability"].(bool); !ok || !v {
bookings = append(bookings, b)
}
}
} }
} }
@@ -227,22 +232,17 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite
vars := mux.Vars(r) vars := mux.Vars(r)
bookingid := vars["bookingid"] bookingid := vars["bookingid"]
request := &fleets.GetBookingRequest{ booking, err := h.services.GetBooking(bookingid)
Bookingid: bookingid,
}
resp, err := h.services.GRPC.Fleets.GetBooking(context.TODO(), request)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
booking := resp.Booking.ToStorageType()
if r.Method == "POST" { if r.Method == "POST" {
r.ParseForm() r.ParseForm()
newbooking := resp.Booking newbooking, _ := fleets.BookingFromStorageType(&booking)
startdate := r.FormValue("startdate") startdate := r.FormValue("startdate")
if startdate != "" { if startdate != "" {
@@ -318,10 +318,61 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite
return return
} }
alternativerequest := &fleets.GetVehiclesRequest{
Namespaces: []string{"parcoursmob"},
AvailabilityFrom: timestamppb.New(booking.Startdate),
AvailabilityTo: timestamppb.New(booking.Enddate.Add(24 * time.Hour)),
}
alternativeresp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), alternativerequest)
if err != nil {
fmt.Println(err)
}
alternatives := []any{}
for _, a := range alternativeresp.Vehicles {
alternatives = append(alternatives, a.ToStorageType())
}
documents := h.filestorage.List(filestorage.PREFIX_BOOKINGS + "/" + bookingid) documents := h.filestorage.List(filestorage.PREFIX_BOOKINGS + "/" + bookingid)
file_types_map := h.config.GetStringMapString("storage.files.file_types") file_types_map := h.config.GetStringMapString("storage.files.file_types")
h.Renderer.VehicleManagementBookingDisplay(w, r, booking, booking.Vehicle, beneficiary, groupresp.Group.ToStorageType(), documents, file_types_map) h.Renderer.VehicleManagementBookingDisplay(w, r, booking, booking.Vehicle, beneficiary, groupresp.Group.ToStorageType(), documents, file_types_map, alternatives)
}
func (h ApplicationHandler) VehicleManagementBookingChangeVehicle(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bookingid := vars["bookingid"]
r.ParseForm()
newvehicle := r.FormValue("vehicle")
booking, err := h.services.GetBooking(bookingid)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
booking.Vehicleid = newvehicle
b, _ := fleets.BookingFromStorageType(&booking)
request := &fleets.UpdateBookingRequest{
Booking: b,
}
_, err = h.services.GRPC.Fleets.UpdateBooking(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/bookings/%s", bookingid), http.StatusFound)
} }
func (h ApplicationHandler) VehiclesFleetMakeUnavailable(w http.ResponseWriter, r *http.Request) { // Get Group func (h ApplicationHandler) VehiclesFleetMakeUnavailable(w http.ResponseWriter, r *http.Request) { // Get Group

View File

@@ -13,11 +13,11 @@ import (
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting" "git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi" fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
"git.coopgo.io/coopgo-platform/fleets/storage"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi" groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
"git.coopgo.io/coopgo-platform/groups-management/storage" groupsmanagementstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi" mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
"github.com/coreos/go-oidc"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"google.golang.org/protobuf/types/known/structpb" "google.golang.org/protobuf/types/known/structpb"
@@ -137,31 +137,44 @@ func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Reques
func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) { func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
// Get Group // Get Group
g := r.Context().Value(identification.GroupKey) // g := r.Context().Value(identification.GroupKey)
if g == nil { // if g == nil {
fmt.Println("no current group") // fmt.Println("no current group")
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// current_group := g.(storage.Group)
current_group, err := h.currentGroup(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
current_group := g.(storage.Group)
// Get current user ID // Get current user ID
u := r.Context().Value(identification.IdtokenKey) // u := r.Context().Value(identification.IdtokenKey)
if u == nil { // if u == nil {
fmt.Println("no current user") // fmt.Println("no current user")
w.WriteHeader(http.StatusInternalServerError) // w.WriteHeader(http.StatusInternalServerError)
return // return
} // }
current_user_token := u.(*oidc.IDToken) // current_user_token := u.(*oidc.IDToken)
// Get current user claims // // Get current user claims
c := r.Context().Value(identification.ClaimsKey) // c := r.Context().Value(identification.ClaimsKey)
if c == nil { // if c == nil {
fmt.Println("no current user claims") // fmt.Println("no current user claims")
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// current_user_claims := c.(map[string]any)
current_user_token, current_user_claims, err := h.currentUser(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
current_user_claims := c.(map[string]any)
vars := mux.Vars(r) vars := mux.Vars(r)
vehicleid := vars["vehicleid"] vehicleid := vars["vehicleid"]
@@ -324,6 +337,15 @@ func (h ApplicationHandler) VehicleBookingDisplay(w http.ResponseWriter, r *http
} }
func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.Request) { func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.Request) {
g := r.Context().Value(identification.GroupKey)
if g == nil {
w.WriteHeader(http.StatusBadRequest)
return
}
group := g.(groupsmanagementstorage.Group)
request := &fleets.GetBookingsRequest{} request := &fleets.GetBookingsRequest{}
resp, err := h.services.GRPC.Fleets.GetBookings(context.TODO(), request) resp, err := h.services.GRPC.Fleets.GetBookings(context.TODO(), request)
if err != nil { if err != nil {
@@ -332,11 +354,21 @@ func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.
return return
} }
bookings := []any{} bookings := []storage.Booking{}
for _, b := range resp.Bookings { for _, b := range resp.Bookings {
bookings = append(bookings, b.ToStorageType()) booking := b.ToStorageType()
if b1, ok := booking.Data["booked_by"].(map[string]any); ok {
if b2, ok := b1["group"].(map[string]any); ok {
if b2["id"] == group.ID {
bookings = append(bookings, booking)
} }
}
}
}
sort.Sort(sorting.BookingsByStartdate(bookings))
h.Renderer.VehicleBookingsList(w, r, bookings) h.Renderer.VehicleBookingsList(w, r, bookings)
} }

View File

@@ -97,6 +97,7 @@ 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)
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/create-event", applicationHandler.AgendaCreateEvent) application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent)
@@ -107,14 +108,20 @@ func main() {
application.HandleFunc("/group/settings", applicationHandler.GroupSettingsDisplay) application.HandleFunc("/group/settings", applicationHandler.GroupSettingsDisplay)
application.HandleFunc("/group/settings/invite-member", applicationHandler.GroupSettingsInviteMember) application.HandleFunc("/group/settings/invite-member", applicationHandler.GroupSettingsInviteMember)
/****************************Groupe Déplacement ************************************/
application.HandleFunc("/journeys/groups_covoiturage", applicationHandler.GroupsGestion)
application.HandleFunc("/journeys/groups_covoiturage/create", applicationHandler.CreateGroup)
application.HandleFunc("/journeys/groups_covoiturage/create/{groupid}", applicationHandler.DisplayGroupCovoiturage)
/****************************************************************/
/********************Code Supprt Emailing************************/ /********************Code Supprt Emailing************************/
application.HandleFunc("/support/", applicationHandler.SupportSend) application.HandleFunc("/support/", applicationHandler.SupportSend)
/*********************** CODE GROUP **************************/ /*********************** CODE GROUP **************************/
appGroup := application.PathPrefix("/group_module").Subrouter() appGroup := application.PathPrefix("/group_module").Subrouter()
appGroup.HandleFunc("/", applicationHandler.Groups) appGroup.HandleFunc("/", applicationHandler.Groups)
appGroup.HandleFunc("/groups", applicationHandler.CreateGroupModule) appGroup.HandleFunc("/groups", applicationHandler.CreateGroupModule)
appGroup.HandleFunc("/groups/{groupid}", applicationHandler.DisplayGroupModule) appGroup.HandleFunc("/groups/{groupid}", applicationHandler.DisplayGroupModule)
/****************************************************************/
//TODO Subrouters with middlewares checking security for each module ? //TODO Subrouters with middlewares checking security for each module ?
application.Use(idp.Middleware) application.Use(idp.Middleware)

View File

@@ -8,10 +8,13 @@ import (
const administrationMenu = "administration" const administrationMenu = "administration"
func (renderer *Renderer) Administration(w http.ResponseWriter, r *http.Request, groups any) { func (renderer *Renderer) Administration(w http.ResponseWriter, r *http.Request, accounts any, beneficiaries any, groups any, bookings any) {
files := renderer.ThemeConfig.GetStringSlice("views.administration.home.files") files := renderer.ThemeConfig.GetStringSlice("views.administration.home.files")
state := NewState(r, renderer.ThemeConfig, administrationMenu) state := NewState(r, renderer.ThemeConfig, administrationMenu)
state.ViewState = map[string]any{ state.ViewState = map[string]any{
"accounts": accounts,
"beneficiaries": beneficiaries,
"bookings": bookings,
"groups": groups, "groups": groups,
} }

View File

@@ -52,7 +52,7 @@ type BeneficiariesDisplayState struct {
Beneficiary any Beneficiary any
} }
func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, bookings []any, beneficiaries_file_types []string, file_types_map map[string]string, documents any) { func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, bookings []any, organizations []any, beneficiaries_file_types []string, file_types_map map[string]string, documents any) {
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files") files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files")
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu) state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
state.ViewState = map[string]any{ state.ViewState = map[string]any{
@@ -61,6 +61,7 @@ func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Requ
"beneficiaries_file_types": beneficiaries_file_types, "beneficiaries_file_types": beneficiaries_file_types,
"file_types_map": file_types_map, "file_types_map": file_types_map,
"documents": documents, "documents": documents,
"organizations": organizations,
} }
renderer.Render("beneficiaries_display", w, r, files, state) renderer.Render("beneficiaries_display", w, r, files, state)

View File

@@ -23,6 +23,17 @@ func TimeFrom(d any) *time.Time {
return nil return nil
} }
func TimeFormat(d any, f string) string {
date := TimeFrom(d)
if date == nil {
return ""
}
if date.Before(time.Now().Add(-24 * 365 * 30 * time.Hour)) {
return ""
}
return date.Format(f)
}
func GenderISO5218(d any) string { func GenderISO5218(d any) string {
if date, ok := d.(string); ok { if date, ok := d.(string); ok {
switch date { switch date {

View File

@@ -1,9 +1,41 @@
package renderer package renderer
import "net/http" import (
"encoding/json"
"html/template"
"net/http"
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
)
const journeysMenu = "journeys" const journeysMenu = "journeys"
type BeneficiariesCovoiturage struct {
Group string `json:"group"`
Count int `json:"count"`
CacheId string `json:"cache_id"`
Beneficiaries []any `json:"beneficiaries"`
}
type BeneficiariesCovoiturageA struct {
//Group string `json:"group"`
Count int `json:"count"`
CacheId string `json:"cache_id"`
Beneficiaries []any `json:"beneficiaries"`
}
func (s BeneficiariesCovoiturage) JSON() template.JS {
result, _ := json.Marshal(s)
return template.JS(result)
}
func (s BeneficiariesCovoiturage) JSONWithLimits(a int, b int) template.JS {
if b < len(s.Beneficiaries) {
s.Beneficiaries = s.Beneficiaries[a:b]
}
return s.JSON()
}
func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request, carpools any, transitjourneys any, vehicles []any, searched bool, departure any, destination any, departuredate string, departuretime string) { func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request, carpools any, transitjourneys any, vehicles []any, searched bool, departure any, destination any, departuredate string, departuretime string) {
files := renderer.ThemeConfig.GetStringSlice("views.journeys.search.files") files := renderer.ThemeConfig.GetStringSlice("views.journeys.search.files")
state := NewState(r, renderer.ThemeConfig, journeysMenu) state := NewState(r, renderer.ThemeConfig, journeysMenu)
@@ -20,3 +52,98 @@ func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request,
renderer.Render("journeys", w, r, files, state) renderer.Render("journeys", w, r, files, state)
} }
type BeneficiariesListstate struct {
Count int `json:"count"`
CacheId string `json:"cache_id"`
Beneficiaries []groupstorage.Group `json:"beneficiaries"`
}
func (s BeneficiariesListstate) JSON() template.JS {
result, _ := json.Marshal(s)
return template.JS(result)
}
func (s BeneficiariesListstate) JSONWithLimits(a int, b int) template.JS {
if b < len(s.Beneficiaries) {
s.Beneficiaries = s.Beneficiaries[a:b]
}
return s.JSON()
}
func (renderer *Renderer) GroupsGestion(w http.ResponseWriter, r *http.Request, groups []groupstorage.Group, cacheid string) {
files := renderer.ThemeConfig.GetStringSlice("views.journeys.list.files")
state := NewState(r, renderer.ThemeConfig, journeysMenu)
// state.ViewState = map[string]any{
// "groups": groups,
// }
//state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
state.ViewState = BeneficiariesListstate{
Count: len(groups),
CacheId: cacheid,
Beneficiaries: groups,
}
renderer.Render("journeys", w, r, files, state)
}
func (renderer *Renderer) CreateGroup(w http.ResponseWriter, r *http.Request, depart any, arrive any, searched bool, beneficiary any, beneficiaries []mobilityaccountsstorage.Account, departure any, destination any) {
files := renderer.ThemeConfig.GetStringSlice("views.journeys.create.files")
state := NewState(r, renderer.ThemeConfig, journeysMenu)
// state.ViewState = map[string]any{
// "departure": depart,
// "destination": arrive,
// //"beneficiary": beneficiary,
// //"accounts": accounts,
// // "cacheid": cacheid,
// // "searched": searched,
// }
viewstate := map[string]any{
"deeparture": depart,
"deestination": arrive,
"beneficiaries": beneficiaries,
"searched": searched,
"departure": departure,
"destination": destination,
// "departuredate": departuredate,
// "departuretime": departuretime,
}
if searched {
viewstate["search"] = map[string]any{
"beneficiary": beneficiary,
}
}
state.ViewState = viewstate
renderer.Render("journeys", w, r, files, state)
}
func (renderer *Renderer) DisplayGroupCovoiturage(w http.ResponseWriter, r *http.Request, groupid string, accounts []any, cacheid string, searched bool, beneficiary any, group any, beneficiaries []mobilityaccountsstorage.Account) {
files := renderer.ThemeConfig.GetStringSlice("views.journeys.display.files")
state := NewState(r, renderer.ThemeConfig, journeysMenu)
viewstate := map[string]any{
"beneficiaries": beneficiaries,
"searched": searched,
"group": group,
"list": BeneficiariesCovoiturage{
Group: groupid,
Count: len(accounts),
CacheId: cacheid,
Beneficiaries: accounts,
},
}
if searched {
viewstate["search"] = map[string]any{
"beneficiary": beneficiary,
}
}
state.ViewState = viewstate
renderer.Render("journeys", w, r, files, state)
}

View File

@@ -9,6 +9,7 @@ import (
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification" "git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
"git.coopgo.io/coopgo-platform/emailing" "git.coopgo.io/coopgo-platform/emailing"
"git.coopgo.io/coopgo-platform/groups-management/storage" "git.coopgo.io/coopgo-platform/groups-management/storage"
"github.com/coreos/go-oidc"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@@ -35,6 +36,7 @@ func NewRenderer(global *viper.Viper, templates_dir string) *Renderer {
} }
func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Request, files []string, state RenderState) { func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Request, files []string, state RenderState) {
genericFiles := renderer.ThemeConfig.GetStringSlice("views.generic.files") genericFiles := renderer.ThemeConfig.GetStringSlice("views.generic.files")
prefixed_files := []string{} prefixed_files := []string{}
@@ -49,6 +51,7 @@ func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Req
t := template.New(name).Funcs( t := template.New(name).Funcs(
template.FuncMap{ template.FuncMap{
"timeFrom": TimeFrom, "timeFrom": TimeFrom,
"timeFormat": TimeFormat,
"genderISO5218": GenderISO5218, "genderISO5218": GenderISO5218,
"dict": Dict, "dict": Dict,
"json": JSON, "json": JSON,
@@ -66,6 +69,7 @@ func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Req
} }
func (renderer *Renderer) RenderNoLayout(name string, w http.ResponseWriter, r *http.Request, files []string, state RenderState) { func (renderer *Renderer) RenderNoLayout(name string, w http.ResponseWriter, r *http.Request, files []string, state RenderState) {
prefixed_files := []string{} prefixed_files := []string{}
for _, f := range files { for _, f := range files {
prefixed_files = append(prefixed_files, renderer.templateFile(f)) prefixed_files = append(prefixed_files, renderer.templateFile(f))
@@ -75,6 +79,7 @@ func (renderer *Renderer) RenderNoLayout(name string, w http.ResponseWriter, r *
t := template.New(name).Funcs( t := template.New(name).Funcs(
template.FuncMap{ template.FuncMap{
"timeFrom": TimeFrom, "timeFrom": TimeFrom,
"timeFormat": TimeFormat,
"genderISO5218": GenderISO5218, "genderISO5218": GenderISO5218,
"dict": Dict, "dict": Dict,
"json": JSON, "json": JSON,
@@ -97,14 +102,34 @@ func (r *Renderer) templateFile(file string) string {
type RenderState struct { type RenderState struct {
icons.IconSet icons.IconSet
LayoutState LayoutState
Group any UserID string
UserClaims map[string]any
Group storage.Group
Roles any Roles any
ViewState any // This is a state specific to a given view ViewState any // This is a state specific to a given view
} }
func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) RenderState { func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) RenderState {
iconset := themeConfig.GetStringMapString("icons.svg") iconset := themeConfig.GetStringMapString("icons.svg")
// Get State elements from Request // Get State elements from Request
var userid string
var claims map[string]any
u := r.Context().Value(identification.IdtokenKey)
if u != nil {
if current_user_token, ok := u.(*oidc.IDToken); ok {
userid = current_user_token.Subject
}
c := r.Context().Value(identification.ClaimsKey)
if c != nil {
if current_user_claims, ok := c.(map[string]any); ok {
claims = current_user_claims
}
}
}
g := r.Context().Value(identification.GroupKey) g := r.Context().Value(identification.GroupKey)
if g == nil { if g == nil {
@@ -187,7 +212,6 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
}) })
} }
/*************************** my code ******************************/
if modules["support"] != nil && modules["support"].(bool) { if modules["support"] != nil && modules["support"].(bool) {
ls.MenuItems = append(ls.MenuItems, MenuItem{ ls.MenuItems = append(ls.MenuItems, MenuItem{
Title: "Support", Title: "Support",
@@ -197,7 +221,7 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
}) })
} }
/******************************************************************/
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",
@@ -207,7 +231,6 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
}) })
} }
/*************************** my code ******************************/
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{
@@ -222,6 +245,8 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
IconSet: icons.NewIconSet(iconset), IconSet: icons.NewIconSet(iconset),
Group: group, Group: group,
Roles: roles, Roles: roles,
UserID: userid,
UserClaims: claims,
LayoutState: ls, LayoutState: ls,
} }
} }

View File

@@ -63,7 +63,7 @@ func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Req
renderer.Render("fleet display vehicle", w, r, files, state) 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, documents []filestorage.FileInfo, file_types_map map[string]string) { 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, alternative_vehicles []any) {
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.booking_display.files") files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.booking_display.files")
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
state.ViewState = map[string]any{ state.ViewState = map[string]any{
@@ -73,6 +73,7 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter,
"group": group, "group": group,
"documents": documents, "documents": documents,
"file_types_map": file_types_map, "file_types_map": file_types_map,
"alternative_vehicles": alternative_vehicles,
} }
renderer.Render("vehicles search", w, r, files, state) renderer.Render("vehicles search", w, r, files, state)

View File

@@ -4,6 +4,7 @@ import (
"net/http" "net/http"
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
"git.coopgo.io/coopgo-platform/fleets/storage"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
) )
@@ -66,7 +67,7 @@ func (renderer *Renderer) VehicleBookingDisplay(w http.ResponseWriter, r *http.R
renderer.Render("vehicles search", w, r, files, state) renderer.Render("vehicles search", w, r, files, state)
} }
func (renderer *Renderer) VehicleBookingsList(w http.ResponseWriter, r *http.Request, bookings []any) { func (renderer *Renderer) VehicleBookingsList(w http.ResponseWriter, r *http.Request, bookings []storage.Booking) {
files := renderer.ThemeConfig.GetStringSlice("views.vehicles.bookings_list.files") files := renderer.ThemeConfig.GetStringSlice("views.vehicles.bookings_list.files")
state := NewState(r, renderer.ThemeConfig, vehiclesMenu) state := NewState(r, renderer.ThemeConfig, vehiclesMenu)
state.ViewState = map[string]any{ state.ViewState = map[string]any{

View File

@@ -1,7 +1,12 @@
package services package services
import ( import (
"context"
"sort"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi" fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
"git.coopgo.io/coopgo-platform/fleets/storage"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@@ -21,3 +26,29 @@ func NewFleetsService(dial string) (*FleetsService, error) {
FleetsClient: client, FleetsClient: client,
}, nil }, nil
} }
func (s *ServicesHandler) GetBooking(bookingid string) (booking storage.Booking, err error) {
request := &fleets.GetBookingRequest{
Bookingid: bookingid,
}
resp, err := s.GRPC.Fleets.GetBooking(context.TODO(), request)
if err == nil {
booking = resp.Booking.ToStorageType()
}
return
}
func (s *ServicesHandler) GetBookings() (bookings []storage.Booking, err error) {
bookings = []storage.Booking{}
request := &fleets.GetBookingsRequest{}
resp, err := s.GRPC.Fleets.GetBookings(context.TODO(), request)
if err == nil {
for _, booking := range resp.Bookings {
bookings = append(bookings, booking.ToStorageType())
}
sort.Sort(sorting.BookingsByStartdate(bookings))
}
return
}

View File

@@ -1,7 +1,10 @@
package services package services
import ( import (
"context"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi" mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
"git.coopgo.io/coopgo-platform/mobility-accounts/storage"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@@ -21,3 +24,37 @@ func NewMobilityAccountService(mobilityAccountsDial string) (*MobilityAccountSer
MobilityAccountsClient: client, MobilityAccountsClient: client,
}, nil }, nil
} }
func (s *ServicesHandler) GetBeneficiaries() (accounts []storage.Account, err error) {
accounts = []storage.Account{}
request := &mobilityaccounts.GetAccountsRequest{
Namespaces: []string{"parcoursmob_beneficiaries"},
}
resp, err := s.GRPC.MobilityAccounts.GetAccounts(context.TODO(), request)
if err == nil {
for _, v := range resp.Accounts {
a := v.ToStorageType()
accounts = append(accounts, a)
}
}
return
}
func (s *ServicesHandler) GetAccounts() (accounts []storage.Account, err error) {
accounts = []storage.Account{}
request := &mobilityaccounts.GetAccountsRequest{
Namespaces: []string{"parcoursmob"},
}
resp, err := s.GRPC.MobilityAccounts.GetAccounts(context.TODO(), request)
if err == nil {
for _, v := range resp.Accounts {
a := v.ToStorageType()
accounts = append(accounts, a)
}
}
return
}