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)) }