From 97ebcf480e3e717fd377aa11a1306cb3969e1d94 Mon Sep 17 00:00:00 2001 From: soukainna Date: Wed, 22 Feb 2023 11:00:44 +0100 Subject: [PATCH 01/19] add page members --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index 154930a..5d7ba4c 100644 --- a/main.go +++ b/main.go @@ -87,6 +87,7 @@ func main() { 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("/vehicles/", applicationHandler.VehiclesSearch) application.HandleFunc("/vehicles/bookings/", applicationHandler.VehiclesBookingsList) From 9965271788d353576392c5fac2af84d50507e594 Mon Sep 17 00:00:00 2001 From: soukainna Date: Wed, 22 Feb 2023 11:01:29 +0100 Subject: [PATCH 02/19] add event list in statistique page --- handlers/application/administration.go | 40 ++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/handlers/application/administration.go b/handlers/application/administration.go index 7c38415..052d8cb 100644 --- a/handlers/application/administration.go +++ b/handlers/application/administration.go @@ -11,6 +11,8 @@ import ( "time" "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" "git.coopgo.io/coopgo-platform/fleets/storage" groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi" @@ -20,6 +22,7 @@ import ( "github.com/google/uuid" "github.com/gorilla/mux" "google.golang.org/protobuf/types/known/structpb" + "google.golang.org/protobuf/types/known/timestamppb" ) func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) { @@ -64,8 +67,40 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque } sort.Sort(sorting.GroupsByName(groups)) + ////////////////////////////////////add event//////////////////////////////////////////// + rresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{ + Namespaces: []string{"parcoursmob_dispositifs"}, + Mindate: timestamppb.New(time.Now().Add(-24 * time.Hour)), + }) - 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) { @@ -354,7 +389,8 @@ func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Req vehicles, _ := h.services.GetVehiclesMap() groups, _ := h.services.GetGroupsMap() - + // fmt.Println(vehicles) + // fmt.Println("////////////////////////////////////////:") h.Renderer.VehicleBookingsList(w, r, bookings, vehicles, groups) } From e559359ff0b303718f496a3975c6fca9d5e20aa1 Mon Sep 17 00:00:00 2001 From: soukainna Date: Wed, 22 Feb 2023 11:01:50 +0100 Subject: [PATCH 03/19] fix err --- handlers/application/agenda.go | 1 - 1 file changed, 1 deletion(-) diff --git a/handlers/application/agenda.go b/handlers/application/agenda.go index f9395a4..147acc4 100644 --- a/handlers/application/agenda.go +++ b/handlers/application/agenda.go @@ -67,7 +67,6 @@ func (h *ApplicationHandler) AgendaHome(w http.ResponseWriter, r *http.Request) groups[g.Id] = g.ToStorageType() } } - h.Renderer.AgendaHome(w, r, responses, groups) } From fa065f2a436086fb92b4ec04731c847399695fef Mon Sep 17 00:00:00 2001 From: soukainna Date: Wed, 22 Feb 2023 11:02:37 +0100 Subject: [PATCH 04/19] add member page with organisations --- handlers/application/members.go | 89 ++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/handlers/application/members.go b/handlers/application/members.go index 586b4e4..ae4c5c3 100644 --- a/handlers/application/members.go +++ b/handlers/application/members.go @@ -6,9 +6,12 @@ import ( "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" ) @@ -36,8 +39,34 @@ func (h *ApplicationHandler) MemberDisplay(w http.ResponseWriter, r *http.Reques w.WriteHeader(http.StatusInternalServerError) return } + //////////////////////////////////add organisations///////////////////////////////////////////////// - h.Renderer.MemberDisplay(w, r, resp.Account.ToStorageType()) + 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) { @@ -76,7 +105,7 @@ func (h *ApplicationHandler) MemberUpdate(w http.ResponseWriter, r *http.Request return } - http.Redirect(w, r, fmt.Sprintf("/app/profile/%s", resp.Account.Id), http.StatusFound) + http.Redirect(w, r, fmt.Sprintf("/app/members/%s", resp.Account.Id), http.StatusFound) return } @@ -126,3 +155,59 @@ func parseUserForm(r *http.Request) (map[string]any, error) { 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) +} From d1818b6251bc028293e8daeda9056ae0fab5d547 Mon Sep 17 00:00:00 2001 From: soukainna Date: Wed, 22 Feb 2023 11:03:33 +0100 Subject: [PATCH 05/19] add event data --- renderer/administration.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/renderer/administration.go b/renderer/administration.go index 635a811..41aee36 100644 --- a/renderer/administration.go +++ b/renderer/administration.go @@ -3,12 +3,13 @@ package renderer import ( "net/http" + agendastorage "git.coopgo.io/coopgo-platform/agenda/storage" mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" ) 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") state := NewState(r, renderer.ThemeConfig, administrationMenu) state.ViewState = map[string]any{ @@ -16,6 +17,7 @@ func (renderer *Renderer) Administration(w http.ResponseWriter, r *http.Request, "beneficiaries": beneficiaries, "bookings": bookings, "groups": groups, + "events": events, } renderer.Render("administration", w, r, files, state) From f023a7bbffe4dd0f1755738cdb027f8bc3ca2e5f Mon Sep 17 00:00:00 2001 From: soukainna Date: Wed, 22 Feb 2023 11:04:09 +0100 Subject: [PATCH 06/19] add members data --- handlers/application/vehicles-management.go | 40 ++++++++++++++++-- renderer/members.go | 45 ++++++++++++++++++++- renderer/vehicle-management.go | 10 +++++ renderer/vehicles.go | 12 ++++++ 4 files changed, 103 insertions(+), 4 deletions(-) diff --git a/handlers/application/vehicles-management.go b/handlers/application/vehicles-management.go index 0528583..e91bb66 100644 --- a/handlers/application/vehicles-management.go +++ b/handlers/application/vehicles-management.go @@ -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.BookingsByStartdate(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) 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()) } @@ -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) } + +// 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) +// } diff --git a/renderer/members.go b/renderer/members.go index a95bc72..ad96005 100644 --- a/renderer/members.go +++ b/renderer/members.go @@ -1,17 +1,22 @@ 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) { +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) } @@ -22,3 +27,41 @@ func (renderer *Renderer) MemberUpdate(w http.ResponseWriter, r *http.Request, u 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) +} diff --git a/renderer/vehicle-management.go b/renderer/vehicle-management.go index 35558dd..dee0dc6 100644 --- a/renderer/vehicle-management.go +++ b/renderer/vehicle-management.go @@ -78,3 +78,13 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter, renderer.Render("vehicles search", w, r, files, state) } + +// func (renderer *Renderer) UnbookingVehicles(w http.ResponseWriter, r *http.Request, vehicles []fleetsstorage.Vehicle) { +// files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.unbooking_display.files") +// state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) +// state.ViewState = map[string]any{ +// "vehicles": vehicles, +// } + +// renderer.Render("fleet display Unbooking vehicle", w, r, files, state) +// } diff --git a/renderer/vehicles.go b/renderer/vehicles.go index 9f9ad11..09faa62 100644 --- a/renderer/vehicles.go +++ b/renderer/vehicles.go @@ -78,3 +78,15 @@ func (renderer *Renderer) VehicleBookingsList(w http.ResponseWriter, r *http.Req 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) +// } From 167e8cfe2ef240e4b7a64dfa9575b3718b268dae Mon Sep 17 00:00:00 2001 From: soukainna Date: Wed, 22 Feb 2023 12:22:49 +0100 Subject: [PATCH 07/19] fix err --- handlers/application/vehicles-management.go | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/handlers/application/vehicles-management.go b/handlers/application/vehicles-management.go index e91bb66..29201ad 100644 --- a/handlers/application/vehicles-management.go +++ b/handlers/application/vehicles-management.go @@ -52,14 +52,14 @@ 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) + // vehiicles := []fleetsstorage.Vehicle{} + // for i, vehiicle := range resp.Vehicles { + // if len(resp.Vehicles[i].Bookings) == 0 { + // v := vehiicle.ToStorageType() + // vehiicles = append(vehiicles, v) + // } + // } + //fmt.Println(vehiicles) sort.Sort(sorting.VehiclesByLicencePlate(vehicles)) sort.Sort(sorting.BookingsByStartdate(bookings)) h.Renderer.VehiclesManagementOverview(w, r, vehicles, vehicles_map, bookings) @@ -190,10 +190,10 @@ func (h *ApplicationHandler) VehiclesFleetDisplay(w http.ResponseWriter, r *http w.WriteHeader(http.StatusInternalServerError) return } - if len(resp.Vehicle.ToStorageType().Bookings) == 0 { - fmt.Println("lol") - } - fmt.Println(resp.Vehicle.ToStorageType().Bookings) + // if len(resp.Vehicle.ToStorageType().Bookings) == 0 { + // fmt.Println("lol") + // } + // fmt.Println(resp.Vehicle.ToStorageType().Bookings) h.Renderer.VehiclesFleetDisplay(w, r, resp.Vehicle.ToStorageType()) } From 3b9ac6696568113eea41984b60ddfe8a9c650c2c Mon Sep 17 00:00:00 2001 From: soukainna Date: Mon, 27 Feb 2023 15:06:24 +0100 Subject: [PATCH 08/19] add url stats --- main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.go b/main.go index 5d7ba4c..48ab0b4 100644 --- a/main.go +++ b/main.go @@ -137,6 +137,10 @@ func main() { appAdmin.HandleFunc("/groups/{groupid}/invite-admin", applicationHandler.AdministrationGroupInviteAdmin) appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember) appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles) + //add statistiques + appAdmin.HandleFunc("/stats/vehicles/available", applicationHandler.AdminStatAvailableVehicles) + appAdmin.HandleFunc("/stats/beneficaires", applicationHandler.AdminStatBeneficaires) + appAdmin.HandleFunc("/stats/events", applicationHandler.AdminStatEvents) fmt.Println("-> HTTP server listening on", address) From 64521c01c172d387a02f698778536d41e5e22616 Mon Sep 17 00:00:00 2001 From: soukainna Date: Fri, 3 Mar 2023 17:22:12 +0100 Subject: [PATCH 09/19] fix main static --- main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.go b/main.go index 48ab0b4..2c13f8f 100644 --- a/main.go +++ b/main.go @@ -136,9 +136,8 @@ func main() { appAdmin.HandleFunc("/groups/{groupid}", applicationHandler.AdministrationGroupDisplay) appAdmin.HandleFunc("/groups/{groupid}/invite-admin", applicationHandler.AdministrationGroupInviteAdmin) appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember) - appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles) //add statistiques - appAdmin.HandleFunc("/stats/vehicles/available", applicationHandler.AdminStatAvailableVehicles) + appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles) appAdmin.HandleFunc("/stats/beneficaires", applicationHandler.AdminStatBeneficaires) appAdmin.HandleFunc("/stats/events", applicationHandler.AdminStatEvents) From bdcb386dffb13a8af7ca34d238110a948e8b3b8d Mon Sep 17 00:00:00 2001 From: soukainna Date: Fri, 3 Mar 2023 17:22:43 +0100 Subject: [PATCH 10/19] try to fix some err --- handlers/application/beneficiaries.go | 1 - 1 file changed, 1 deletion(-) diff --git a/handlers/application/beneficiaries.go b/handlers/application/beneficiaries.go index 460140c..e99c092 100644 --- a/handlers/application/beneficiaries.go +++ b/handlers/application/beneficiaries.go @@ -54,7 +54,6 @@ func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Re cacheid := uuid.NewString() h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour) - h.Renderer.BeneficiariesList(w, r, accounts, cacheid) } From 795066b6e5f1a865e79484878919df9e73373774 Mon Sep 17 00:00:00 2001 From: soukainna Date: Fri, 3 Mar 2023 17:23:52 +0100 Subject: [PATCH 11/19] add unbooking vehicles --- renderer/vehicle-management.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/renderer/vehicle-management.go b/renderer/vehicle-management.go index dee0dc6..05bacce 100644 --- a/renderer/vehicle-management.go +++ b/renderer/vehicle-management.go @@ -88,3 +88,14 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter, // renderer.Render("fleet display Unbooking vehicle", w, r, files, state) // } + +func (renderer *Renderer) UnbookingVehicles(w http.ResponseWriter, r *http.Request, vehicles []fleetsstorage.Vehicle) { + files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.unbooking_display.files") + state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) + state.ViewState = map[string]any{ + + "vehicles": vehicles, + } + + renderer.Render("fleet display Unbooking vehicle", w, r, files, state) +} From c3e67cb9ddaba3bfca5b31669b8540ee5e24afde Mon Sep 17 00:00:00 2001 From: soukainna Date: Fri, 3 Mar 2023 17:24:35 +0100 Subject: [PATCH 12/19] delete block function --- renderer/vehicle-management.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/renderer/vehicle-management.go b/renderer/vehicle-management.go index 05bacce..3790c56 100644 --- a/renderer/vehicle-management.go +++ b/renderer/vehicle-management.go @@ -79,16 +79,6 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter, renderer.Render("vehicles search", w, r, files, state) } -// func (renderer *Renderer) UnbookingVehicles(w http.ResponseWriter, r *http.Request, vehicles []fleetsstorage.Vehicle) { -// files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.unbooking_display.files") -// state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) -// state.ViewState = map[string]any{ -// "vehicles": vehicles, -// } - -// renderer.Render("fleet display Unbooking vehicle", w, r, files, state) -// } - func (renderer *Renderer) UnbookingVehicles(w http.ResponseWriter, r *http.Request, vehicles []fleetsstorage.Vehicle) { files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.unbooking_display.files") state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) From c9b326c49a65356f69902c2e78d14e413d2b69bc Mon Sep 17 00:00:00 2001 From: soukainna Date: Fri, 3 Mar 2023 17:25:13 +0100 Subject: [PATCH 13/19] fix err --- renderer/vehicle-management.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/renderer/vehicle-management.go b/renderer/vehicle-management.go index 3790c56..35558dd 100644 --- a/renderer/vehicle-management.go +++ b/renderer/vehicle-management.go @@ -78,14 +78,3 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter, renderer.Render("vehicles search", w, r, files, state) } - -func (renderer *Renderer) UnbookingVehicles(w http.ResponseWriter, r *http.Request, vehicles []fleetsstorage.Vehicle) { - files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.unbooking_display.files") - state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) - state.ViewState = map[string]any{ - - "vehicles": vehicles, - } - - renderer.Render("fleet display Unbooking vehicle", w, r, files, state) -} From 1b2902c6320ef7577c562cd49b985e3481a37454 Mon Sep 17 00:00:00 2001 From: soukainna Date: Mon, 6 Mar 2023 10:23:49 +0100 Subject: [PATCH 14/19] add functions to display statistiques --- handlers/application/administration.go | 199 +++++++++++++++++++++++-- 1 file changed, 183 insertions(+), 16 deletions(-) diff --git a/handlers/application/administration.go b/handlers/application/administration.go index 052d8cb..63ca02f 100644 --- a/handlers/application/administration.go +++ b/handlers/application/administration.go @@ -10,19 +10,20 @@ import ( "sort" "time" + "git.coopgo.io/coopgo-apps/parcoursmob/utils/identification" "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" - "git.coopgo.io/coopgo-platform/fleets/storage" + 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" groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage" accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi" mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" "github.com/google/uuid" "github.com/gorilla/mux" "google.golang.org/protobuf/types/known/structpb" - "google.golang.org/protobuf/types/known/timestamppb" ) func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) { @@ -70,7 +71,6 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque ////////////////////////////////////add event//////////////////////////////////////////// rresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{ Namespaces: []string{"parcoursmob_dispositifs"}, - Mindate: timestamppb.New(time.Now().Add(-24 * time.Hour)), }) if err != nil { @@ -368,30 +368,125 @@ func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWrit 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) { - request := &fleets.GetBookingsRequest{} - resp, err := h.services.GRPC.Fleets.GetBookings(context.TODO(), 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{} + bookings := []fleetsstorage.Booking{} + //vehicles_map := map[string]fleetsstorage.Vehicle{} + + // for _, vehicle := range resp.Vehicles { + // if filteVehicle(r, vehicle) { + // v := vehicle.ToStorageType() + // vehicles = append(vehicles, v) + // vehicles_map[v.ID] = v + // for _, b := range v.Bookings { + // if b.Status() != fleetsstorage.StatusOld { + // bookings = append(bookings, b) + // } + // } + + // } + // } + 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.StatusNotFound) - return + w.WriteHeader(http.StatusInternalServerError) } - bookings := []storage.Booking{} + 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) - for _, b := range resp.Bookings { - booking := b.ToStorageType() - bookings = append(bookings, booking) } + groups := map[string]any{} - sort.Sort(sorting.BookingsByStartdate(bookings)) + 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 + } - vehicles, _ := h.services.GetVehiclesMap() - groups, _ := h.services.GetGroupsMap() + for _, g := range admingroups.Groups { + groups[g.Id] = g.ToStorageType() + } + + } + //fmt.Println(groups) + //fmt.Println("****************************************************************") // fmt.Println(vehicles) - // fmt.Println("////////////////////////////////////////:") - h.Renderer.VehicleBookingsList(w, r, bookings, vehicles, groups) + // fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") + // id := "" + // for _, v := range vehicles { + // id = v.ID + // for _, vv := range v.Bookings { + + // i := 1 + // // fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") + // // fmt.Println(vv.Vehicleid) + // // fmt.Println("*********************************************************") + // if id == vv.Vehicleid { + // i++ + // fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") + // fmt.Println(vv.Vehicleid) + // fmt.Println("*********************************************************") + // } + // fmt.Println(i) + + // } + // fmt.Println(v.Status) + // fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") + //} + // fmt.Println(bookings) + 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) { @@ -431,3 +526,75 @@ func (h *ApplicationHandler) groupmembers(groupid string) (groupmembers []mobili return groupmembers, admins, err } + +////////////////////////available //////////////////////////////////// +// func (h ApplicationHandler) AdminStatAvailableVehicles(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{} +// for i, vehiicle := range resp.Vehicles { +// if len(resp.Vehicles[i].Bookings) == 0 { +// v := vehiicle.ToStorageType() +// vehicles = append(vehicles, v) +// } +// } +// fmt.Println(vehicles) +// fmt.Println("////////////////////////////////////////:") +// h.Renderer.UnbookingVehicles(w, r, vehicles) +// } + +//////////////////////////////beneificiare list/////////// +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) + fmt.Println(beneficiaries) + h.Renderer.AdminStatBeneficaires(w, r, beneficiaries, cacheid) +} + +//////////////////////////////event list/////////// +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) +} From a05942b7ed6eed8de94b39674afc554717e8b818 Mon Sep 17 00:00:00 2001 From: soukainna Date: Mon, 6 Mar 2023 10:24:43 +0100 Subject: [PATCH 15/19] add logic to display stats --- renderer/administration.go | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/renderer/administration.go b/renderer/administration.go index 41aee36..45c4618 100644 --- a/renderer/administration.go +++ b/renderer/administration.go @@ -1,9 +1,12 @@ package renderer import ( + "encoding/json" + "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" ) @@ -41,3 +44,60 @@ func (renderer *Renderer) AdministrationGroupDisplay(w http.ResponseWriter, r *h 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() +} + +/////////////////////////////////stats +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) +} From e4418f26e0fa18daf081d70e66ba581c60ebc244 Mon Sep 17 00:00:00 2001 From: soukainna Date: Mon, 6 Mar 2023 10:25:16 +0100 Subject: [PATCH 16/19] fix err --- handlers/application/administration.go | 41 -------------------------- 1 file changed, 41 deletions(-) diff --git a/handlers/application/administration.go b/handlers/application/administration.go index 63ca02f..55d40ca 100644 --- a/handlers/application/administration.go +++ b/handlers/application/administration.go @@ -398,21 +398,6 @@ func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Req //vehicles := []fleetsstorage.Vehicle{} bookings := []fleetsstorage.Booking{} - //vehicles_map := map[string]fleetsstorage.Vehicle{} - - // for _, vehicle := range resp.Vehicles { - // if filteVehicle(r, vehicle) { - // v := vehicle.ToStorageType() - // vehicles = append(vehicles, v) - // vehicles_map[v.ID] = v - // for _, b := range v.Bookings { - // if b.Status() != fleetsstorage.StatusOld { - // bookings = append(bookings, b) - // } - // } - - // } - // } administrators := []string{} reequest := &fleets.GetVehiclesRequest{ Namespaces: []string{"parcoursmob"}, @@ -458,32 +443,6 @@ func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Req } } - //fmt.Println(groups) - //fmt.Println("****************************************************************") - // fmt.Println(vehicles) - // fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") - // id := "" - // for _, v := range vehicles { - // id = v.ID - // for _, vv := range v.Bookings { - - // i := 1 - // // fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") - // // fmt.Println(vv.Vehicleid) - // // fmt.Println("*********************************************************") - // if id == vv.Vehicleid { - // i++ - // fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") - // fmt.Println(vv.Vehicleid) - // fmt.Println("*********************************************************") - // } - // fmt.Println(i) - - // } - // fmt.Println(v.Status) - // fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") - //} - // fmt.Println(bookings) sort.Sort(sorting.VehiclesByLicencePlate(vehicles)) sort.Sort(sorting.BookingsByStartdate(bookings)) h.Renderer.AdminStatVehicles(w, r, vehicles, bookings, groups) From 232764e7d70980e6ea0aa13307fceae706957245 Mon Sep 17 00:00:00 2001 From: soukainna Date: Mon, 6 Mar 2023 10:27:12 +0100 Subject: [PATCH 17/19] delete log --- handlers/application/administration.go | 36 +------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/handlers/application/administration.go b/handlers/application/administration.go index 55d40ca..5d75e21 100644 --- a/handlers/application/administration.go +++ b/handlers/application/administration.go @@ -99,7 +99,7 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque groupps[g.Id] = g.ToStorageType() } } - ///////////////////////////////////////////////////////////////////////////////////////// + h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings, responses) } @@ -387,16 +387,6 @@ func filteVehicle(r *http.Request, v *fleets.Vehicle) bool { func (h ApplicationHandler) AdminStatVehicles(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{} bookings := []fleetsstorage.Booking{} administrators := []string{} reequest := &fleets.GetVehiclesRequest{ @@ -486,29 +476,6 @@ func (h *ApplicationHandler) groupmembers(groupid string) (groupmembers []mobili return groupmembers, admins, err } -////////////////////////available //////////////////////////////////// -// func (h ApplicationHandler) AdminStatAvailableVehicles(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{} -// for i, vehiicle := range resp.Vehicles { -// if len(resp.Vehicles[i].Bookings) == 0 { -// v := vehiicle.ToStorageType() -// vehicles = append(vehicles, v) -// } -// } -// fmt.Println(vehicles) -// fmt.Println("////////////////////////////////////////:") -// h.Renderer.UnbookingVehicles(w, r, vehicles) -// } - //////////////////////////////beneificiare list/////////// func (h ApplicationHandler) AdminStatBeneficaires(w http.ResponseWriter, r *http.Request) { beneficiaries, err := h.services.GetBeneficiaries() @@ -519,7 +486,6 @@ func (h ApplicationHandler) AdminStatBeneficaires(w http.ResponseWriter, r *http } cacheid := uuid.NewString() h.cache.PutWithTTL(cacheid, beneficiaries, 1*time.Hour) - fmt.Println(beneficiaries) h.Renderer.AdminStatBeneficaires(w, r, beneficiaries, cacheid) } From a63a4ad1c29ab5e6422f16701650b61c4159c7ca Mon Sep 17 00:00:00 2001 From: soukainna Date: Mon, 6 Mar 2023 10:31:50 +0100 Subject: [PATCH 18/19] fix err --- renderer/administration.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/renderer/administration.go b/renderer/administration.go index 45c4618..fe89393 100644 --- a/renderer/administration.go +++ b/renderer/administration.go @@ -45,7 +45,6 @@ func (renderer *Renderer) AdministrationGroupDisplay(w http.ResponseWriter, r *h renderer.Render("administration", w, r, files, state) } -///////////////////////////////////////////////////////////////////// type BeneficiariesState struct { Count int `json:"count"` CacheId string `json:"cache_id"` @@ -64,7 +63,6 @@ func (s BeneficiariesState) JSONWithLimits(a int, b int) template.JS { return s.JSON() } -/////////////////////////////////stats func (renderer *Renderer) AdminStatBeneficaires(w http.ResponseWriter, r *http.Request, Beneficiaries []mobilityaccountsstorage.Account, cacheid string) { files := renderer.ThemeConfig.GetStringSlice("views.administration.beneficaires_list.files") From 7847b4c31f1c5e65bd633bec2ca6371cc7d4faeb Mon Sep 17 00:00:00 2001 From: soukainna Date: Mon, 6 Mar 2023 10:32:57 +0100 Subject: [PATCH 19/19] clean code --- handlers/application/administration.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/handlers/application/administration.go b/handlers/application/administration.go index 5d75e21..668f845 100644 --- a/handlers/application/administration.go +++ b/handlers/application/administration.go @@ -476,7 +476,6 @@ func (h *ApplicationHandler) groupmembers(groupid string) (groupmembers []mobili return groupmembers, admins, err } -//////////////////////////////beneificiare list/////////// func (h ApplicationHandler) AdminStatBeneficaires(w http.ResponseWriter, r *http.Request) { beneficiaries, err := h.services.GetBeneficiaries() if err != nil { @@ -489,7 +488,6 @@ func (h ApplicationHandler) AdminStatBeneficaires(w http.ResponseWriter, r *http h.Renderer.AdminStatBeneficaires(w, r, beneficiaries, cacheid) } -//////////////////////////////event list/////////// 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"},