69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
package renderer
|
|
|
|
import (
|
|
"encoding/json"
|
|
"html/template"
|
|
"net/http"
|
|
|
|
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
|
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
|
)
|
|
|
|
const solidarityserviceMenu = "solidarity_service"
|
|
|
|
|
|
type SolidarityListState struct {
|
|
Count int `json:"count"`
|
|
CacheId string `json:"cache_id"`
|
|
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
|
Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"`
|
|
|
|
}
|
|
|
|
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 < len(s.Beneficiaries) {
|
|
s.Beneficiaries = s.Beneficiaries[a:b]
|
|
}
|
|
return s.JSON()
|
|
}
|
|
|
|
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, accounts []mobilityaccountsstorage.Account, cacheid string) {
|
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
|
state.ViewState = BeneficiariesListState{
|
|
Count: len(accounts),
|
|
CacheId: cacheid,
|
|
Beneficiaries: accounts,
|
|
}
|
|
|
|
renderer.Render("solidarity_service", w, r, files, state)
|
|
}
|
|
|
|
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, booking *solidarity_service.CreateBookingSolidarityResponse) {
|
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
|
state.ViewState = map[string]any{
|
|
"booking": booking,
|
|
}
|
|
|
|
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, accounts []mobilityaccountsstorage.Account, cacheid string) {
|
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
|
state.ViewState = SolidarityListState {
|
|
Count: len(accounts),
|
|
Beneficiaries: accounts,
|
|
CacheId: cacheid,
|
|
Drivers: drivers,
|
|
}
|
|
|
|
renderer.Render("solidarity_service", w, r, files, state)
|
|
}
|