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.

49 lines
1.0 KiB

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