add template func for listing languages
This commit is contained in:
parent
8c32b88cce
commit
9863c6b166
@ -7,6 +7,7 @@ import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-kit/kit/log/level"
|
||||
@ -122,6 +123,37 @@ func New(
|
||||
}
|
||||
}),
|
||||
|
||||
render.InjectTemplateFunc("listLanguages", func(r *http.Request) interface{} {
|
||||
urlTo := web.NewURLTo(m)
|
||||
route := urlTo(router.CompleteSetLanguage).String()
|
||||
csrfElement := csrf.TemplateField(r)
|
||||
|
||||
createFormElement := func (tag, translation string) string {
|
||||
return fmt.Sprintf(`
|
||||
<form
|
||||
action="%s"
|
||||
method="POST"
|
||||
>
|
||||
%s
|
||||
<input type="hidden" name="lang" value="%s">
|
||||
<input
|
||||
type="submit"
|
||||
value="%s"
|
||||
class="text-gray-500 hover:underline"
|
||||
/>
|
||||
</form>
|
||||
`, route, csrfElement, tag, translation)
|
||||
}
|
||||
return func () template.HTML {
|
||||
languages := locHelper.ListLanguages()
|
||||
languageOptions := make([]string, len(languages))
|
||||
for tag, translation := range languages {
|
||||
languageOptions = append(languageOptions, createFormElement(tag, translation))
|
||||
}
|
||||
return (template.HTML)(strings.Join(languageOptions, "\n"))
|
||||
}
|
||||
}),
|
||||
|
||||
render.InjectTemplateFunc("urlToNotice", func(r *http.Request) interface{} {
|
||||
return func(name string) *url.URL {
|
||||
noticeName := roomdb.PinnedNoticeName(name)
|
||||
@ -237,6 +269,11 @@ func New(
|
||||
)
|
||||
mainMux.Handle("/admin/", members.AuthenticateFromContext(r)(adminHandler))
|
||||
|
||||
// handle setting language
|
||||
m.Get(router.CompleteSetLanguage).HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
fmt.Println("set das language jaaa")
|
||||
})
|
||||
|
||||
// landing page
|
||||
m.Get(router.CompleteIndex).Handler(r.HTML("landing/index.tmpl", func(w http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
// TODO: try websocket upgrade (issue #)
|
||||
|
@ -14,6 +14,8 @@ const (
|
||||
CompleteNoticeShow = "complete:notice:show"
|
||||
CompleteNoticeList = "complete:notice:list"
|
||||
|
||||
CompleteSetLanguage = "complete:set-language"
|
||||
|
||||
CompleteAliasResolve = "complete:alias:resolve"
|
||||
|
||||
CompleteInviteFacade = "complete:invite:accept"
|
||||
@ -42,5 +44,7 @@ func CompleteApp() *mux.Router {
|
||||
m.Path("/notice/show").Methods("GET").Name(CompleteNoticeShow)
|
||||
m.Path("/notice/list").Methods("GET").Name(CompleteNoticeList)
|
||||
|
||||
m.Path("/set-language").Methods("POST").Name(CompleteSetLanguage)
|
||||
|
||||
return m
|
||||
}
|
||||
|
@ -95,16 +95,8 @@
|
||||
class="mb-2 mx-auto px-3 py-1 text-gray-500 w-32 rounded shadow bg-gray-50 ring-1 ring-gray-300 hover:bg-gray-100 cursor-pointer">
|
||||
Language
|
||||
</summary>
|
||||
<div
|
||||
class="grid grid-cols-2 justify-items-center gap-x-1">
|
||||
<a href="" class="text-gray-500 bold hover:underline">English</a>
|
||||
<a href="" class="text-gray-500 hover:underline">Hmong</a>
|
||||
<a href="" class="text-gray-500 hover:underline">Унáҥам Тунý</a>
|
||||
<a href="" class="text-gray-500 hover:underline">Suomi</a>
|
||||
<a href="" class="text-gray-500 hover:underline">Русский</a>
|
||||
<a href="" class="text-gray-500 hover:underline">xapaitíiso</a>
|
||||
<a href="" class="text-gray-500 hover:underline">Português</a>
|
||||
<a href="" class="text-gray-500 hover:underline">Svenska</a>
|
||||
<div class="grid grid-cols-2 justify-items-center gap-x-1">
|
||||
{{ listLanguages }}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user