Browse Source
Changed tags to allow same-name taggs with different categories, added tag list
master
Changed tags to allow same-name taggs with different categories, added tag list
master
Gisle Aune
7 years ago
10 changed files with 220 additions and 13 deletions
-
46controllers/listcontroller.go
-
34controllers/tagcontroller.go
-
1main.go
-
43model/tag.go
-
1view/renderer.go
-
2view/templates/base/default.tmpl
-
6view/templates/index.tmpl
-
4view/templates/page/view.tmpl
-
48view/templates/tags/list.tmpl
-
46viewmodel/taglist.go
@ -0,0 +1,34 @@ |
|||||
|
package controllers |
||||
|
|
||||
|
import ( |
||||
|
"net/http" |
||||
|
|
||||
|
"git.aiterp.net/AiteRP/aitestory/view" |
||||
|
"git.aiterp.net/AiteRP/aitestory/viewmodel" |
||||
|
|
||||
|
"git.aiterp.net/AiteRP/aitestory/model" |
||||
|
"git.aiterp.net/gisle/wrouter" |
||||
|
"git.aiterp.net/gisle/wrouter/auth" |
||||
|
) |
||||
|
|
||||
|
// TagController serves and handles the tag managment pages
|
||||
|
var TagController = wrouter.Router{} |
||||
|
|
||||
|
func tagList(path string, w http.ResponseWriter, req *http.Request, user *auth.User) bool { |
||||
|
//var err error
|
||||
|
if (req.Method != "GET" && req.Method != "POST") || len(req.URL.Path) > len(path) { |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
tl := viewmodel.TagList{} |
||||
|
tl.Tags, _ = model.ListTags() |
||||
|
tl.Setup(user) |
||||
|
|
||||
|
view.Render(w, "tags/list", 200, tl) |
||||
|
|
||||
|
return true |
||||
|
} |
||||
|
|
||||
|
func init() { |
||||
|
TagController.Function("/", tagList) |
||||
|
} |
@ -0,0 +1,48 @@ |
|||||
|
{{ define "content" }} |
||||
|
<article> |
||||
|
<h1>All Tags</h1> |
||||
|
|
||||
|
<div class="tag-list"> |
||||
|
{{ range $tagHeader, $tags := .Map }} |
||||
|
<div class="tl-item"> |
||||
|
<h2>{{ $tagHeader }}</h2> |
||||
|
<ul> |
||||
|
{{ range $tags }} |
||||
|
<li><a class="ttype-{{.Type | tolower }}" href="/{{.Type}}/{{.Name}}">{{ .Name }}</a></li> |
||||
|
{{ end }} |
||||
|
</ul> |
||||
|
</div> |
||||
|
{{ end }} |
||||
|
</div> |
||||
|
|
||||
|
|
||||
|
</article> |
||||
|
{{ end }} |
||||
|
|
||||
|
{{ define "menu" }} |
||||
|
<a href="/"><h1>Tags</h1></a> |
||||
|
|
||||
|
<ul> |
||||
|
<li><a href="/"><div class="mg-icon"><</div><div class="mg-label">Back</div></a></li> |
||||
|
</ul> |
||||
|
|
||||
|
{{ if $.User.LoggedIn }} |
||||
|
<ul> |
||||
|
<li><a href="/page/create"><div class="mg-icon">+</div><div class="mg-label">Create</div></a></li> |
||||
|
</ul> |
||||
|
|
||||
|
<ul> |
||||
|
<li><a href="/user/logout"><div class="mg-icon">A</div><div class="mg-label">Logout</div></a></li> |
||||
|
</ul> |
||||
|
{{ else }} |
||||
|
<ul> |
||||
|
<li><a href="/user/login"><div class="mg-icon">A</div><div class="mg-label">Login</div></a></li> |
||||
|
</ul> |
||||
|
{{ end }} |
||||
|
|
||||
|
|
||||
|
{{ end }} |
||||
|
|
||||
|
{{ define "head" }} |
||||
|
|
||||
|
{{ end }} |
@ -0,0 +1,46 @@ |
|||||
|
package viewmodel |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
|
||||
|
"git.aiterp.net/AiteRP/aitestory/model" |
||||
|
"git.aiterp.net/gisle/wrouter/auth" |
||||
|
) |
||||
|
|
||||
|
// TagList is a view model for rendering the tag lists.
|
||||
|
type TagList struct { |
||||
|
Base |
||||
|
Type string |
||||
|
Tags []model.Tag |
||||
|
TagCategories []string |
||||
|
|
||||
|
tagMap map[string][]model.Tag |
||||
|
} |
||||
|
|
||||
|
// Map lazy-loads the map of tags, which is only
|
||||
|
// used when listing all of them.
|
||||
|
func (tl TagList) Map() map[string][]model.Tag { |
||||
|
// Set up the map
|
||||
|
tl.tagMap = make(map[string][]model.Tag, len(model.TagTypes)) |
||||
|
for _, tagType := range model.TagTypes { |
||||
|
tl.tagMap[tagType] = make([]model.Tag, 0, 64) |
||||
|
} |
||||
|
|
||||
|
// Organize
|
||||
|
for _, tag := range tl.Tags { |
||||
|
tl.tagMap[tag.Type] = append(tl.tagMap[tag.Type], tag) |
||||
|
} |
||||
|
|
||||
|
return tl.tagMap |
||||
|
} |
||||
|
|
||||
|
// Setup sets up the page model and the base, and should
|
||||
|
// be run after the details have been filled in.
|
||||
|
func (tl *TagList) Setup(user *auth.User) { |
||||
|
title := tl.Type |
||||
|
if tl.Type != "" { |
||||
|
title = "All" |
||||
|
} |
||||
|
|
||||
|
tl.setupBase(user, fmt.Sprintf("%s Tags", title)) |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue