parcoursmob/renderer/solidarity_service.go

69 lines
2.4 KiB
Go
Raw Normal View History

2024-05-02 07:54:51 +00:00
package renderer
import (
"encoding/json"
"html/template"
2024-05-02 07:54:51 +00:00
"net/http"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
2024-08-28 12:10:03 +00:00
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
2024-05-02 07:54:51 +00:00
)
const solidarityserviceMenu = "solidarity_service"
type SolidarityListState struct {
Count int `json:"count"`
2024-09-17 08:30:29 +00:00
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()
}
2024-09-17 08:30:29 +00:00
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)
2024-09-17 08:30:29 +00:00
state.ViewState = BeneficiariesListState{
Count: len(accounts),
CacheId: cacheid,
2024-09-17 08:30:29 +00:00
Beneficiaries: accounts,
}
renderer.Render("solidarity_service", w, r, files, state)
}
2024-09-17 12:42:27 +00:00
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, booking *solidarity_service.CreateBookingSolidarityResponse) {
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-08-28 12:10:03 +00:00
state.ViewState = map[string]any{
"booking": booking,
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-09-18 13:56:13 +00:00
func (renderer *Renderer) SolidarityServiceListAvailableDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, booking *solidarity_service.CreateBookingSolidarityRequest, accounts []mobilityaccountsstorage.Account, cacheid string) {
2024-08-28 12:10:03 +00:00
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)
}