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
|
|
|
|
|
|
|
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"
|
|
|
|
|
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"`
|
|
|
|
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
2024-09-12 08:52:47 +00:00
|
|
|
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) {
|
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-17 08:30:29 +00:00
|
|
|
state.ViewState = BeneficiariesListState{
|
|
|
|
Count: len(accounts),
|
2024-09-12 08:52:47 +00:00
|
|
|
CacheId: cacheid,
|
2024-09-17 08:30:29 +00:00
|
|
|
Beneficiaries: accounts,
|
2024-09-12 08:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
2024-09-12 08:52:47 +00:00
|
|
|
"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-06-07 09:51:01 +00:00
|
|
|
|
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")
|
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 {
|
|
|
|
Count: len(accounts),
|
|
|
|
Beneficiaries: accounts,
|
|
|
|
CacheId: cacheid,
|
|
|
|
Drivers: drivers,
|
|
|
|
}
|
2024-06-07 09:51:01 +00:00
|
|
|
|
|
|
|
renderer.Render("solidarity_service", w, r, files, state)
|
|
|
|
}
|