2024-05-02 07:54:51 +00:00
|
|
|
package renderer
|
|
|
|
|
|
|
|
import (
|
2024-09-12 08:52:47 +00:00
|
|
|
"encoding/json"
|
|
|
|
"html/template"
|
2024-05-02 07:54:51 +00:00
|
|
|
"net/http"
|
2024-09-12 08:52:47 +00:00
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
2024-09-25 13:16:02 +00:00
|
|
|
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
2024-05-02 07:54:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const solidarityserviceMenu = "solidarity_service"
|
|
|
|
|
2024-09-12 08:52:47 +00:00
|
|
|
|
|
|
|
type SolidarityListState struct {
|
|
|
|
Count int `json:"count"`
|
2024-09-17 08:30:29 +00:00
|
|
|
CacheId string `json:"cache_id"`
|
2024-09-25 13:16:02 +00:00
|
|
|
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
|
2024-09-12 08:52:47 +00:00
|
|
|
Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"`
|
2024-09-25 13:16:02 +00:00
|
|
|
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
2024-09-12 08:52:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-09-25 13:16:02 +00:00
|
|
|
type BeneficiariesSolidarityListState struct {
|
|
|
|
Count int `json:"count"`
|
|
|
|
CacheId string `json:"cache_id"`
|
|
|
|
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
|
|
|
|
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
type SolidarityBookingsState struct {
|
|
|
|
Bookings *solidarity_service.CreateBookingSolidarityResponse `json:"bookings"`
|
|
|
|
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s BeneficiariesSolidarityListState) JSON() template.JS {
|
|
|
|
result, _ := json.Marshal(s)
|
|
|
|
return template.JS(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s BeneficiariesSolidarityListState) JSONWithLimits(a int, b int) template.JS {
|
|
|
|
if b < 5 {
|
|
|
|
s.Beneficiaries = s.Beneficiaries[a:b]
|
|
|
|
}
|
|
|
|
return s.JSON()
|
|
|
|
}
|
|
|
|
|
2024-09-12 08:52:47 +00:00
|
|
|
func (s SolidarityListState) JSON() template.JS {
|
|
|
|
result, _ := json.Marshal(s)
|
|
|
|
return template.JS(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s SolidarityListState) JSONWithLimits(a int, b int) template.JS {
|
2024-09-25 13:16:02 +00:00
|
|
|
if b < 5 {
|
2024-09-12 08:52:47 +00:00
|
|
|
s.Beneficiaries = s.Beneficiaries[a:b]
|
|
|
|
}
|
|
|
|
return s.JSON()
|
|
|
|
}
|
|
|
|
|
2024-09-26 11:34:08 +00:00
|
|
|
func (s SolidarityBookingsState) JSON() template.JS {
|
|
|
|
result, _ := json.Marshal(s)
|
|
|
|
return template.JS(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s SolidarityBookingsState) JSONWithLimits(a int, b int) template.JS {
|
|
|
|
if b < 5 {
|
|
|
|
s.Beneficiaries = s.Beneficiaries[a:b]
|
|
|
|
}
|
|
|
|
return s.JSON()
|
|
|
|
}
|
|
|
|
|
2024-11-07 17:14:48 +00:00
|
|
|
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
|
2024-09-12 08:52:47 +00:00
|
|
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
|
|
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
2024-09-25 13:16:02 +00:00
|
|
|
state.ViewState = BeneficiariesSolidarityListState{
|
|
|
|
Count: len(parcourmobAccounts),
|
2024-09-12 08:52:47 +00:00
|
|
|
CacheId: cacheid,
|
2024-09-25 13:16:02 +00:00
|
|
|
Beneficiaries: parcourmobAccounts,
|
2024-09-12 08:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renderer.Render("solidarity_service", w, r, files, state)
|
|
|
|
}
|
|
|
|
|
2024-09-25 13:16:02 +00:00
|
|
|
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, bookings *solidarity_service.CreateBookingSolidarityResponse, parcourmobAccounts []mobilityaccountsstorage.Account) {
|
2024-08-28 12:10:03 +00:00
|
|
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
2024-05-02 07:54:51 +00:00
|
|
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
2024-09-25 13:16:02 +00:00
|
|
|
state.ViewState = SolidarityBookingsState{
|
|
|
|
Bookings: bookings,
|
|
|
|
Beneficiaries: parcourmobAccounts,
|
|
|
|
|
2024-08-28 12:10:03 +00:00
|
|
|
}
|
2024-05-02 07:54:51 +00:00
|
|
|
|
|
|
|
renderer.Render("solidarity_service", w, r, files, state)
|
|
|
|
}
|
2024-06-07 09:51:01 +00:00
|
|
|
|
2024-11-07 17:14:48 +00:00
|
|
|
func (renderer *Renderer) SolidarityServiceListAvailableDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, booking *solidarity_service.CreateBookingSolidarityRequest, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
|
2024-08-28 12:10:03 +00:00
|
|
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
2024-06-07 09:51:01 +00:00
|
|
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
2024-09-12 08:52:47 +00:00
|
|
|
state.ViewState = SolidarityListState {
|
2024-09-25 13:16:02 +00:00
|
|
|
Count: len(parcourmobAccounts),
|
2024-09-12 08:52:47 +00:00
|
|
|
CacheId: cacheid,
|
|
|
|
Drivers: drivers,
|
2024-09-25 13:16:02 +00:00
|
|
|
Beneficiaries: parcourmobAccounts,
|
|
|
|
|
2024-09-12 08:52:47 +00:00
|
|
|
}
|
2024-06-07 09:51:01 +00:00
|
|
|
|
|
|
|
renderer.Render("solidarity_service", w, r, files, state)
|
|
|
|
}
|