Compare commits

...

2 Commits

Author SHA1 Message Date
mfrigo 2274f8d6d0 [+] bug fix regarding booking-list 2023-11-24 16:27:34 +01:00
mfrigo 4229c13b6b Implemented functional "Actions réalisées"
- Added events and vehicles inside it
- Included dates, characteristics, and names of events/vehicles
- Introduced color-coded badges to indicate the status of events/vehicles (ongoing or not)
2023-10-23 09:45:57 +02:00
3 changed files with 135 additions and 9 deletions

View File

@ -23,6 +23,7 @@ import (
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"
"git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
@ -43,6 +44,67 @@ type BeneficiariesForm struct {
Gender string `json:"gender"`
}
type Event_Beneficiary interface {
Name() string
Date() time.Time
DateEnd() time.Time
Type() string
Db() string
ID() string
Icons() string
Status() int
}
type Event struct {
IDVal string
NameVal string
DateVal time.Time
DateEndVal time.Time
TypeVal string
DbVal string
Deleted bool
IconSet string
StatusVal int
}
func (e Event) Name() string {
return e.NameVal
}
func (e Event) Date() time.Time {
return e.DateVal
}
func (e Event) DateEnd() time.Time {
return e.DateEndVal
}
func (e Event) Type() string {
return e.TypeVal
}
func (e Event) ID() string {
return e.IDVal
}
func (e Event) Db() string {
return e.DbVal
}
func (e Event) Icons() string {
return e.IconSet
}
func (e Event) Status() int {
return e.StatusVal
}
func sortByDate(events []Event_Beneficiary) {
sort.Slice(events, func(i, j int) bool {
return events[i].Date().After(events[j].Date())
})
}
func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Request) {
accounts, err := h.beneficiaries(r)
@ -149,6 +211,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
}
events := []agendastorage.Event{}
currentTime := time.Now().Truncate(24 * time.Hour)
for _, e := range subcriptionresp.Subscription {
eventresquest := &agenda.GetEventRequest{
@ -160,10 +223,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
w.WriteHeader(http.StatusInternalServerError)
return
}
currentTime := time.Now().Truncate(24 * time.Hour)
if eventresp.Event.Startdate.AsTime().Equal(currentTime) || eventresp.Event.Startdate.AsTime().After(currentTime) {
events = append(events, eventresp.Event.ToStorageType())
}
events = append(events, eventresp.Event.ToStorageType())
}
sort.Sort(sorting.EventsByStartdate(events))
@ -178,12 +238,78 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
return
}
bookings := []any{}
bookings := []fleetsstorage.Booking{}
for _, b := range bookingsresp.Bookings {
bookings = append(bookings, b.ToStorageType())
}
var events_list []Event_Beneficiary
var status_event int
for _, e := range events {
if e.Startdate.After(currentTime) {
status_event = 1
} else if e.Startdate.Before(currentTime) && e.Enddate.After(currentTime) || e.Enddate.Equal(currentTime) {
status_event = 2
} else {
status_event = 3
}
event := Event{
NameVal: e.Name,
DateVal: e.Startdate,
DateEndVal: e.Enddate,
TypeVal: e.Type,
IDVal: e.ID,
DbVal: "/app/agenda/",
IconSet: "calendar",
StatusVal: status_event,
}
events_list = append(events_list, event)
}
var status_booking int
for _, b := range bookings {
if b.Enddate.After(currentTime) || b.Enddate.Equal(currentTime) {
GetVehiculeRequest := &fleets.GetVehicleRequest{
Vehicleid: b.Vehicleid,
}
GetVehiculeResp, err := h.services.GRPC.Fleets.GetVehicle(context.Background(), GetVehiculeRequest)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if b.Startdate.After(currentTime) {
status_booking = 1
} else if b.Startdate.Before(currentTime) && b.Enddate.After(currentTime) || b.Enddate.Equal(currentTime) {
status_booking = 2
} else {
status_booking = 3
}
event := Event{
NameVal: GetVehiculeResp.Vehicle.ToStorageType().Data["name"].(string),
DateVal: b.Startdate,
DateEndVal: b.Enddate,
TypeVal: "Réservation de véhicule",
IDVal: b.ID,
DbVal: "/app/vehicles-management/bookings/",
IconSet: "vehicle",
StatusVal: status_booking,
}
events_list = append(events_list, event)
}
}
sortByDate(events_list)
groupsrequest := &groupsmanagement.GetGroupsRequest{
Namespaces: []string{"parcoursmob_organizations"},
Member: beneficiaryID,
@ -202,7 +328,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
beneficiaries_file_types := h.config.GetStringSlice("modules.beneficiaries.documents_types")
file_types_map := h.config.GetStringMapString("storage.files.file_types")
h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents, events)
h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents, events_list)
}
func (h *ApplicationHandler) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request) {

View File

@ -57,6 +57,7 @@ func (h *ApplicationHandler) VehiclesManagementOverview(w http.ResponseWriter, r
}
}
fmt.Println(vehicles_map)
sort.Sort(sorting.VehiclesByLicencePlate(vehicles))
sort.Sort(sorting.BookingsByStartdate(bookings))

View File

@ -5,7 +5,7 @@ import (
"html/template"
"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"
)
@ -53,7 +53,7 @@ type BeneficiariesDisplayState struct {
Beneficiary 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, event []agendastorage.Event) {
func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, bookings []fleetsstorage.Booking, organizations []any, beneficiaries_file_types []string, file_types_map map[string]string, documents any, event interface{}) {
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files")
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
state.ViewState = map[string]any{
@ -65,7 +65,6 @@ func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Requ
"organizations": organizations,
"event": event,
}
renderer.Render("beneficiaries_display", w, r, files, state)
}