2022-03-26 15:26:14 +00:00
|
|
|
|
package views
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/util"
|
2022-03-29 20:59:36 +00:00
|
|
|
|
"github.com/bouncepaw/mycorrhiza/viewutil"
|
2022-03-26 15:26:14 +00:00
|
|
|
|
"html/template"
|
|
|
|
|
"io"
|
|
|
|
|
"log"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const adminTranslationRu = `
|
|
|
|
|
{{define "panel title"}}Панель админстратора{{end}}
|
|
|
|
|
{{define "panel safe section title"}}Безопасная секция{{end}}
|
|
|
|
|
{{define "panel link about"}}Об этой вики{{end}}
|
|
|
|
|
{{define "panel update header"}}Обновить ссылки в верхней панели{{end}}
|
|
|
|
|
{{define "panel link user list"}}Список пользователей{{end}}
|
|
|
|
|
{{define "panel users"}}Управление пользователями{{end}}
|
|
|
|
|
{{define "panel unsafe section title"}}Опасная секция{{end}}
|
|
|
|
|
{{define "panel shutdown"}}Выключить вики{{end}}
|
|
|
|
|
{{define "panel reindex hyphae"}}Переиндексировать гифы{{end}}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
adminTemplatesEn *template.Template
|
|
|
|
|
adminTemplatesRu *template.Template
|
|
|
|
|
)
|
|
|
|
|
|
2022-03-29 20:59:36 +00:00
|
|
|
|
func localizedAdminTemplates(meta viewutil.Meta) *template.Template {
|
2022-03-26 15:26:14 +00:00
|
|
|
|
if meta.Lc.Locale == "ru" {
|
|
|
|
|
return adminTemplatesRu
|
|
|
|
|
}
|
|
|
|
|
return adminTemplatesEn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func templateAsString(temp *template.Template, name string, datum ...interface{}) string {
|
|
|
|
|
var buf strings.Builder
|
|
|
|
|
var err error
|
|
|
|
|
if len(datum) == 1 {
|
|
|
|
|
err = temp.ExecuteTemplate(&buf, name, datum[0])
|
|
|
|
|
} else {
|
|
|
|
|
err = temp.ExecuteTemplate(&buf, name, nil)
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
return buf.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
adminTemplatesEn = template.Must(
|
|
|
|
|
template.
|
|
|
|
|
New("admin").
|
|
|
|
|
Funcs(template.FuncMap{
|
|
|
|
|
"beautifulName": util.BeautifulName,
|
|
|
|
|
}).
|
|
|
|
|
ParseFS(fs, "admin.html"))
|
|
|
|
|
adminTemplatesRu = template.Must(
|
|
|
|
|
template.Must(adminTemplatesEn.Clone()).Parse(adminTranslationRu))
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-29 20:59:36 +00:00
|
|
|
|
func AdminPanel(meta viewutil.Meta) {
|
2022-03-26 15:26:14 +00:00
|
|
|
|
var buf strings.Builder
|
|
|
|
|
err := localizedAdminTemplates(meta).ExecuteTemplate(&buf, "panel", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
_, err = io.WriteString(meta.W, Base(
|
2022-04-01 19:51:15 +00:00
|
|
|
|
meta,
|
2022-03-26 15:26:14 +00:00
|
|
|
|
templateAsString(localizedAdminTemplates(meta), "panel title"),
|
|
|
|
|
buf.String(),
|
|
|
|
|
))
|
2022-04-02 08:09:37 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
2022-03-26 15:26:14 +00:00
|
|
|
|
}
|