Massive overhaul, fixing menus and changing template engine. Added /month/ and /author/ filters

This commit is contained in:
2017-10-29 17:41:40 +01:00
parent b05f53308e
commit fb9e43ba12
44 changed files with 862 additions and 519 deletions
+7 -2
View File
@@ -16,11 +16,14 @@ type Base struct {
LoggedIn bool
SessionID string
}
ViewTitle string
ViewBackground string
ViewPath string
ViewTitle string
Message string
}
// InitBase initializes the base of the viewmodel
func (base *Base) setupBase(user *auth.User, viewTitle string) {
func (base *Base) setupBase(user *auth.User, viewTitle string, viewPath string) {
if user != nil {
base.User.ID = user.FullID()
base.User.Name = user.ID
@@ -29,5 +32,7 @@ func (base *Base) setupBase(user *auth.User, viewTitle string) {
base.User.SessionID = user.Session.ID
}
base.ViewPath = viewPath
base.ViewTitle = fmt.Sprintf("%s - %s", viewTitle, server.Main.Config.View.Title)
}
+16
View File
@@ -0,0 +1,16 @@
package viewmodel
import "git.aiterp.net/AiteRP/aitestory/model"
// IndexBase is used for the index menu.
type IndexBase struct {
Categories []model.PageCategory
ActiveTag model.Tag
ActiveAuthor string
ActiveDate string
ActiveDatePath string
}
func (im *IndexBase) setupMenu() {
im.Categories = model.PageCategories
}
@@ -5,18 +5,18 @@ import (
"git.aiterp.net/gisle/wrouter/auth"
)
// PageList is a view model for rendering the front page
type PageList struct {
// IndexList is a view model for rendering the front page
type IndexList struct {
Base
IndexBase
Headers []model.Header
ActiveCategory model.PageCategory
Categories []model.PageCategory
ActiveTag model.Tag
FavoriteTags []model.Tag
}
// Setup sets up the page model and the base, and should
// be run after the details have been filled in.
func (pl *PageList) Setup(user *auth.User) {
pl.setupBase(user, "Index")
func (il *IndexList) Setup(user *auth.User, viewPath string, viewTitle string) {
il.setupMenu()
il.setupBase(user, viewTitle, viewPath)
}
+49
View File
@@ -0,0 +1,49 @@
package viewmodel
import (
"fmt"
"git.aiterp.net/AiteRP/aitestory/model"
"git.aiterp.net/gisle/wrouter/auth"
)
// IndexTags is a view model for rendering the tag lists.
type IndexTags struct {
Base
IndexBase
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 (it IndexTags) Map() map[string][]model.Tag {
// Set up the map
it.tagMap = make(map[string][]model.Tag, len(model.TagTypes))
for _, tagType := range model.TagTypes {
it.tagMap[tagType] = make([]model.Tag, 0, 64)
}
// Organize
for _, tag := range it.Tags {
it.tagMap[tag.Type] = append(it.tagMap[tag.Type], tag)
}
return it.tagMap
}
// Setup sets up the page model and the base, and should
// be run after the details have been filled in.
func (it *IndexTags) Setup(user *auth.User, viewPath string) {
title := it.Type
if it.Type != "" {
title = "All"
}
it.setupMenu()
it.setupBase(user, fmt.Sprintf("%s Tags", title), viewPath)
}
+19
View File
@@ -0,0 +1,19 @@
package viewmodel
import "git.aiterp.net/gisle/wrouter/auth"
// Message is a simple viewmodel for the message pages
type Message struct {
Base
Title string
Text string
Danger bool
}
// NewMessage creates a message model
func NewMessage(user *auth.User, title string, danger bool, text string) *Message {
msg := &Message{Title: title, Text: text, Danger: danger}
msg.setupBase(user, title, "")
return msg
}
+9
View File
@@ -0,0 +1,9 @@
package viewmodel
import "git.aiterp.net/AiteRP/aitestory/model"
// PageBase describes the basic parts of a page.
type PageBase struct {
Page *model.Page
HideMenu bool
}
+26
View File
@@ -0,0 +1,26 @@
package viewmodel
import (
"git.aiterp.net/AiteRP/aitestory/model"
"git.aiterp.net/gisle/wrouter/auth"
)
// PageCreate is the view model for the page create form.
type PageCreate struct {
Base
IndexBase
Page model.Page
Error string
TagInput string
}
// Setup sets the view model up.
func (pf *PageCreate) Setup(user *auth.User) {
pf.setupMenu()
pf.setupBase(user, "Create", "/page/create")
pf.Categories = model.PageCategories
pf.Page.Defaults()
}
+19
View File
@@ -0,0 +1,19 @@
package viewmodel
import (
"fmt"
"git.aiterp.net/gisle/wrouter/auth"
)
// PageDelete is the view model used to view the page's delete form.
type PageDelete struct {
Base
PageBase
}
// Setup sets up the page view model. It should be calles last
func (pv *PageDelete) Setup(user *auth.User) {
pv.HideMenu = false
pv.setupBase(user, pv.Page.Name, fmt.Sprintf("/page/delete/%s", pv.Page.ID))
}
@@ -5,17 +5,19 @@ import (
"git.aiterp.net/gisle/wrouter/auth"
)
type PageForm struct {
// PageEdit is the view model for the page edit form.
type PageEdit struct {
Base
Page model.Page
PageBase
Categories []model.PageCategory
Operation string
Error string
TagInput string
}
func (pf *PageForm) Setup(user *auth.User) {
pf.setupBase(user, "Create")
// Setup sets the view model up.
func (pf *PageEdit) Setup(user *auth.User) {
pf.setupBase(user, "Edit", "/page/edit/"+pf.Page.ID)
pf.Categories = model.PageCategories
pf.Page.Defaults()
}
+20
View File
@@ -0,0 +1,20 @@
package viewmodel
import (
"fmt"
"git.aiterp.net/gisle/wrouter/auth"
)
// PageSource is the view model used to view the page's source.
// It's got no extra data on its own.
type PageSource struct {
Base
PageBase
}
// Setup sets up the page view model. It should be calles last
func (pv *PageSource) Setup(user *auth.User) {
pv.HideMenu = false
pv.setupBase(user, pv.Page.Name, fmt.Sprintf("/page/source/%s", pv.Page.ID))
}
+8 -3
View File
@@ -1,15 +1,20 @@
package viewmodel
import (
"git.aiterp.net/AiteRP/aitestory/model"
"fmt"
"git.aiterp.net/gisle/wrouter/auth"
)
// PageView is the view model used to view the page. It's got no extra
// data on its own.
type PageView struct {
Base
Page *model.Page
PageBase
}
// Setup sets up the page view model. It should be calles last
func (pv *PageView) Setup(user *auth.User) {
pv.setupBase(user, pv.Page.Name)
pv.HideMenu = false
pv.setupBase(user, pv.Page.Name, fmt.Sprintf("/page/%s", pv.Page.ID))
}
-46
View File
@@ -1,46 +0,0 @@
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))
}
+1 -1
View File
@@ -15,5 +15,5 @@ type UserLogin struct {
// Setup sets up the page model and the base, and should
// be run after the details have been filled in.
func (ul *UserLogin) Setup(user *auth.User) {
ul.setupBase(user, "Login")
ul.setupBase(user, "Login", "/user/login")
}