2022-08-11 15:26:55 +00:00
|
|
|
package application
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2022-09-06 13:02:59 +00:00
|
|
|
"sort"
|
2022-08-11 15:26:55 +00:00
|
|
|
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
2022-11-01 10:32:13 +00:00
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
2022-09-06 13:02:59 +00:00
|
|
|
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
|
|
|
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
2022-08-11 15:26:55 +00:00
|
|
|
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
|
|
|
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
2022-12-05 19:06:22 +00:00
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
2022-08-11 15:26:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
g := r.Context().Value(identification.GroupKey)
|
|
|
|
if g == nil {
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
group := g.(storage.Group)
|
|
|
|
|
|
|
|
request := &mobilityaccounts.GetAccountsBatchRequest{
|
|
|
|
Accountids: group.Members,
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), request)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var accounts = []any{}
|
|
|
|
|
|
|
|
// We only display the 10 last here
|
|
|
|
count := len(resp.Accounts)
|
2022-10-17 03:02:19 +00:00
|
|
|
min := count - 5
|
2022-08-11 15:26:55 +00:00
|
|
|
if min < 0 {
|
|
|
|
min = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, account := range resp.Accounts[min:] {
|
|
|
|
if filterAccount(r, account) {
|
|
|
|
a := account.ToStorageType()
|
|
|
|
accounts = append([]any{a}, accounts...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 19:06:22 +00:00
|
|
|
members, _, err := h.groupmembers(group.ID)
|
2022-09-06 13:02:59 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
count_members := len(members)
|
|
|
|
|
|
|
|
events := []agendastorage.Event{}
|
|
|
|
|
|
|
|
eventsresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
|
|
|
Namespaces: []string{"parcoursmob_dispositifs"},
|
2022-12-05 19:06:22 +00:00
|
|
|
Mindate: timestamppb.Now(),
|
2022-09-06 13:02:59 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
for _, e := range eventsresp.Events {
|
|
|
|
events = append(events, e.ToStorageType())
|
|
|
|
}
|
|
|
|
|
2022-11-01 10:32:13 +00:00
|
|
|
sort.Sort(sorting.EventsByStartdate(events))
|
2022-09-06 13:02:59 +00:00
|
|
|
|
|
|
|
h.Renderer.Dashboard(w, r, accounts, count, count_members, events)
|
2022-08-11 15:26:55 +00:00
|
|
|
|
|
|
|
}
|