package renderer
import (
"encoding/json"
"html/template"
"net/http"
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
)
const solidarityserviceMenu = "solidarity_service"
type SolidarityListState struct {
Count int `json:"count"`
CacheId string `json:"cache_id"`
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
}
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()
}
func (s SolidarityListState) JSON() template.JS {
result, _ := json.Marshal(s)
return template.JS(result)
}
func (s SolidarityListState) JSONWithLimits(a int, b int) template.JS {
if b < 5 {
s.Beneficiaries = s.Beneficiaries[a:b]
}
return s.JSON()
}
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()
}
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = BeneficiariesSolidarityListState{
Count: len(parcourmobAccounts),
CacheId: cacheid,
Beneficiaries: parcourmobAccounts,
}
renderer.Render("solidarity_service", w, r, files, state)
}
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, bookings *solidarity_service.CreateBookingSolidarityResponse, parcourmobAccounts []mobilityaccountsstorage.Account) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = SolidarityBookingsState{
Bookings: bookings,
Beneficiaries: parcourmobAccounts,
}
renderer.Render("solidarity_service", w, r, files, state)
}
func (renderer *Renderer) SolidarityServiceListAvailableDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, booking *solidarity_service.CreateBookingSolidarityRequest, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = SolidarityListState {
Count: len(parcourmobAccounts),
CacheId: cacheid,
Drivers: drivers,
Beneficiaries: parcourmobAccounts,
}
renderer.Render("solidarity_service", w, r, files, state)
}