From 556f8a24c03aee1cca1957a02886913556e4cb45 Mon Sep 17 00:00:00 2001 From: soukainna Date: Tue, 8 Nov 2022 12:24:06 +0100 Subject: [PATCH 1/5] ajouter le module groupe --- handlers/application/group_module.go | 211 +++++++++++++++ main.go | 11 + renderer/group_module.go | 79 ++++++ renderer/renderer.go | 10 + themes/default/config.yaml | 13 + .../layouts/group_module/create_group.html | 67 +++++ .../layouts/group_module/display_group.html | 249 ++++++++++++++++++ .../web/layouts/group_module/home.html | 60 +++++ 8 files changed, 700 insertions(+) create mode 100644 handlers/application/group_module.go create mode 100644 renderer/group_module.go create mode 100644 themes/default/web/layouts/group_module/create_group.html create mode 100644 themes/default/web/layouts/group_module/display_group.html create mode 100644 themes/default/web/layouts/group_module/home.html diff --git a/handlers/application/group_module.go b/handlers/application/group_module.go new file mode 100644 index 0000000..1e95c4c --- /dev/null +++ b/handlers/application/group_module.go @@ -0,0 +1,211 @@ +package application + +import ( + "context" + "fmt" + "net/http" + "sort" + "strings" + "time" + + 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" + "google.golang.org/protobuf/types/known/structpb" +) + +type BeneficiariesGroupForm struct { + FirstName string `json:"first_name" validate:"required"` + LastName string `json:"last_name" validate:"required"` + Email string `json:"email" validate:"required,email"` + Birthdate *time.Time `json:"birthdate"` + PhoneNumber string `json:"phone_number" validate:"required,phoneNumber"` + Address any `json:"address,omitempty"` + Gender string `json:"gender"` +} + +type GroupsModuleByName []groupstorage.Group + +func (a GroupsModuleByName) Len() int { return len(a) } +func (a GroupsModuleByName) Less(i, j int) bool { + return strings.Compare(a[i].Data["name"].(string), a[j].Data["name"].(string)) < 0 +} +func (a GroupsModuleByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + +func (h *ApplicationHandler) Groups(w http.ResponseWriter, r *http.Request) { + + request := &groupsmanagement.GetGroupsRequest{ + Namespaces: []string{"parcoursmob_groups"}, + } + + 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) + } + + sort.Sort(GroupsModuleByName(groups)) + + h.Renderer.Groups(w, r, groups) +} + +func (h *ApplicationHandler) CreateGroupModule(w http.ResponseWriter, r *http.Request) { + if r.Method == "POST" { + r.ParseForm() + + if r.FormValue("name") == "" { + + fmt.Println("invalid name") + w.WriteHeader(http.StatusBadRequest) + return + } + + groupid := uuid.NewString() + + dataMap := map[string]any{ + "name": r.FormValue("name"), + } + + data, err := structpb.NewValue(dataMap) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } + + request_organization := &groupsmanagement.AddGroupRequest{ + Group: &groupsmanagement.Group{ + Id: groupid, + Namespace: "parcoursmob_groups", + Data: data.GetStructValue(), + }, + } + + _, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_organization) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } + + http.Redirect(w, r, fmt.Sprintf("/app/group_module/groups/%s", groupid), http.StatusFound) + return + } + h.Renderer.CreateGroupModule(w, r) +} + +func filterAcccount(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) DisplayGroupModule(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 + } + fmt.Println(resp.Group.Members) + + 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 filterAcccount(r, account) { + a := account.ToStorageType() + accounts = append(accounts, a) + } + } + fmt.Println(accounts) + + 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 + } + + fmt.Println("yeesssssssssssssssssssssssss") + fmt.Println(respbeneficiary.Account.Id) + fmt.Println("===================yeesssssssssssssssssssssssss") + fmt.Println(r.FormValue("beneficiaryid")) + fmt.Println("=====================yeesssssssssssssssssssssssss") + // } + http.Redirect(w, r, fmt.Sprintf("/app/group_module/groups/%s", resp.Group.ToStorageType().ID), http.StatusFound) + return + } + + accountsB, 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.DisplayGroupModule(w, r, resp.Group.ToStorageType().ID, accounts, cacheid, searched, beneficiary, resp.Group.ToStorageType(), accountsB) +} diff --git a/main.go b/main.go index 3f57525..03199c4 100644 --- a/main.go +++ b/main.go @@ -98,6 +98,17 @@ func main() { /********************Code Supprt Emailing************************/ application.HandleFunc("/support/", applicationHandler.SupportSend) + // application.HandleFunc("/group_module/", applicationHandler.GroupModule) + // application.HandleFunc("/group_module/create", applicationHandler.GroupModuleCreate) + /*********************** CODE GROUP **************************/ + appGroup := application.PathPrefix("/group_module").Subrouter() + appGroup.HandleFunc("/", applicationHandler.Groups) + appGroup.HandleFunc("/groups", applicationHandler.CreateGroupModule) + //appGroup.HandleFunc("/createBeneficaire", applicationHandler.CreateGroupBeneficaire) + //appGroup.HandleFunc("/groups/{groupid}/createBeneficaire", applicationHandler.BeneficaireSearch) + //appGroup.HandleFunc("/groups/{groupid}/{beneficiaryid}", applicationHandler.DisplayGroupBeneficaire) + appGroup.HandleFunc("/groups/{groupid}", applicationHandler.DisplayGroupModule) + //appGroup.HandleFunc("/groups/{groupid}/invite-admin", applicationHandler.AdministrationGroupInviteAdmin) /****************************************************************/ //TODO Subrouters with middlewares checking security for each module ? diff --git a/renderer/group_module.go b/renderer/group_module.go new file mode 100644 index 0000000..fb822de --- /dev/null +++ b/renderer/group_module.go @@ -0,0 +1,79 @@ +package renderer + +import ( + "encoding/json" + "fmt" + "html/template" + "net/http" +) + +const groupMenu = "group_module" + +type BeneficiariesList struct { + Group string `json:"group"` + Count int `json:"count"` + CacheId string `json:"cache_id"` + Beneficiaries []any `json:"beneficiaries"` +} + +func (s BeneficiariesList) JSON() template.JS { + result, _ := json.Marshal(s) + return template.JS(result) +} + +func (s BeneficiariesList) JSONWithLimits(a int, b int) template.JS { + if b < len(s.Beneficiaries) { + s.Beneficiaries = s.Beneficiaries[a:b] + } + return s.JSON() +} + +func (renderer *Renderer) Groups(w http.ResponseWriter, r *http.Request, groups any) { + files := renderer.ThemeConfig.GetStringSlice("views.group_module.home.files") + state := NewState(r, renderer.ThemeConfig, groupMenu) + state.ViewState = map[string]any{ + "groups": groups, + } + + renderer.Render("group_module", w, r, files, state) +} + +func (renderer *Renderer) CreateGroupModule(w http.ResponseWriter, r *http.Request) { + files := renderer.ThemeConfig.GetStringSlice("views.group_module.create_group.files") + state := NewState(r, renderer.ThemeConfig, groupMenu) + + renderer.Render("group_module", w, r, files, state) +} + +func (renderer *Renderer) DisplayGroupModule(w http.ResponseWriter, r *http.Request, groupid string, accounts []any, cacheid string, searched bool, beneficiary any, group any, beneficiaries []any) { + files := renderer.ThemeConfig.GetStringSlice("views.group_module.display_group.files") + state := NewState(r, renderer.ThemeConfig, groupMenu) + + viewstate := map[string]any{ + "beneficiaries": beneficiaries, + "searched": searched, + "group": group, + "list": BeneficiariesList{ + Group: groupid, + Count: len(accounts), + CacheId: cacheid, + Beneficiaries: accounts, + }, + } + + if searched { + viewstate["search"] = map[string]any{ + "beneficiary": beneficiary, + } + + } + + fmt.Println(beneficiary) + + state.ViewState = viewstate + fmt.Println("èèèèèèèèèèèèèèèèèèèèèèèèèè") + fmt.Println(state.ViewState) + fmt.Println(group) + + renderer.Render("beneficiaries_list", w, r, files, state) +} diff --git a/renderer/renderer.go b/renderer/renderer.go index f0d44b1..1a681b2 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -196,6 +196,16 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende Icon: "hero:outline/support", }) + } + /******************************************************************/ + if modules["group_module"] != nil && modules["group_module"].(bool) { + ls.MenuItems = append(ls.MenuItems, MenuItem{ + Title: "Groupes / Communautés", + Link: "/app/group_module/", + Active: menuState == groupMenu, + Icon: "hero:outline/group_module", + }) + } /*************************** my code ******************************/ diff --git a/themes/default/config.yaml b/themes/default/config.yaml index a35f3be..dc61b64 100644 --- a/themes/default/config.yaml +++ b/themes/default/config.yaml @@ -97,6 +97,18 @@ views: search: files: - web/layouts/support/support.html + group_module: + home: + files: + - web/layouts/group_module/home.html + create_group: + files: + - web/layouts/group_module/create_group.html + + display_group: + files: + - web/layouts/group_module/display_group.html + administration: home: files: @@ -128,6 +140,7 @@ icons: coopgo:parcoursmob/monogram: hero:outline/briefcase: hero:outline/support: + hero:outline/group_module: hero:outline/calendar: hero:outline/chevron-right: hero:outline/cog: diff --git a/themes/default/web/layouts/group_module/create_group.html b/themes/default/web/layouts/group_module/create_group.html new file mode 100644 index 0000000..7ab861a --- /dev/null +++ b/themes/default/web/layouts/group_module/create_group.html @@ -0,0 +1,67 @@ +{{define "content"}} + + +
+

Groups > Créer un group

+
+ +
+
+
+
+
+

Nouveau groupe

+

Informations de base sur le groupe à créer

+
+
+
+
+ + +
+
+
+
+
+
+ + + + +
+
+
+{{end}} \ No newline at end of file diff --git a/themes/default/web/layouts/group_module/display_group.html b/themes/default/web/layouts/group_module/display_group.html new file mode 100644 index 0000000..d421547 --- /dev/null +++ b/themes/default/web/layouts/group_module/display_group.html @@ -0,0 +1,249 @@ +{{define "content"}} +
+

Gestion du groupe

+ +
+
+

+
+
+ +
+
+
+

Info du groupe

+
+
+
+
+
+
Nom
+
+ {{.ViewState.group.Data.name}}
+
+
+
+
+
+
+
+ + + + + +
+
+
+
+
+ + + + + + + + + + + + + +
+ Nom du bénéficiaire + + Téléphone + + Email +
+
+ + +
+
+
+
+
+
+ +
+
+
+
+

Ajouter un bénéficiaire

+
+
+
+ + +
+ + + + +
    + + + + +
+
+
+ + + +
+
+
+ +
+
+
+ +{{end}} \ No newline at end of file diff --git a/themes/default/web/layouts/group_module/home.html b/themes/default/web/layouts/group_module/home.html new file mode 100644 index 0000000..6d29350 --- /dev/null +++ b/themes/default/web/layouts/group_module/home.html @@ -0,0 +1,60 @@ + + {{define "content"}} +
+

Gestion des groupes

+ + + + +
+{{end}} \ No newline at end of file From 6364056ae1be8d5f2994c8f440bc9ce902f07014 Mon Sep 17 00:00:00 2001 From: soukainna Date: Tue, 8 Nov 2022 16:49:42 +0100 Subject: [PATCH 2/5] add types of group --- handlers/application/group_module.go | 10 ++++++++- renderer/group_module.go | 6 ++++-- .../layouts/group_module/create_group.html | 21 ++++++++++++++++++- .../layouts/group_module/display_group.html | 5 +++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/handlers/application/group_module.go b/handlers/application/group_module.go index 1e95c4c..61b8665 100644 --- a/handlers/application/group_module.go +++ b/handlers/application/group_module.go @@ -69,11 +69,18 @@ func (h *ApplicationHandler) CreateGroupModule(w http.ResponseWriter, r *http.Re w.WriteHeader(http.StatusBadRequest) return } + if r.FormValue("type") == "" { + + fmt.Println("invalid type") + w.WriteHeader(http.StatusBadRequest) + return + } groupid := uuid.NewString() dataMap := map[string]any{ "name": r.FormValue("name"), + "type": r.FormValue("type"), } data, err := structpb.NewValue(dataMap) @@ -101,7 +108,8 @@ func (h *ApplicationHandler) CreateGroupModule(w http.ResponseWriter, r *http.Re http.Redirect(w, r, fmt.Sprintf("/app/group_module/groups/%s", groupid), http.StatusFound) return } - h.Renderer.CreateGroupModule(w, r) + group_types := h.config.GetStringSlice("modules.groups.group_types") + h.Renderer.CreateGroupModule(w, r, group_types) } func filterAcccount(r *http.Request, a *mobilityaccounts.Account) bool { diff --git a/renderer/group_module.go b/renderer/group_module.go index fb822de..40dff27 100644 --- a/renderer/group_module.go +++ b/renderer/group_module.go @@ -38,10 +38,12 @@ func (renderer *Renderer) Groups(w http.ResponseWriter, r *http.Request, groups renderer.Render("group_module", w, r, files, state) } -func (renderer *Renderer) CreateGroupModule(w http.ResponseWriter, r *http.Request) { +func (renderer *Renderer) CreateGroupModule(w http.ResponseWriter, r *http.Request, group_types []string) { files := renderer.ThemeConfig.GetStringSlice("views.group_module.create_group.files") state := NewState(r, renderer.ThemeConfig, groupMenu) - + state.ViewState = map[string]any{ + "group_types": group_types, + } renderer.Render("group_module", w, r, files, state) } diff --git a/themes/default/web/layouts/group_module/create_group.html b/themes/default/web/layouts/group_module/create_group.html index 7ab861a..4936a2a 100644 --- a/themes/default/web/layouts/group_module/create_group.html +++ b/themes/default/web/layouts/group_module/create_group.html @@ -8,14 +8,17 @@
@@ -43,16 +47,30 @@
-
+
+
+ + +
+
+
+ {{end}} \ No newline at end of file diff --git a/themes/default/web/layouts/group_module/display_group.html b/themes/default/web/layouts/group_module/display_group.html index d421547..462f844 100644 --- a/themes/default/web/layouts/group_module/display_group.html +++ b/themes/default/web/layouts/group_module/display_group.html @@ -21,6 +21,11 @@
{{.ViewState.group.Data.name}}
+
+
Type
+
+ {{.ViewState.group.Data.type}}
+
From 6accf3e4b9426240bd9638b7fc5896776c4a1706 Mon Sep 17 00:00:00 2001 From: soukainna Date: Tue, 8 Nov 2022 17:28:01 +0100 Subject: [PATCH 3/5] change variable in group_module --- handlers/application/group_module.go | 4 +- renderer/group_module.go | 4 +- themes/default/config.yaml | 191 ------------- .../layouts/group_module/create_group.html | 86 ------ .../layouts/group_module/display_group.html | 254 ------------------ .../web/layouts/group_module/home.html | 60 ----- 6 files changed, 5 insertions(+), 594 deletions(-) delete mode 100644 themes/default/config.yaml delete mode 100644 themes/default/web/layouts/group_module/create_group.html delete mode 100644 themes/default/web/layouts/group_module/display_group.html delete mode 100644 themes/default/web/layouts/group_module/home.html diff --git a/handlers/application/group_module.go b/handlers/application/group_module.go index 61b8665..b8832f5 100644 --- a/handlers/application/group_module.go +++ b/handlers/application/group_module.go @@ -208,12 +208,12 @@ func (h *ApplicationHandler) DisplayGroupModule(w http.ResponseWriter, r *http.R return } - accountsB, err := h.beneficiaries(r) + 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.DisplayGroupModule(w, r, resp.Group.ToStorageType().ID, accounts, cacheid, searched, beneficiary, resp.Group.ToStorageType(), accountsB) + h.Renderer.DisplayGroupModule(w, r, resp.Group.ToStorageType().ID, accounts, cacheid, searched, beneficiary, resp.Group.ToStorageType(), accountsBeneficaire) } diff --git a/renderer/group_module.go b/renderer/group_module.go index 40dff27..24e7ec1 100644 --- a/renderer/group_module.go +++ b/renderer/group_module.go @@ -5,6 +5,8 @@ import ( "fmt" "html/template" "net/http" + + mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" ) const groupMenu = "group_module" @@ -47,7 +49,7 @@ func (renderer *Renderer) CreateGroupModule(w http.ResponseWriter, r *http.Reque renderer.Render("group_module", w, r, files, state) } -func (renderer *Renderer) DisplayGroupModule(w http.ResponseWriter, r *http.Request, groupid string, accounts []any, cacheid string, searched bool, beneficiary any, group any, beneficiaries []any) { +func (renderer *Renderer) DisplayGroupModule(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.group_module.display_group.files") state := NewState(r, renderer.ThemeConfig, groupMenu) diff --git a/themes/default/config.yaml b/themes/default/config.yaml deleted file mode 100644 index dc61b64..0000000 --- a/themes/default/config.yaml +++ /dev/null @@ -1,191 +0,0 @@ -name: PARCOURSMOB - -views: - generic: - files: - - web/layouts/layout.html - - web/layouts/_partials/mainmenu.html - dashboard: - files: - - web/layouts/dashboard/_partials/agenda-widget.html - - web/layouts/dashboard/_partials/beneficiaries-widget.html - - web/layouts/dashboard/dashboard.html - beneficiaries: - list: - files: - - web/layouts/beneficiaries/list.html - create: - files: - - web/layouts/_partials/address_autocomplete.html - - web/layouts/beneficiaries/create.html - display: - files: - - web/layouts/_partials/address_autocomplete.html - - web/layouts/vehicles_management/_partials/vehicle-type-select.html - - web/layouts/beneficiaries/_partials/beneficiary-vehicles.html - - web/layouts/beneficiaries/_partials/beneficiary-notes.html - - web/layouts/beneficiaries/_partials/beneficiary-journeys.html - - web/layouts/beneficiaries/_partials/beneficiary-events.html - - web/layouts/beneficiaries/_partials/beneficiary-files.html - - web/layouts/beneficiaries/display.html - update: - files: - - web/layouts/_partials/address_autocomplete.html - - web/layouts/beneficiaries/update.html - - vehicles: - search: - files: - - web/layouts/_partials/address_autocomplete.html - - web/layouts/vehicles_management/_partials/vehicle-type-select.html - - web/layouts/vehicles/search.html - booking_display: - files: - - web/layouts/vehicles/booking-display.html - bookings_list: - files: - - web/layouts/vehicles_management/_partials/bookings-list.html - - web/layouts/vehicles/bookings-list.html - vehicles_management: - overview: - files: - - web/layouts/vehicles_management/_partials/bookings-list.html - - web/layouts/vehicles_management/_partials/vehicles-list.html - - web/layouts/vehicles_management/overview.html - fleet_add: - files: - - web/layouts/_partials/address_autocomplete.html - - web/layouts/vehicles_management/_partials/vehicle-type-select.html - - web/layouts/vehicles_management/fleet-add.html - fleet_display: - files: - - web/layouts/vehicles_management/_partials/calendar.html - - web/layouts/vehicles_management/fleet-display.html - fleet_update: - files: - - web/layouts/_partials/address_autocomplete.html - - web/layouts/vehicles_management/_partials/vehicle-type-select.html - - web/layouts/vehicles_management/fleet-update.html - booking_display: - files: - - web/layouts/vehicles_management/booking-display.html - agenda: - list: - files: - - web/layouts/agenda/home.html - display_event: - files: - - web/layouts/agenda/display-event.html - create_event: - files: - - web/layouts/_partials/address_autocomplete.html - - web/layouts/agenda/create-event.html - directory: - home: - files: - - web/layouts/directory/home.html - journeys: - search: - files: - - web/layouts/_partials/address_autocomplete.html - - web/layouts/journeys/_partials/journeys-all.html - - web/layouts/journeys/_partials/journeys-others.html - - web/layouts/journeys/_partials/journeys-carpool.html - - web/layouts/journeys/_partials/journeys-public-transit.html - - web/layouts/journeys/search.html - support: - search: - files: - - web/layouts/support/support.html - group_module: - home: - files: - - web/layouts/group_module/home.html - create_group: - files: - - web/layouts/group_module/create_group.html - - display_group: - files: - - web/layouts/group_module/display_group.html - - administration: - home: - files: - - web/layouts/administration/home.html - create_group: - files: - - web/layouts/administration/create_group.html - display_group: - files: - - web/layouts/administration/_partials/groups_admins.html - - web/layouts/administration/_partials/group_members.html - - web/layouts/administration/display_group.html - group: - settings: - files: - - web/layouts/administration/_partials/groups_admins.html - - web/layouts/administration/_partials/group_members.html - - web/layouts/group/settings.html - auth: - groups: - files: - - web/layouts/auth/groups.html - onboarding: - files: - - web/layouts/auth/onboarding.html - -icons: - svg: - coopgo:parcoursmob/monogram: - hero:outline/briefcase: - hero:outline/support: - hero:outline/group_module: - hero:outline/calendar: - hero:outline/chevron-right: - hero:outline/cog: - hero:outline/document-text: - hero:outline/home: - hero:outline/map: - hero:outline/office-building: - hero:outline/plus-circle: - hero:outline/shield-check: - hero:outline/user-group: - hero:outline/x: - hero:solid/chevron-right: - hero:solid/question-mark-icon: - hero:solid/search: - hero:solid/selector: - img:profile-picture-placeholder: - tabler-icons:car: - tabler-icons:walk: - tabler-icons:bus: - -emails: - onboarding: - new_administrator: - subject: PARCOURSMOB - Vous avez été invité comme administrateur - files: - - emails/layout.html - - emails/onboarding/new-administrator.html - existing_administrator: - subject: PARCOURSMOB - Vous avez été invité comme administrateur - files: - - emails/layout.html - - emails/onboarding/existing-administrator.html - new_member: - subject: PARCOURSMOB - Vous avez été invité à rejoindre une organisation - files: - - emails/layout.html - - emails/onboarding/new-member.html - existing_member: - subject: PARCOURSMOB - Vous avez été invité à rejoindre une organisation - files: - - emails/layout.html - - emails/onboarding/existing-member.html - support_email: - subject: PARCOURMOB - Vous avez reçu un commentaire - files: - - emails/layout.html - - emails/onboarding/support_emailing.html - \ No newline at end of file diff --git a/themes/default/web/layouts/group_module/create_group.html b/themes/default/web/layouts/group_module/create_group.html deleted file mode 100644 index 4936a2a..0000000 --- a/themes/default/web/layouts/group_module/create_group.html +++ /dev/null @@ -1,86 +0,0 @@ -{{define "content"}} - - -
-

Groups > Créer un group

-
- -
-{{end}} \ No newline at end of file diff --git a/themes/default/web/layouts/group_module/display_group.html b/themes/default/web/layouts/group_module/display_group.html deleted file mode 100644 index 462f844..0000000 --- a/themes/default/web/layouts/group_module/display_group.html +++ /dev/null @@ -1,254 +0,0 @@ -{{define "content"}} -
-

Gestion du groupe

- -
-
-

-
-
- -
-
-
-

Info du groupe

-
-
-
-
-
-
Nom
-
- {{.ViewState.group.Data.name}}
-
-
-
Type
-
- {{.ViewState.group.Data.type}}
-
-
-
-
-
-
-
- - - - - -
-
-
-
-
- - - - - - - - - - - - - -
- Nom du bénéficiaire - - Téléphone - - Email -
-
- - -
-
-
-
-
-
- -
-
-
-
-

Ajouter un bénéficiaire

-
-
-
- - -
- - - - -
    - - - - -
-
-
- - - -
-
-
- -
-
-
- -{{end}} \ No newline at end of file diff --git a/themes/default/web/layouts/group_module/home.html b/themes/default/web/layouts/group_module/home.html deleted file mode 100644 index 6d29350..0000000 --- a/themes/default/web/layouts/group_module/home.html +++ /dev/null @@ -1,60 +0,0 @@ - - {{define "content"}} - -{{end}} \ No newline at end of file From 941a7ccc5e83aeba900297548c90e10b9315db32 Mon Sep 17 00:00:00 2001 From: soukainna Date: Tue, 8 Nov 2022 17:56:12 +0100 Subject: [PATCH 4/5] remove all printlln --- handlers/application/group_module.go | 8 -------- main.go | 6 ------ renderer/group_module.go | 6 ------ 3 files changed, 20 deletions(-) diff --git a/handlers/application/group_module.go b/handlers/application/group_module.go index b8832f5..6fb6e93 100644 --- a/handlers/application/group_module.go +++ b/handlers/application/group_module.go @@ -138,7 +138,6 @@ func (h *ApplicationHandler) DisplayGroupModule(w http.ResponseWriter, r *http.R w.WriteHeader(http.StatusInternalServerError) return } - fmt.Println(resp.Group.Members) var accounts = []any{} @@ -157,7 +156,6 @@ func (h *ApplicationHandler) DisplayGroupModule(w http.ResponseWriter, r *http.R accounts = append(accounts, a) } } - fmt.Println(accounts) cacheid := uuid.NewString() h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour) @@ -198,12 +196,6 @@ func (h *ApplicationHandler) DisplayGroupModule(w http.ResponseWriter, r *http.R return } - fmt.Println("yeesssssssssssssssssssssssss") - fmt.Println(respbeneficiary.Account.Id) - fmt.Println("===================yeesssssssssssssssssssssssss") - fmt.Println(r.FormValue("beneficiaryid")) - fmt.Println("=====================yeesssssssssssssssssssssssss") - // } http.Redirect(w, r, fmt.Sprintf("/app/group_module/groups/%s", resp.Group.ToStorageType().ID), http.StatusFound) return } diff --git a/main.go b/main.go index d110e73..8fe2c90 100644 --- a/main.go +++ b/main.go @@ -109,17 +109,11 @@ func main() { /********************Code Supprt Emailing************************/ application.HandleFunc("/support/", applicationHandler.SupportSend) - // application.HandleFunc("/group_module/", applicationHandler.GroupModule) - // application.HandleFunc("/group_module/create", applicationHandler.GroupModuleCreate) /*********************** CODE GROUP **************************/ appGroup := application.PathPrefix("/group_module").Subrouter() appGroup.HandleFunc("/", applicationHandler.Groups) appGroup.HandleFunc("/groups", applicationHandler.CreateGroupModule) - //appGroup.HandleFunc("/createBeneficaire", applicationHandler.CreateGroupBeneficaire) - //appGroup.HandleFunc("/groups/{groupid}/createBeneficaire", applicationHandler.BeneficaireSearch) - //appGroup.HandleFunc("/groups/{groupid}/{beneficiaryid}", applicationHandler.DisplayGroupBeneficaire) appGroup.HandleFunc("/groups/{groupid}", applicationHandler.DisplayGroupModule) - //appGroup.HandleFunc("/groups/{groupid}/invite-admin", applicationHandler.AdministrationGroupInviteAdmin) /****************************************************************/ //TODO Subrouters with middlewares checking security for each module ? diff --git a/renderer/group_module.go b/renderer/group_module.go index 24e7ec1..ba3fd03 100644 --- a/renderer/group_module.go +++ b/renderer/group_module.go @@ -2,7 +2,6 @@ package renderer import ( "encoding/json" - "fmt" "html/template" "net/http" @@ -72,12 +71,7 @@ func (renderer *Renderer) DisplayGroupModule(w http.ResponseWriter, r *http.Requ } - fmt.Println(beneficiary) - state.ViewState = viewstate - fmt.Println("èèèèèèèèèèèèèèèèèèèèèèèèèè") - fmt.Println(state.ViewState) - fmt.Println(group) renderer.Render("beneficiaries_list", w, r, files, state) } From 814a20c7e2d7bca0493aeeb5f5a6df3cdf5e24ce Mon Sep 17 00:00:00 2001 From: soukainna Date: Thu, 10 Nov 2022 17:24:36 +0100 Subject: [PATCH 5/5] add the logic to store adresse --- handlers/application/group_module.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/handlers/application/group_module.go b/handlers/application/group_module.go index 6fb6e93..e6da0aa 100644 --- a/handlers/application/group_module.go +++ b/handlers/application/group_module.go @@ -2,6 +2,7 @@ package application import ( "context" + "encoding/json" "fmt" "net/http" "sort" @@ -16,6 +17,8 @@ import ( "google.golang.org/protobuf/types/known/structpb" ) +var Addres any + type BeneficiariesGroupForm struct { FirstName string `json:"first_name" validate:"required"` LastName string `json:"last_name" validate:"required"` @@ -61,6 +64,12 @@ func (h *ApplicationHandler) Groups(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) CreateGroupModule(w http.ResponseWriter, r *http.Request) { if r.Method == "POST" { + if r.PostFormValue("address") != "" { + var a any + json.Unmarshal([]byte(r.PostFormValue("address")), &a) + + Addres = a + } r.ParseForm() if r.FormValue("name") == "" { @@ -79,8 +88,10 @@ func (h *ApplicationHandler) CreateGroupModule(w http.ResponseWriter, r *http.Re groupid := uuid.NewString() dataMap := map[string]any{ - "name": r.FormValue("name"), - "type": r.FormValue("type"), + "name": r.FormValue("name"), + "type": r.FormValue("type"), + "description": r.FormValue("description"), + "address": Addres, } data, err := structpb.NewValue(dataMap) @@ -149,7 +160,6 @@ func (h *ApplicationHandler) DisplayGroupModule(w http.ResponseWriter, r *http.R // if err != nil { // return err // } - for _, account := range ressp.Accounts { if filterAcccount(r, account) { a := account.ToStorageType()