solidarity transport updates
This commit is contained in:
@@ -8,6 +8,9 @@ import (
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/icons"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
cache "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
||||
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
||||
validatedprofile "git.coopgo.io/coopgo-apps/parcoursmob/utils/validated-profile"
|
||||
"git.coopgo.io/coopgo-platform/emailing"
|
||||
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
"github.com/coreos/go-oidc/v3/oidc"
|
||||
@@ -20,9 +23,10 @@ type Renderer struct {
|
||||
GlobalConfig *viper.Viper
|
||||
ThemeConfig *viper.Viper
|
||||
Mailer *emailing.Mailer
|
||||
FileStorage cache.FileStorage
|
||||
}
|
||||
|
||||
func NewRenderer(global *viper.Viper, templates_dir string) *Renderer {
|
||||
func NewRenderer(global *viper.Viper, templates_dir string, filestorage cache.FileStorage) *Renderer {
|
||||
theme := viper.New()
|
||||
theme.SetConfigName("config")
|
||||
theme.AddConfigPath(templates_dir)
|
||||
@@ -34,6 +38,7 @@ func NewRenderer(global *viper.Viper, templates_dir string) *Renderer {
|
||||
TemplatesDir: templates_dir,
|
||||
GlobalConfig: global,
|
||||
ThemeConfig: theme,
|
||||
FileStorage: filestorage,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,24 +56,41 @@ func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Req
|
||||
w.WriteHeader(http.StatusOK)
|
||||
t := template.New(name).Funcs(
|
||||
template.FuncMap{
|
||||
"timeFrom": TimeFrom,
|
||||
"timeFormat": TimeFormat,
|
||||
"genderISO5218": GenderISO5218,
|
||||
"dict": Dict,
|
||||
"json": JSON,
|
||||
"rawjson": RawJSON,
|
||||
"unescapeHTML": UnescapeHTML,
|
||||
"walkingLength": WalkingLength,
|
||||
"divideFloat64": Divide[float64],
|
||||
"divideInt": Divide[int],
|
||||
"typeOf": reflect.TypeOf,
|
||||
"moduleAvailable": ModuleAvailable(state.Group, renderer.GlobalConfig),
|
||||
"timeFrom": TimeFrom,
|
||||
"timeFormat": TimeFormat,
|
||||
"genderISO5218": GenderISO5218,
|
||||
"dict": Dict,
|
||||
"json": JSON,
|
||||
"rawjson": RawJSON,
|
||||
"unescapeHTML": UnescapeHTML,
|
||||
"walkingLength": WalkingLength,
|
||||
"divideFloat64": Divide[float64],
|
||||
"divideInt": Divide[int],
|
||||
"typeOf": reflect.TypeOf,
|
||||
"shortDuration": ShortDuration,
|
||||
"beneficiaryValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.beneficiaries.validated_profile")),
|
||||
"solidarityDriverValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.solidarity_transport.drivers.validated_profile")),
|
||||
"carpoolDriverValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.organized_carpool.drivers.validated_profile")),
|
||||
"beneficiaryDocuments": func(id string) []filestorage.FileInfo {
|
||||
documents := renderer.FileStorage.List(filestorage.PREFIX_BENEFICIARIES + "/" + id)
|
||||
return documents
|
||||
},
|
||||
"solidarityDocuments": func(id string) []filestorage.FileInfo {
|
||||
documents := renderer.FileStorage.List(filestorage.PREFIX_SOLIDARITY_TRANSPORT_DRIVERS + "/" + id)
|
||||
return documents
|
||||
},
|
||||
"carpoolDocuments": func(id string) []filestorage.FileInfo {
|
||||
documents := renderer.FileStorage.List(filestorage.PREFIX_ORGANIZED_CARPOOL_DRIVERS + "/" + id)
|
||||
return documents
|
||||
},
|
||||
},
|
||||
)
|
||||
t = template.Must(t.ParseFiles(prefixed_files...))
|
||||
|
||||
err := t.ExecuteTemplate(w, "main", state)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("")
|
||||
log.Error().Err(err).Msg("issue executing template")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,23 +103,39 @@ func (renderer *Renderer) RenderNoLayout(name string, w http.ResponseWriter, r *
|
||||
w.WriteHeader(http.StatusOK)
|
||||
t := template.New(name).Funcs(
|
||||
template.FuncMap{
|
||||
"timeFrom": TimeFrom,
|
||||
"timeFormat": TimeFormat,
|
||||
"genderISO5218": GenderISO5218,
|
||||
"dict": Dict,
|
||||
"json": JSON,
|
||||
"rawjson": RawJSON,
|
||||
"unsescapeHTML": UnescapeHTML,
|
||||
"divideFloat64": Divide[float64],
|
||||
"divideInt": Divide[int],
|
||||
"typeOf": reflect.TypeOf,
|
||||
"timeFrom": TimeFrom,
|
||||
"timeFormat": TimeFormat,
|
||||
"genderISO5218": GenderISO5218,
|
||||
"dict": Dict,
|
||||
"json": JSON,
|
||||
"rawjson": RawJSON,
|
||||
"unsescapeHTML": UnescapeHTML,
|
||||
"divideFloat64": Divide[float64],
|
||||
"divideInt": Divide[int],
|
||||
"typeOf": reflect.TypeOf,
|
||||
"shortDuration": ShortDuration,
|
||||
"beneficiaryValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.beneficiaries.validated_profile")),
|
||||
"solidarityDriverValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.solidarity_transport.drivers.validated_profile")),
|
||||
"carpoolDriverValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.organized_carpool.drivers.validated_profile")),
|
||||
"beneficiaryDocuments": func(id string) []filestorage.FileInfo {
|
||||
documents := renderer.FileStorage.List(filestorage.PREFIX_BENEFICIARIES + "/" + id)
|
||||
return documents
|
||||
},
|
||||
"solidarityDocuments": func(id string) []filestorage.FileInfo {
|
||||
documents := renderer.FileStorage.List(filestorage.PREFIX_SOLIDARITY_TRANSPORT_DRIVERS + "/" + id)
|
||||
return documents
|
||||
},
|
||||
"carpoolDocuments": func(id string) []filestorage.FileInfo {
|
||||
documents := renderer.FileStorage.List(filestorage.PREFIX_ORGANIZED_CARPOOL_DRIVERS + "/" + id)
|
||||
return documents
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
t = template.Must(t.ParseFiles(prefixed_files...))
|
||||
err := t.ExecuteTemplate(w, "main", state)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("")
|
||||
log.Error().Err(err).Msg("issue executing template")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +155,7 @@ type RenderState struct {
|
||||
|
||||
func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) RenderState {
|
||||
iconset := themeConfig.GetStringMapString("icons.svg")
|
||||
menu := themeConfig.Get("menu_items")
|
||||
|
||||
// Get State elements from Request
|
||||
var userid string
|
||||
@@ -162,6 +201,9 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
|
||||
Active: menuState == administrationMenu,
|
||||
},
|
||||
|
||||
Menu: menu,
|
||||
|
||||
// DEPRECATED
|
||||
MenuItems: []MenuItem{
|
||||
{
|
||||
Title: "Tableau de bord",
|
||||
@@ -172,6 +214,7 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
|
||||
},
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
if modules["beneficiaries"] != nil && modules["beneficiaries"].(bool) {
|
||||
ls.MenuItems = append(ls.MenuItems, MenuItem{
|
||||
Title: "Bénéficiaires",
|
||||
@@ -252,14 +295,6 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
|
||||
Icon: "hero:outline/document-text",
|
||||
})
|
||||
}
|
||||
/*if modules["conseillers"] != nil && modules["conseillers"].(bool) {
|
||||
ls.MenuItems = append(ls.MenuItems, MenuItem{
|
||||
Title: "Conseillers",
|
||||
Link: "/app/conseillers/",
|
||||
Active: menuState == membersMenu,
|
||||
Icon: "hero:outline/user-group",
|
||||
})
|
||||
}*/
|
||||
/*if modules["diags"] != nil && modules["diags"].(bool) {
|
||||
ls.MenuItems = append(ls.MenuItems, MenuItem{
|
||||
Title: "Diagnostics",
|
||||
|
||||
Reference in New Issue
Block a user