The backend for the AiteStory website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1004 B

  1. package viewmodel
  2. import (
  3. "fmt"
  4. "git.aiterp.net/AiteRP/aitestory/model"
  5. "git.aiterp.net/gisle/wrouter/auth"
  6. )
  7. // TagList is a view model for rendering the tag lists.
  8. type TagList struct {
  9. Base
  10. Type string
  11. Tags []model.Tag
  12. TagCategories []string
  13. tagMap map[string][]model.Tag
  14. }
  15. // Map lazy-loads the map of tags, which is only
  16. // used when listing all of them.
  17. func (tl TagList) Map() map[string][]model.Tag {
  18. // Set up the map
  19. tl.tagMap = make(map[string][]model.Tag, len(model.TagTypes))
  20. for _, tagType := range model.TagTypes {
  21. tl.tagMap[tagType] = make([]model.Tag, 0, 64)
  22. }
  23. // Organize
  24. for _, tag := range tl.Tags {
  25. tl.tagMap[tag.Type] = append(tl.tagMap[tag.Type], tag)
  26. }
  27. return tl.tagMap
  28. }
  29. // Setup sets up the page model and the base, and should
  30. // be run after the details have been filled in.
  31. func (tl *TagList) Setup(user *auth.User) {
  32. title := tl.Type
  33. if tl.Type != "" {
  34. title = "All"
  35. }
  36. tl.setupBase(user, fmt.Sprintf("%s Tags", title))
  37. }