2022-08-11 15:26:55 +00:00
|
|
|
package renderer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
2022-10-30 19:11:36 +00:00
|
|
|
|
2023-10-23 07:45:57 +00:00
|
|
|
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
2022-10-30 19:11:36 +00:00
|
|
|
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
2024-09-26 11:34:08 +00:00
|
|
|
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
2024-09-25 13:16:02 +00:00
|
|
|
|
2022-08-11 15:26:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const beneficiariesMenu = "beneficiaries"
|
|
|
|
|
|
|
|
type BeneficiariesListState struct {
|
2022-10-30 19:11:36 +00:00
|
|
|
Count int `json:"count"`
|
|
|
|
CacheId string `json:"cache_id"`
|
|
|
|
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
2024-09-26 11:34:08 +00:00
|
|
|
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type BeneficiarySolidarityState struct {
|
|
|
|
Count int `json:"count"`
|
|
|
|
CacheId string `json:"cache_id"`
|
|
|
|
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
|
|
|
BeneficiarySolidarity *solidarity_service.GetPassengerResponse `json:"beneficiarysolidarity"`
|
|
|
|
BookingSolidarity *solidarity_service.GetBookingsByStatusResponse `json:"bookingsolidarity"`
|
|
|
|
|
2022-08-11 15:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s BeneficiariesListState) JSON() template.JS {
|
|
|
|
result, _ := json.Marshal(s)
|
|
|
|
return template.JS(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s BeneficiariesListState) JSONWithLimits(a int, b int) template.JS {
|
2024-08-28 12:10:03 +00:00
|
|
|
if b < len(s.Beneficiaries) {
|
2022-08-11 15:26:55 +00:00
|
|
|
s.Beneficiaries = s.Beneficiaries[a:b]
|
|
|
|
}
|
|
|
|
return s.JSON()
|
|
|
|
}
|
|
|
|
|
2024-09-26 11:34:08 +00:00
|
|
|
func (s BeneficiarySolidarityState) JSON() template.JS {
|
|
|
|
result, _ := json.Marshal(s)
|
|
|
|
return template.JS(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s BeneficiarySolidarityState) JSONWithLimits(a int, b int) template.JS {
|
|
|
|
if b < 5 {
|
|
|
|
s.Beneficiaries = s.Beneficiaries[a:b]
|
|
|
|
}
|
|
|
|
return s.JSON()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (renderer *Renderer) BeneficiariesList(w http.ResponseWriter, r *http.Request, accounts []mobilityaccountsstorage.Account, accountssolidarity *solidarity_service.GetAllPassengersResponse, cacheid string) {
|
2022-08-11 15:26:55 +00:00
|
|
|
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.list.files")
|
|
|
|
|
|
|
|
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
|
|
|
state.ViewState = BeneficiariesListState{
|
2024-09-12 08:52:47 +00:00
|
|
|
Count: len(accounts),
|
2022-08-11 15:26:55 +00:00
|
|
|
CacheId: cacheid,
|
|
|
|
Beneficiaries: accounts,
|
2024-09-26 11:34:08 +00:00
|
|
|
BeneficiariesSolidarity : accountssolidarity,
|
2022-08-11 15:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renderer.Render("beneficiaries_list", w, r, files, state)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (renderer *Renderer) BeneficiaryCreate(w http.ResponseWriter, r *http.Request) {
|
|
|
|
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.create.files")
|
|
|
|
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
|
|
|
|
|
|
|
renderer.Render("beneficiaries_create", w, r, files, state)
|
|
|
|
}
|
|
|
|
|
|
|
|
type BeneficiariesDisplayState struct {
|
|
|
|
Beneficiary any
|
|
|
|
}
|
|
|
|
|
2024-09-26 11:34:08 +00:00
|
|
|
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{}) {
|
2022-08-11 15:26:55 +00:00
|
|
|
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files")
|
|
|
|
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
2022-09-05 05:25:05 +00:00
|
|
|
state.ViewState = map[string]any{
|
2022-10-31 23:40:20 +00:00
|
|
|
"beneficiary": beneficiary,
|
|
|
|
"bookings": bookings,
|
|
|
|
"beneficiaries_file_types": beneficiaries_file_types,
|
|
|
|
"file_types_map": file_types_map,
|
|
|
|
"documents": documents,
|
2022-12-05 19:06:22 +00:00
|
|
|
"organizations": organizations,
|
2024-09-25 13:16:02 +00:00
|
|
|
"event": event,
|
2024-09-26 11:34:08 +00:00
|
|
|
}
|
|
|
|
renderer.Render("beneficiaries_display", w, r, files, state)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (renderer *Renderer) BeneficiarySolidarityDisplay(w http.ResponseWriter, r *http.Request, accounts []mobilityaccountsstorage.Account, beneficiary *solidarity_service.GetPassengerResponse, solidarity_bookings_list *solidarity_service.GetBookingsByStatusResponse, cacheid string) {
|
|
|
|
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files")
|
|
|
|
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
|
|
|
state.ViewState = BeneficiarySolidarityState{
|
|
|
|
Count : len(accounts),
|
|
|
|
CacheId : cacheid,
|
|
|
|
Beneficiaries: accounts,
|
|
|
|
BeneficiarySolidarity : beneficiary,
|
|
|
|
BookingSolidarity : solidarity_bookings_list,
|
|
|
|
|
2022-09-05 05:25:05 +00:00
|
|
|
}
|
2022-08-11 15:26:55 +00:00
|
|
|
renderer.Render("beneficiaries_display", w, r, files, state)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (renderer *Renderer) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request, beneficiary any) {
|
|
|
|
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.update.files")
|
|
|
|
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
|
|
|
state.ViewState = beneficiary
|
|
|
|
|
|
|
|
renderer.Render("beneficiaries_update", w, r, files, state)
|
|
|
|
}
|