parcoursmob/renderer/solidarity_service.go

70 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, drivers *solidarity_service.DriverJourneysResponse, 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)
}
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, booking *solidarity_service.BookingSolidarityRequest) {
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) SolidarityServiceBookingListDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, accounts []mobilityaccountsstorage.Account, booking *solidarity_service.BookingSolidarityRequest, 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)
}