Compare commits
24 Commits
groupsCovo
...
addStatist
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7847b4c31f | ||
|
|
a63a4ad1c2 | ||
|
|
232764e7d7 | ||
|
|
e4418f26e0 | ||
|
|
a05942b7ed | ||
|
|
1b2902c632 | ||
|
|
c9b326c49a | ||
|
|
c3e67cb9dd | ||
|
|
795066b6e5 | ||
|
|
bdcb386dff | ||
|
|
64521c01c1 | ||
|
|
3b9ac66965 | ||
|
|
167e8cfe2e | ||
|
|
f023a7bbff | ||
|
|
d1818b6251 | ||
|
|
fa065f2a43 | ||
|
|
e559359ff0 | ||
|
|
9965271788 | ||
|
|
97ebcf480e | ||
| 1b847ea216 | |||
| 0c0a9d0496 | |||
|
|
d531fe63ff | ||
|
|
47a2b1a3cb | ||
|
|
d9f5721a15 |
@@ -10,8 +10,14 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||||
|
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
||||||
|
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||||
|
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||||
|
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
||||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||||
|
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||||
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||||
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
accounts "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"
|
||||||
@@ -62,8 +68,39 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque
|
|||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(sorting.GroupsByName(groups))
|
sort.Sort(sorting.GroupsByName(groups))
|
||||||
|
////////////////////////////////////add event////////////////////////////////////////////
|
||||||
|
rresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||||
|
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||||
|
})
|
||||||
|
|
||||||
h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings)
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
responses := []agendastorage.Event{}
|
||||||
|
|
||||||
|
groupids := []string{}
|
||||||
|
for _, e := range rresp.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,
|
||||||
|
})
|
||||||
|
groupps := map[string]any{}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
for _, g := range groupsresp.Groups {
|
||||||
|
groupps[g.Id] = g.ToStorageType()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings, responses)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -86,6 +123,8 @@ func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r
|
|||||||
"agenda": r.FormValue("modules.agenda") == "on",
|
"agenda": r.FormValue("modules.agenda") == "on",
|
||||||
"groups": r.FormValue("modules.groups") == "on",
|
"groups": r.FormValue("modules.groups") == "on",
|
||||||
"administration": r.FormValue("modules.administration") == "on",
|
"administration": r.FormValue("modules.administration") == "on",
|
||||||
|
"support": r.FormValue("modules.support") == "on",
|
||||||
|
"group_module": r.FormValue("modules.group_module") == "on",
|
||||||
}
|
}
|
||||||
|
|
||||||
groupid := uuid.NewString()
|
groupid := uuid.NewString()
|
||||||
@@ -329,6 +368,76 @@ func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWrit
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filteVehicle(r *http.Request, v *fleets.Vehicle) bool {
|
||||||
|
g := r.Context().Value(identification.GroupKey)
|
||||||
|
if g == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
group := g.(storage.Group)
|
||||||
|
|
||||||
|
for _, n := range v.Administrators {
|
||||||
|
if n == group.ID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
bookings := []fleetsstorage.Booking{}
|
||||||
|
administrators := []string{}
|
||||||
|
reequest := &fleets.GetVehiclesRequest{
|
||||||
|
Namespaces: []string{"parcoursmob"},
|
||||||
|
}
|
||||||
|
reesp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), reequest)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
vehicles := []fleetsstorage.Vehicle{}
|
||||||
|
for _, vehiicle := range reesp.Vehicles {
|
||||||
|
|
||||||
|
v := vehiicle.ToStorageType()
|
||||||
|
adminfound := false
|
||||||
|
for _, a := range administrators {
|
||||||
|
if a == v.Administrators[0] {
|
||||||
|
adminfound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !adminfound {
|
||||||
|
administrators = append(administrators, v.Administrators[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
vehicles = append(vehicles, v)
|
||||||
|
|
||||||
|
}
|
||||||
|
groups := map[string]any{}
|
||||||
|
|
||||||
|
if len(administrators) > 0 {
|
||||||
|
admingroups, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||||
|
Groupids: administrators,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, g := range admingroups.Groups {
|
||||||
|
groups[g.Id] = g.ToStorageType()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
sort.Sort(sorting.VehiclesByLicencePlate(vehicles))
|
||||||
|
sort.Sort(sorting.BookingsByStartdate(bookings))
|
||||||
|
h.Renderer.AdminStatVehicles(w, r, vehicles, bookings, groups)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) members() ([]*accounts.Account, error) {
|
func (h *ApplicationHandler) members() ([]*accounts.Account, error) {
|
||||||
resp, err := h.services.GRPC.MobilityAccounts.GetAccounts(context.TODO(), &accounts.GetAccountsRequest{
|
resp, err := h.services.GRPC.MobilityAccounts.GetAccounts(context.TODO(), &accounts.GetAccountsRequest{
|
||||||
Namespaces: []string{"parcoursmob"},
|
Namespaces: []string{"parcoursmob"},
|
||||||
@@ -366,3 +475,49 @@ func (h *ApplicationHandler) groupmembers(groupid string) (groupmembers []mobili
|
|||||||
|
|
||||||
return groupmembers, admins, err
|
return groupmembers, admins, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h ApplicationHandler) AdminStatBeneficaires(w http.ResponseWriter, r *http.Request) {
|
||||||
|
beneficiaries, err := h.services.GetBeneficiaries()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cacheid := uuid.NewString()
|
||||||
|
h.cache.PutWithTTL(cacheid, beneficiaries, 1*time.Hour)
|
||||||
|
h.Renderer.AdminStatBeneficaires(w, r, beneficiaries, cacheid)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h ApplicationHandler) AdminStatEvents(w http.ResponseWriter, r *http.Request) {
|
||||||
|
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||||
|
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||||
|
})
|
||||||
|
|
||||||
|
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.AdminStatEvents(w, r, responses, groups)
|
||||||
|
}
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ func (h *ApplicationHandler) AgendaHome(w http.ResponseWriter, r *http.Request)
|
|||||||
groups[g.Id] = g.ToStorageType()
|
groups[g.Id] = g.ToStorageType()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Renderer.AgendaHome(w, r, responses, groups)
|
h.Renderer.AgendaHome(w, r, responses, groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Re
|
|||||||
|
|
||||||
cacheid := uuid.NewString()
|
cacheid := uuid.NewString()
|
||||||
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
||||||
|
|
||||||
h.Renderer.BeneficiariesList(w, r, accounts, cacheid)
|
h.Renderer.BeneficiariesList(w, r, accounts, cacheid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) BeneficiaryCreate(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) BeneficiaryCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
g := r.Context().Value(identification.GroupKey)
|
g := r.Context().Value(identification.GroupKey)
|
||||||
if g == nil {
|
if g == nil {
|
||||||
|
fmt.Println("Create beneficiary : could not find group")
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,35 +5,14 @@ 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()
|
||||||
|
|
||||||
@@ -165,334 +144,3 @@ 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)
|
|
||||||
}
|
|
||||||
|
|||||||
213
handlers/application/members.go
Normal file
213
handlers/application/members.go
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
package application
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
|
||||||
|
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||||
|
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"google.golang.org/protobuf/types/known/structpb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserForm struct {
|
||||||
|
FirstName string `json:"first_name" validate:"required"`
|
||||||
|
LastName string `json:"last_name" validate:"required"`
|
||||||
|
Email string `json:"email" validate:"required,email"`
|
||||||
|
PhoneNumber string `json:"phone_number" validate:"required,phoneNumber"`
|
||||||
|
Address any `json:"address,omitempty"`
|
||||||
|
Gender string `json:"gender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ApplicationHandler) MemberDisplay(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
adm := strings.Split(r.URL.Path, "/")
|
||||||
|
adminid := adm[3]
|
||||||
|
|
||||||
|
request := &mobilityaccounts.GetAccountRequest{
|
||||||
|
Id: adminid,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//////////////////////////////////add organisations/////////////////////////////////////////////////
|
||||||
|
|
||||||
|
var allIds []string
|
||||||
|
for _, v := range resp.Account.ToStorageType().Data["groups"].([]any) {
|
||||||
|
s := fmt.Sprintf("%v", v)
|
||||||
|
if !(strings.Contains(s, "admin")) {
|
||||||
|
allIds = append(allIds, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reques := &groupsmanagement.GetGroupsBatchRequest{
|
||||||
|
Groupids: allIds,
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), reques)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var groupsName []string
|
||||||
|
|
||||||
|
for _, group := range res.Groups {
|
||||||
|
g := fmt.Sprintf("%v", group.ToStorageType().Data["name"])
|
||||||
|
groupsName = append(groupsName, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Renderer.MemberDisplay(w, r, resp.Account.ToStorageType(), groupsName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ApplicationHandler) MemberUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
adm := strings.Split(r.URL.Path, "/")
|
||||||
|
userID := adm[3]
|
||||||
|
|
||||||
|
if r.Method == "POST" {
|
||||||
|
|
||||||
|
dataMap, err := parseUserForm(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := structpb.NewValue(dataMap)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
request := &mobilityaccounts.UpdateDataRequest{
|
||||||
|
Account: &mobilityaccounts.Account{
|
||||||
|
Id: userID,
|
||||||
|
Namespace: "parcoursmob",
|
||||||
|
Data: data.GetStructValue(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.MobilityAccounts.UpdateData(context.TODO(), request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, fmt.Sprintf("/app/members/%s", resp.Account.Id), http.StatusFound)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
request := &mobilityaccounts.GetAccountRequest{
|
||||||
|
Id: userID,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Renderer.MemberUpdate(w, r, resp.Account.ToStorageType())
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseUserForm(r *http.Request) (map[string]any, error) {
|
||||||
|
if err := r.ParseForm(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
formData := UserForm{
|
||||||
|
FirstName: r.PostFormValue("first_name"),
|
||||||
|
LastName: r.PostFormValue("last_name"),
|
||||||
|
Email: r.PostFormValue("email"),
|
||||||
|
PhoneNumber: r.PostFormValue("phone_number"),
|
||||||
|
Gender: r.PostFormValue("gender"),
|
||||||
|
}
|
||||||
|
|
||||||
|
validate := formvalidators.New()
|
||||||
|
if err := validate.Struct(formData); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
d, err := json.Marshal(formData)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var dataMap map[string]any
|
||||||
|
err = json.Unmarshal(d, &dataMap)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataMap, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ApplicationHandler) MembersList(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
accounts, err := h.services.GetAccounts()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var groupsName []string
|
||||||
|
|
||||||
|
for _, v := range accounts {
|
||||||
|
adminid := v.ID
|
||||||
|
request := &mobilityaccounts.GetAccountRequest{
|
||||||
|
Id: adminid,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//////////////////////////////////add organisations/////////////////////////////////////////////////
|
||||||
|
|
||||||
|
var allIds []string
|
||||||
|
for _, v := range resp.Account.ToStorageType().Data["groups"].([]any) {
|
||||||
|
s := fmt.Sprintf("%v", v)
|
||||||
|
if !(strings.Contains(s, "admin")) {
|
||||||
|
allIds = append(allIds, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
reques := &groupsmanagement.GetGroupsBatchRequest{
|
||||||
|
Groupids: allIds,
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), reques)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
g := ""
|
||||||
|
for _, group := range res.Groups {
|
||||||
|
g += fmt.Sprintf("%v", group.ToStorageType().Data["name"]) + " "
|
||||||
|
}
|
||||||
|
groupsName = append(groupsName, g)
|
||||||
|
|
||||||
|
}
|
||||||
|
cacheid := uuid.NewString()
|
||||||
|
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
||||||
|
|
||||||
|
h.Renderer.MembersList(w, r, accounts, cacheid, groupsName)
|
||||||
|
}
|
||||||
@@ -52,10 +52,16 @@ func (h *ApplicationHandler) VehiclesManagementOverview(w http.ResponseWriter, r
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +190,10 @@ func (h *ApplicationHandler) VehiclesFleetDisplay(w http.ResponseWriter, r *http
|
|||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
|
||||||
|
// fmt.Println("lol")
|
||||||
|
// }
|
||||||
|
// fmt.Println(resp.Vehicle.ToStorageType().Bookings)
|
||||||
h.Renderer.VehiclesFleetDisplay(w, r, resp.Vehicle.ToStorageType())
|
h.Renderer.VehiclesFleetDisplay(w, r, resp.Vehicle.ToStorageType())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,3 +466,28 @@ 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) {
|
||||||
|
// request := &fleets.GetVehiclesRequest{
|
||||||
|
// Namespaces: []string{"parcoursmob"},
|
||||||
|
// }
|
||||||
|
// resp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), request)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
// }
|
||||||
|
// vehicles := []fleetsstorage.Vehicle{}
|
||||||
|
// fmt.Println(resp.Vehicles[0].Bookings)
|
||||||
|
// for i, vehicle := range resp.Vehicles {
|
||||||
|
// if len(resp.Vehicles[i].Bookings) == 0 {
|
||||||
|
// v := vehicle.ToStorageType()
|
||||||
|
// vehicles = append(vehicles, v)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// // if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
|
||||||
|
// // h.Renderer.UnbookingVehicles(w, r, resp.Vehicle.ToStorageType())
|
||||||
|
// // }
|
||||||
|
// // fmt.Println(resp.Vehicle.ToStorageType().Bookings)
|
||||||
|
// fmt.Println(vehicles)
|
||||||
|
// h.Renderer.UnbookingVehicles(w, r, vehicles)
|
||||||
|
// }
|
||||||
|
|||||||
@@ -136,14 +136,7 @@ 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
|
fmt.Println("Book")
|
||||||
// g := r.Context().Value(identification.GroupKey)
|
|
||||||
// if g == nil {
|
|
||||||
// fmt.Println("no current group")
|
|
||||||
// w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// current_group := g.(storage.Group)
|
|
||||||
current_group, err := h.currentGroup(r)
|
current_group, err := h.currentGroup(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -151,24 +144,6 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current user ID
|
|
||||||
// u := r.Context().Value(identification.IdtokenKey)
|
|
||||||
// if u == nil {
|
|
||||||
// fmt.Println("no current user")
|
|
||||||
// w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// current_user_token := u.(*oidc.IDToken)
|
|
||||||
|
|
||||||
// // Get current user claims
|
|
||||||
// c := r.Context().Value(identification.ClaimsKey)
|
|
||||||
// if c == nil {
|
|
||||||
// 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)
|
current_user_token, current_user_claims, err := h.currentUser(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -191,7 +166,7 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
r.ParseMultipartForm(10 * 1024 * 1024)
|
r.ParseMultipartForm(100 * 1024 * 1024)
|
||||||
|
|
||||||
start := r.FormValue("startdate")
|
start := r.FormValue("startdate")
|
||||||
end := r.FormValue("enddate")
|
end := r.FormValue("enddate")
|
||||||
@@ -203,7 +178,7 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
|||||||
"booked_by": map[string]any{
|
"booked_by": map[string]any{
|
||||||
"user": map[string]any{
|
"user": map[string]any{
|
||||||
"id": current_user_token.Subject,
|
"id": current_user_token.Subject,
|
||||||
"display_name": current_user_claims["display_name"],
|
"display_name": fmt.Sprintf("%s %s", current_user_claims["first_name"], current_user_claims["last_name"]),
|
||||||
},
|
},
|
||||||
"group": map[string]any{
|
"group": map[string]any{
|
||||||
"id": current_group.ID,
|
"id": current_group.ID,
|
||||||
@@ -233,7 +208,6 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
|||||||
Booking: booking,
|
Booking: booking,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(r.FormFile("doc-identity_proof"))
|
|
||||||
for _, v := range h.config.GetStringSlice("modules.fleets.booking_documents.mandatory") {
|
for _, v := range h.config.GetStringSlice("modules.fleets.booking_documents.mandatory") {
|
||||||
existing_file := r.FormValue("type-" + v)
|
existing_file := r.FormValue("type-" + v)
|
||||||
if existing_file == "" {
|
if existing_file == "" {
|
||||||
@@ -282,11 +256,13 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
for _, m := range members {
|
for _, m := range members {
|
||||||
h.emailing.Send("fleets.bookings.creation_admin_alert", m.Data["email"].(string), map[string]string{
|
if email, ok := m.Data["email"].(string); ok {
|
||||||
|
h.emailing.Send("fleets.bookings.creation_admin_alert", email, map[string]string{
|
||||||
"bookingid": booking.Id,
|
"bookingid": booking.Id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
http.Redirect(w, r, fmt.Sprintf("/app/vehicles/bookings/%s", booking.Id), http.StatusFound)
|
http.Redirect(w, r, fmt.Sprintf("/app/vehicles/bookings/%s", booking.Id), http.StatusFound)
|
||||||
|
|
||||||
@@ -314,9 +290,9 @@ func (h ApplicationHandler) VehicleBookingDisplay(w http.ResponseWriter, r *http
|
|||||||
|
|
||||||
beneficiaryresp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), beneficiaryrequest)
|
beneficiaryresp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), beneficiaryrequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
beneficiaryresp = &mobilityaccounts.GetAccountResponse{
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
Account: &mobilityaccounts.Account{},
|
||||||
return
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
grouprequest := &groupsmanagement.GetGroupRequest{
|
grouprequest := &groupsmanagement.GetGroupRequest{
|
||||||
@@ -370,7 +346,10 @@ func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.
|
|||||||
|
|
||||||
sort.Sort(sorting.BookingsByStartdate(bookings))
|
sort.Sort(sorting.BookingsByStartdate(bookings))
|
||||||
|
|
||||||
h.Renderer.VehicleBookingsList(w, r, bookings)
|
vehicles, _ := h.services.GetVehiclesMap()
|
||||||
|
groups, _ := h.services.GetGroupsMap()
|
||||||
|
|
||||||
|
h.Renderer.VehicleBookingsList(w, r, bookings, vehicles, groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) BookingDocumentDownload(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) BookingDocumentDownload(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
13
handlers/auth/disconnect.go
Normal file
13
handlers/auth/disconnect.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
func (h *AuthHandler) Disconnect(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := h.idp.SessionsStore.Get(r, "parcoursmob_session")
|
||||||
|
if err == nil {
|
||||||
|
session.Options.MaxAge = -1
|
||||||
|
session.Save(r, w)
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, "/", http.StatusOK)
|
||||||
|
}
|
||||||
16
main.go
16
main.go
@@ -61,6 +61,7 @@ func main() {
|
|||||||
r.PathPrefix("/public/").Handler(http.StripPrefix("/public/", http.FileServer(http.Dir(templates_public_dir))))
|
r.PathPrefix("/public/").Handler(http.StripPrefix("/public/", http.FileServer(http.Dir(templates_public_dir))))
|
||||||
|
|
||||||
r.HandleFunc("/auth/onboarding", authHandler.Onboarding)
|
r.HandleFunc("/auth/onboarding", authHandler.Onboarding)
|
||||||
|
r.HandleFunc("/auth/disconnect", authHandler.Disconnect)
|
||||||
r.HandleFunc("/auth/lost-password", authHandler.LostPasswordInit)
|
r.HandleFunc("/auth/lost-password", authHandler.LostPasswordInit)
|
||||||
r.HandleFunc("/auth/lost-password/recover", authHandler.LostPasswordRecover)
|
r.HandleFunc("/auth/lost-password/recover", authHandler.LostPasswordRecover)
|
||||||
r.HandleFunc("/auth/groups/", authHandler.Groups)
|
r.HandleFunc("/auth/groups/", authHandler.Groups)
|
||||||
@@ -84,6 +85,9 @@ func main() {
|
|||||||
application.HandleFunc("/beneficiaries/{beneficiaryid}/documents/{document}", applicationHandler.BeneficiaryDocumentDownload)
|
application.HandleFunc("/beneficiaries/{beneficiaryid}/documents/{document}", applicationHandler.BeneficiaryDocumentDownload)
|
||||||
application.HandleFunc("/beneficiaries/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
application.HandleFunc("/beneficiaries/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
||||||
application.HandleFunc("/members/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
application.HandleFunc("/members/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
||||||
|
application.HandleFunc("/members/{adminid}", applicationHandler.MemberDisplay)
|
||||||
|
application.HandleFunc("/members/{adminid}/update", applicationHandler.MemberUpdate)
|
||||||
|
application.HandleFunc("/members/", applicationHandler.MembersList)
|
||||||
application.HandleFunc("/journeys/", applicationHandler.JourneysSearch)
|
application.HandleFunc("/journeys/", applicationHandler.JourneysSearch)
|
||||||
application.HandleFunc("/vehicles/", applicationHandler.VehiclesSearch)
|
application.HandleFunc("/vehicles/", applicationHandler.VehiclesSearch)
|
||||||
application.HandleFunc("/vehicles/bookings/", applicationHandler.VehiclesBookingsList)
|
application.HandleFunc("/vehicles/bookings/", applicationHandler.VehiclesBookingsList)
|
||||||
@@ -97,7 +101,6 @@ 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)
|
||||||
@@ -109,9 +112,9 @@ func main() {
|
|||||||
application.HandleFunc("/group/settings/invite-member", applicationHandler.GroupSettingsInviteMember)
|
application.HandleFunc("/group/settings/invite-member", applicationHandler.GroupSettingsInviteMember)
|
||||||
|
|
||||||
/****************************Groupe Déplacement ************************************/
|
/****************************Groupe Déplacement ************************************/
|
||||||
application.HandleFunc("/journeys/groups_covoiturage", applicationHandler.GroupsGestion)
|
// application.HandleFunc("/journeys/groups_covoiturage", applicationHandler.GroupsGestion)
|
||||||
application.HandleFunc("/journeys/groups_covoiturage/create", applicationHandler.CreateGroup)
|
// application.HandleFunc("/journeys/groups_covoiturage/create", applicationHandler.CreateGroup)
|
||||||
application.HandleFunc("/journeys/groups_covoiturage/create/{groupid}", applicationHandler.DisplayGroupCovoiturage)
|
// application.HandleFunc("/journeys/groups_covoiturage/create/{groupid}", applicationHandler.DisplayGroupCovoiturage)
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
|
||||||
/********************Code Supprt Emailing************************/
|
/********************Code Supprt Emailing************************/
|
||||||
@@ -133,7 +136,10 @@ func main() {
|
|||||||
appAdmin.HandleFunc("/groups/{groupid}", applicationHandler.AdministrationGroupDisplay)
|
appAdmin.HandleFunc("/groups/{groupid}", applicationHandler.AdministrationGroupDisplay)
|
||||||
appAdmin.HandleFunc("/groups/{groupid}/invite-admin", applicationHandler.AdministrationGroupInviteAdmin)
|
appAdmin.HandleFunc("/groups/{groupid}/invite-admin", applicationHandler.AdministrationGroupInviteAdmin)
|
||||||
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
|
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
|
||||||
//TODO Secure with Middleware checking for modules
|
//add statistiques
|
||||||
|
appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles)
|
||||||
|
appAdmin.HandleFunc("/stats/beneficaires", applicationHandler.AdminStatBeneficaires)
|
||||||
|
appAdmin.HandleFunc("/stats/events", applicationHandler.AdminStatEvents)
|
||||||
|
|
||||||
fmt.Println("-> HTTP server listening on", address)
|
fmt.Println("-> HTTP server listening on", address)
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
package renderer
|
package renderer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||||
|
fleetsstorage "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"
|
||||||
)
|
)
|
||||||
|
|
||||||
const administrationMenu = "administration"
|
const administrationMenu = "administration"
|
||||||
|
|
||||||
func (renderer *Renderer) Administration(w http.ResponseWriter, r *http.Request, accounts any, beneficiaries any, groups any, bookings any) {
|
func (renderer *Renderer) Administration(w http.ResponseWriter, r *http.Request, accounts any, beneficiaries any, groups any, bookings any, events []agendastorage.Event) {
|
||||||
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{
|
||||||
@@ -16,6 +20,7 @@ func (renderer *Renderer) Administration(w http.ResponseWriter, r *http.Request,
|
|||||||
"beneficiaries": beneficiaries,
|
"beneficiaries": beneficiaries,
|
||||||
"bookings": bookings,
|
"bookings": bookings,
|
||||||
"groups": groups,
|
"groups": groups,
|
||||||
|
"events": events,
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.Render("administration", w, r, files, state)
|
renderer.Render("administration", w, r, files, state)
|
||||||
@@ -39,3 +44,58 @@ func (renderer *Renderer) AdministrationGroupDisplay(w http.ResponseWriter, r *h
|
|||||||
|
|
||||||
renderer.Render("administration", w, r, files, state)
|
renderer.Render("administration", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BeneficiariesState struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
CacheId string `json:"cache_id"`
|
||||||
|
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s BeneficiariesState) JSON() template.JS {
|
||||||
|
result, _ := json.Marshal(s)
|
||||||
|
return template.JS(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s BeneficiariesState) JSONWithLimits(a int, b int) template.JS {
|
||||||
|
if b < len(s.Beneficiaries) {
|
||||||
|
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||||
|
}
|
||||||
|
return s.JSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (renderer *Renderer) AdminStatBeneficaires(w http.ResponseWriter, r *http.Request, Beneficiaries []mobilityaccountsstorage.Account, cacheid string) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.administration.beneficaires_list.files")
|
||||||
|
|
||||||
|
state := NewState(r, renderer.ThemeConfig, administrationMenu)
|
||||||
|
state.ViewState = BeneficiariesState{
|
||||||
|
Count: len(Beneficiaries),
|
||||||
|
CacheId: cacheid,
|
||||||
|
Beneficiaries: Beneficiaries,
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.Render("beneficiaries_State", w, r, files, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (renderer *Renderer) AdminStatEvents(w http.ResponseWriter, r *http.Request, events []agendastorage.Event, groups map[string]any) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.administration.events_list.files")
|
||||||
|
|
||||||
|
state := NewState(r, renderer.ThemeConfig, administrationMenu)
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
"events": events,
|
||||||
|
"groups": groups,
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.Render("beneficiaries_State", w, r, files, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (renderer *Renderer) AdminStatVehicles(w http.ResponseWriter, r *http.Request, vehicles []fleetsstorage.Vehicle, bookings []fleetsstorage.Booking, admingroups map[string]any) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.administration.vehicles_list.files")
|
||||||
|
state := NewState(r, renderer.ThemeConfig, administrationMenu)
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
"vehicles": vehicles,
|
||||||
|
"bookings": bookings,
|
||||||
|
"admingroups": admingroups,
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.Render("vehicles_state", w, r, files, state)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,41 +1,9 @@
|
|||||||
package renderer
|
package renderer
|
||||||
|
|
||||||
import (
|
import "net/http"
|
||||||
"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)
|
||||||
@@ -52,98 +20,3 @@ 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)
|
|
||||||
}
|
|
||||||
|
|||||||
67
renderer/members.go
Normal file
67
renderer/members.go
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package renderer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"html/template"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
const membersMenu = "members"
|
||||||
|
|
||||||
|
func (renderer *Renderer) MemberDisplay(w http.ResponseWriter, r *http.Request, admins any, groups []string) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.members.display.files")
|
||||||
|
|
||||||
|
state := NewState(r, renderer.ThemeConfig, membersMenu)
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
"admins": admins,
|
||||||
|
"groups": groups,
|
||||||
|
}
|
||||||
|
renderer.Render("members_list", w, r, files, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (renderer *Renderer) MemberUpdate(w http.ResponseWriter, r *http.Request, user any) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.members.update.files")
|
||||||
|
state := NewState(r, renderer.ThemeConfig, membersMenu)
|
||||||
|
state.ViewState = user
|
||||||
|
renderer.Render("members_update", w, r, files, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
type MembersListState struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
CacheId string `json:"cache_id"`
|
||||||
|
Members []mobilityaccountsstorage.Account `json:"members"`
|
||||||
|
Groups []string `json:"groups"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s MembersListState) JSON() template.JS {
|
||||||
|
result, _ := json.Marshal(s)
|
||||||
|
return template.JS(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s MembersListState) JSONWithLimits(a int, b int) template.JS {
|
||||||
|
if b < len(s.Members) {
|
||||||
|
s.Members = s.Members[a:b]
|
||||||
|
}
|
||||||
|
return s.JSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (renderer *Renderer) MembersList(w http.ResponseWriter, r *http.Request, accounts []mobilityaccountsstorage.Account, cacheid string, groups []string) {
|
||||||
|
files := renderer.ThemeConfig.GetStringSlice("views.members.list.files")
|
||||||
|
|
||||||
|
state := NewState(r, renderer.ThemeConfig, membersMenu)
|
||||||
|
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
|
||||||
|
"list": MembersListState{
|
||||||
|
Count: len(accounts),
|
||||||
|
CacheId: cacheid,
|
||||||
|
Members: accounts,
|
||||||
|
Groups: groups,
|
||||||
|
},
|
||||||
|
"groups": groups,
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.Render("members_list", w, r, files, state)
|
||||||
|
}
|
||||||
@@ -240,7 +240,14 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
|
|||||||
Icon: "hero:outline/document-text",
|
Icon: "hero:outline/document-text",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if modules["conseillers"] != nil && modules["conseillers"].(bool) {
|
||||||
|
ls.MenuItems = append(ls.MenuItems, MenuItem{
|
||||||
|
Title: "Conseillers",
|
||||||
|
Link: "/app/conseillers/",
|
||||||
|
Active: menuState == membersMenu,
|
||||||
|
Icon: "hero:outline/user-group",
|
||||||
|
})
|
||||||
|
}
|
||||||
return RenderState{
|
return RenderState{
|
||||||
IconSet: icons.NewIconSet(iconset),
|
IconSet: icons.NewIconSet(iconset),
|
||||||
Group: group,
|
Group: group,
|
||||||
|
|||||||
@@ -67,12 +67,26 @@ 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 []storage.Booking) {
|
func (renderer *Renderer) VehicleBookingsList(w http.ResponseWriter, r *http.Request, bookings []storage.Booking, vehiclesMap any, groupsMap any) {
|
||||||
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{
|
||||||
"bookings": bookings,
|
"bookings": bookings,
|
||||||
|
"vehicles_map": vehiclesMap,
|
||||||
|
"groups_map": groupsMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.Render("vehicles search", w, r, files, state)
|
renderer.Render("vehicles search", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func (renderer *Renderer) VehicleUnbookingsList(w http.ResponseWriter, r *http.Request, bookings []storage.Booking, vehiclesMap any, groupsMap any) {
|
||||||
|
// files := renderer.ThemeConfig.GetStringSlice("views.vehicles.bookings_list.files")
|
||||||
|
// state := NewState(r, renderer.ThemeConfig, vehiclesMenu)
|
||||||
|
// state.ViewState = map[string]any{
|
||||||
|
// "bookings": bookings,
|
||||||
|
// "vehicles_map": vehiclesMap,
|
||||||
|
// "groups_map": groupsMap,
|
||||||
|
// }
|
||||||
|
|
||||||
|
// renderer.Render("vehicles search", w, r, files, state)
|
||||||
|
// }
|
||||||
|
|||||||
@@ -52,3 +52,17 @@ func (s *ServicesHandler) GetBookings() (bookings []storage.Booking, err error)
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServicesHandler) GetVehiclesMap() (vehicles map[string]storage.Vehicle, err error) {
|
||||||
|
vehicles = map[string]storage.Vehicle{}
|
||||||
|
|
||||||
|
request := &fleets.GetVehiclesRequest{}
|
||||||
|
resp, err := s.GRPC.Fleets.GetVehicles(context.TODO(), request)
|
||||||
|
if err == nil {
|
||||||
|
for _, vehicle := range resp.Vehicles {
|
||||||
|
vehicles[vehicle.Id] = vehicle.ToStorageType()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
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"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,3 +24,19 @@ func NewGroupsManagementService(groupsManagementDial string) (*GroupsManagementS
|
|||||||
GroupsManagementClient: client,
|
GroupsManagementClient: client,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServicesHandler) GetGroupsMap() (groups map[string]storage.Group, err error) {
|
||||||
|
groups = map[string]storage.Group{}
|
||||||
|
|
||||||
|
request := &groupsmanagement.GetGroupsRequest{
|
||||||
|
Namespaces: []string{"parcoursmob_organizations"},
|
||||||
|
}
|
||||||
|
resp, err := s.GRPC.GroupsManagement.GetGroups(context.TODO(), request)
|
||||||
|
if err == nil {
|
||||||
|
for _, group := range resp.Groups {
|
||||||
|
groups[group.Id] = group.ToStorageType()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user