2022-04-01 20:52:56 +00:00
|
|
|
|
package categories
|
2022-03-19 20:57:33 +00:00
|
|
|
|
|
|
|
|
|
import (
|
2022-04-01 20:52:56 +00:00
|
|
|
|
"embed"
|
2022-03-29 20:59:36 +00:00
|
|
|
|
"github.com/bouncepaw/mycorrhiza/viewutil"
|
2022-03-19 20:57:33 +00:00
|
|
|
|
"log"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2022-04-01 21:59:47 +00:00
|
|
|
|
const ruTranslation = `
|
2022-03-20 19:24:40 +00:00
|
|
|
|
{{define "empty cat"}}Эта категория пуста.{{end}}
|
|
|
|
|
{{define "add hypha"}}Добавить в категорию{{end}}
|
|
|
|
|
{{define "cat"}}Категория{{end}}
|
|
|
|
|
{{define "hypha name"}}Имя гифы{{end}}
|
2022-03-22 13:57:25 +00:00
|
|
|
|
{{define "categories"}}Категории{{end}}
|
2022-03-23 12:46:08 +00:00
|
|
|
|
{{define "placeholder"}}Имя категории...{{end}}
|
2022-03-22 13:57:25 +00:00
|
|
|
|
{{define "remove from category title"}}Убрать гифу из этой категории{{end}}
|
2022-03-23 12:46:08 +00:00
|
|
|
|
{{define "add to category title"}}Добавить гифу в эту категорию{{end}}
|
2022-04-01 21:59:47 +00:00
|
|
|
|
{{define "category list"}}Список категорий{{end}}
|
2022-03-23 12:46:08 +00:00
|
|
|
|
{{define "no categories"}}В этой вики нет категорий.{{end}}
|
|
|
|
|
{{define "category x"}}Категория {{. | beautifulName}}{{end}}
|
2022-03-20 19:24:40 +00:00
|
|
|
|
`
|
|
|
|
|
|
2022-03-20 08:21:59 +00:00
|
|
|
|
var (
|
2022-04-01 20:52:56 +00:00
|
|
|
|
//go:embed *.html
|
2022-04-01 21:35:40 +00:00
|
|
|
|
fs embed.FS
|
|
|
|
|
viewListChain, viewPageChain, viewCardChain viewutil.Chain
|
2022-03-20 08:21:59 +00:00
|
|
|
|
)
|
2022-03-19 20:57:33 +00:00
|
|
|
|
|
2022-04-01 20:52:56 +00:00
|
|
|
|
func prepareViews() {
|
2022-05-18 16:58:24 +00:00
|
|
|
|
viewCardChain = viewutil.CopyEnRuWith(fs, "view_card.html", ruTranslation)
|
|
|
|
|
viewListChain = viewutil.CopyEnRuWith(fs, "view_list.html", ruTranslation)
|
|
|
|
|
viewPageChain = viewutil.CopyEnRuWith(fs, "view_page.html", ruTranslation)
|
2022-03-19 20:57:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 21:35:40 +00:00
|
|
|
|
type cardData struct {
|
|
|
|
|
HyphaName string
|
|
|
|
|
Categories []string
|
|
|
|
|
GivenPermissionToModify bool
|
2022-03-23 12:46:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 21:59:47 +00:00
|
|
|
|
// CategoryCard is the little sidebar that is shown nearby the hypha view.
|
2022-04-01 20:52:56 +00:00
|
|
|
|
func CategoryCard(meta viewutil.Meta, hyphaName string) string {
|
2022-03-23 12:46:08 +00:00
|
|
|
|
var buf strings.Builder
|
2022-04-01 21:35:40 +00:00
|
|
|
|
err := viewCardChain.Get(meta).ExecuteTemplate(&buf, "category card", cardData{
|
2022-04-23 18:53:15 +00:00
|
|
|
|
HyphaName: hyphaName,
|
|
|
|
|
Categories: categoriesWithHypha(hyphaName),
|
|
|
|
|
GivenPermissionToModify: meta.U.CanProceed("add-to-category"),
|
2022-03-19 20:57:33 +00:00
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
return buf.String()
|
|
|
|
|
}
|
2022-03-20 08:21:59 +00:00
|
|
|
|
|
2022-04-01 21:07:28 +00:00
|
|
|
|
type pageData struct {
|
2022-05-18 16:46:01 +00:00
|
|
|
|
*viewutil.BaseData
|
2022-04-01 21:07:28 +00:00
|
|
|
|
CatName string
|
|
|
|
|
Hyphae []string
|
|
|
|
|
GivenPermissionToModify bool
|
2022-03-20 08:21:59 +00:00
|
|
|
|
}
|
2022-03-20 18:24:54 +00:00
|
|
|
|
|
2022-04-01 21:07:28 +00:00
|
|
|
|
func categoryPage(meta viewutil.Meta, catName string) {
|
2022-05-18 16:46:01 +00:00
|
|
|
|
viewutil.ExecutePage(meta, viewPageChain, pageData{
|
|
|
|
|
BaseData: &viewutil.BaseData{
|
|
|
|
|
Addr: "/category/" + catName,
|
2022-04-01 21:07:28 +00:00
|
|
|
|
},
|
|
|
|
|
CatName: catName,
|
2022-04-01 21:43:11 +00:00
|
|
|
|
Hyphae: hyphaeInCategory(catName),
|
2022-04-01 21:07:28 +00:00
|
|
|
|
GivenPermissionToModify: meta.U.CanProceed("add-to-category"),
|
2022-05-18 16:46:01 +00:00
|
|
|
|
})
|
2022-04-01 20:52:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type listData struct {
|
2022-05-18 16:46:01 +00:00
|
|
|
|
*viewutil.BaseData
|
2022-04-01 20:52:56 +00:00
|
|
|
|
Categories []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func categoryList(meta viewutil.Meta) {
|
2022-05-18 16:46:01 +00:00
|
|
|
|
viewutil.ExecutePage(meta, viewListChain, listData{
|
|
|
|
|
BaseData: &viewutil.BaseData{
|
|
|
|
|
Addr: "/category",
|
2022-04-01 20:52:56 +00:00
|
|
|
|
},
|
2022-04-01 21:43:11 +00:00
|
|
|
|
Categories: listOfCategories(),
|
2022-05-18 16:46:01 +00:00
|
|
|
|
})
|
2022-03-20 18:24:54 +00:00
|
|
|
|
}
|