hide modtool options we don't have access to on forum and topics pages
use hookgen for route_topic_list_start hook add route_topic_list_mostviewed_start hook
This commit is contained in:
parent
32bd1a5e28
commit
96b61078c5
|
@ -208,6 +208,8 @@ type TopicListPage struct {
|
|||
ForumList []Forum
|
||||
DefaultForum int
|
||||
Sort TopicListSort
|
||||
CanLock bool
|
||||
CanMove bool
|
||||
Paginator
|
||||
}
|
||||
|
||||
|
@ -215,6 +217,8 @@ type ForumPage struct {
|
|||
*Header
|
||||
ItemList []*TopicsRow
|
||||
Forum *Forum
|
||||
CanLock bool
|
||||
CanMove bool
|
||||
Paginator
|
||||
}
|
||||
|
||||
|
|
|
@ -228,12 +228,12 @@ func compileCommons(c *tmpl.CTemplateSet, head, head2 *Header, forumList []Forum
|
|||
|
||||
var topicsList []*TopicsRow
|
||||
topicsList = append(topicsList, &TopicsRow{1, "topic-title", "Topic Title", "The topic content.", 1, false, false, now, now, user3.ID, 1, 1, "", "::1", 1, 0, 1, 1, 0, "classname", 0, "", user2, "", 0, user3, "General", "/forum/general.2", nil})
|
||||
topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, Paginator{[]int{1}, 1, 1}}
|
||||
topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, false, false, Paginator{[]int{1}, 1, 1}}
|
||||
o.Add("topics", "c.TopicListPage", topicListPage)
|
||||
o.Add("topics_mini", "c.TopicListPage", topicListPage)
|
||||
|
||||
forumItem := BlankForum(1, "general-forum.1", "General Forum", "Where the general stuff happens", true, "all", 0, "", 0)
|
||||
forumPage := ForumPage{htitle("General Forum"), topicsList, forumItem, Paginator{[]int{1}, 1, 1}}
|
||||
forumPage := ForumPage{htitle("General Forum"), topicsList, forumItem, false, false, Paginator{[]int{1}, 1, 1}}
|
||||
o.Add("forum", "c.ForumPage", forumPage)
|
||||
o.Add("forums", "c.ForumsPage", ForumsPage{htitle("Forum List"), forumList})
|
||||
|
||||
|
@ -311,10 +311,10 @@ func compileTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName string
|
|||
|
||||
var topicsList []*TopicsRow
|
||||
topicsList = append(topicsList, &TopicsRow{1, "topic-title", "Topic Title", "The topic content.", 1, false, false, now, now, user3.ID, 1, 1, "", "127.0.0.1", 1, 0, 1, 1, 0, "classname", 0, "", user2, "", 0, user3, "General", "/forum/general.2", nil})
|
||||
topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, Paginator{[]int{1}, 1, 1}}
|
||||
topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, false, false, Paginator{[]int{1}, 1, 1}}
|
||||
|
||||
forumItem := BlankForum(1, "general-forum.1", "General Forum", "Where the general stuff happens", true, "all", 0, "", 0)
|
||||
forumPage := ForumPage{htitle("General Forum"), topicsList, forumItem, Paginator{[]int{1}, 1, 1}}
|
||||
forumPage := ForumPage{htitle("General Forum"), topicsList, forumItem, false, false, Paginator{[]int{1}, 1, 1}}
|
||||
|
||||
// Experimental!
|
||||
for _, tmpl := range strings.Split(Dev.ExtraTmpls, ",") {
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strconv"
|
||||
|
||||
c "github.com/Azareal/Gosora/common"
|
||||
"github.com/Azareal/Gosora/common/counters"
|
||||
co "github.com/Azareal/Gosora/common/counters"
|
||||
p "github.com/Azareal/Gosora/common/phrases"
|
||||
)
|
||||
|
||||
|
@ -55,7 +55,7 @@ func ViewForum(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header, s
|
|||
}
|
||||
|
||||
//pageList := c.Paginate(page, lastPage, 5)
|
||||
pi := c.ForumPage{h, topicList, forum, pagi}
|
||||
pi := c.ForumPage{h, topicList, forum, u.Perms.CloseTopic, u.Perms.MoveTopic, pagi}
|
||||
tmpl := forum.Tmpl
|
||||
if tmpl == "" {
|
||||
ferr = renderTemplate("forum", w, r, h, pi)
|
||||
|
@ -66,6 +66,6 @@ func ViewForum(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header, s
|
|||
ferr = renderTemplate("forum", w, r, h, pi)
|
||||
}
|
||||
}
|
||||
counters.ForumViewCounter.Bump(forum.ID)
|
||||
co.ForumViewCounter.Bump(forum.ID)
|
||||
return ferr
|
||||
}
|
||||
|
|
|
@ -20,7 +20,11 @@ func wsTopicList(topicList []*c.TopicsRow, lastPage int) *c.WsTopicList {
|
|||
}
|
||||
|
||||
func TopicList(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c.RouteError {
|
||||
skip, rerr := h.Hooks.VhookSkippable("route_topic_list_start", w, r, u, h)
|
||||
/*skip, rerr := h.Hooks.VhookSkippable("route_topic_list_start", w, r, u, h)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}*/
|
||||
skip, rerr := c.H_route_topic_list_start_hook(h.Hooks, w, r, u, h)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
|
@ -28,6 +32,10 @@ func TopicList(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c
|
|||
}
|
||||
|
||||
func TopicListMostViewed(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c.RouteError {
|
||||
skip, rerr := h.Hooks.VhookSkippable("route_topic_list_mostviewed_start", w, r, u, h)
|
||||
if skip || rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
return TopicListCommon(w, r, u, h, "mostviewed", c.TopicListMostViewed)
|
||||
}
|
||||
|
||||
|
@ -71,6 +79,7 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c.
|
|||
var topicList []*c.TopicsRow
|
||||
var forumList []c.Forum
|
||||
var pagi c.Paginator
|
||||
var canLock, ccanLock, canMove, ccanMove bool
|
||||
q := r.FormValue("q")
|
||||
if q != "" && c.RepliesSearch != nil {
|
||||
var canSee []int
|
||||
|
@ -117,6 +126,7 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c.
|
|||
if err != nil {
|
||||
return c.InternalError(err, w, r)
|
||||
}
|
||||
// TODO: Cache emptied map across requests with sync pool
|
||||
reqUserList := make(map[int]bool)
|
||||
for _, t := range tMap {
|
||||
reqUserList[t.CreatedBy] = true
|
||||
|
@ -141,16 +151,41 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c.
|
|||
}
|
||||
|
||||
// TODO: De-dupe this logic in common/topic_list.go?
|
||||
//var sb strings.Builder
|
||||
for _, t := range topicList {
|
||||
//c.BuildTopicURLSb(&sb, c.NameToSlug(t.Title), t.ID)
|
||||
//t.Link = sb.String()
|
||||
//sb.Reset()
|
||||
t.Link = c.BuildTopicURL(c.NameToSlug(t.Title), t.ID)
|
||||
// TODO: Pass forum to something like t.Forum and use that instead of these two properties? Could be more flexible.
|
||||
forum := c.Forums.DirtyGet(t.ParentID)
|
||||
t.ForumName = forum.Name
|
||||
t.ForumLink = forum.Link
|
||||
|
||||
fp, err := c.FPStore.Get(forum.ID, user.Group)
|
||||
if err == c.ErrNoRows {
|
||||
fp = c.BlankForumPerms()
|
||||
} else if err != nil {
|
||||
return c.InternalError(err, w, r)
|
||||
}
|
||||
if fp.Overrides && !user.IsSuperAdmin {
|
||||
ccanLock = fp.CloseTopic
|
||||
ccanMove = fp.MoveTopic
|
||||
} else {
|
||||
ccanLock = user.Perms.CloseTopic
|
||||
ccanMove = user.Perms.MoveTopic
|
||||
}
|
||||
if ccanLock {
|
||||
canLock = true
|
||||
}
|
||||
if ccanMove {
|
||||
canMove = true
|
||||
}
|
||||
|
||||
// TODO: Create a specialised function with a bit less overhead for getting the last page for a post count
|
||||
_, _, lastPage := c.PageOffset(t.PostCount, 1, c.Config.ItemsPerPage)
|
||||
t.LastPage = lastPage
|
||||
// TODO: Avoid map if either is equal to the current user
|
||||
t.Creator = userList[t.CreatedBy]
|
||||
t.LastUser = userList[t.LastReplyBy]
|
||||
}
|
||||
|
@ -166,15 +201,37 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c.
|
|||
}
|
||||
|
||||
h.Title = phrases.GetTitlePhrase("topics_search")
|
||||
pi := c.TopicListPage{h, topicList, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, pagi}
|
||||
pi := c.TopicListPage{h, topicList, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, canLock, canMove, pagi}
|
||||
return renderTemplate("topics", w, r, h, pi)
|
||||
}
|
||||
|
||||
// TODO: Pass a struct back rather than passing back so many variables
|
||||
if user.IsSuperAdmin {
|
||||
topicList, forumList, pagi, err = c.TopicList.GetList(page, tsorder, fids)
|
||||
canLock, canMove = true, true
|
||||
} else {
|
||||
topicList, forumList, pagi, err = c.TopicList.GetListByGroup(group, page, tsorder, fids)
|
||||
for _, forum := range forumList {
|
||||
fp, err := c.FPStore.Get(forum.ID, user.Group)
|
||||
if err == c.ErrNoRows {
|
||||
fp = c.BlankForumPerms()
|
||||
} else if err != nil {
|
||||
return c.InternalError(err, w, r)
|
||||
}
|
||||
if fp.Overrides {
|
||||
ccanLock = fp.CloseTopic
|
||||
ccanMove = fp.MoveTopic
|
||||
} else {
|
||||
ccanLock = user.Perms.CloseTopic
|
||||
ccanMove = user.Perms.MoveTopic
|
||||
}
|
||||
if ccanLock {
|
||||
canLock = true
|
||||
}
|
||||
if ccanMove {
|
||||
canMove = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return c.InternalError(err, w, r)
|
||||
|
@ -190,7 +247,7 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c.
|
|||
return nil
|
||||
}
|
||||
|
||||
pi := c.TopicListPage{h, topicList, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, pagi}
|
||||
pi := c.TopicListPage{h, topicList, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, canLock, canMove, pagi}
|
||||
if r.FormValue("i") == "1" {
|
||||
return renderTemplate("topics_mini", w, r, h, pi)
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
{{end}}
|
||||
</div>
|
||||
{{if .CurrentUser.Loggedin}}
|
||||
{{template "topics_mod_floater.html"}}
|
||||
{{template "topics_mod_floater.html" .}}
|
||||
|
||||
{{if .CurrentUser.Perms.CreateTopic}}
|
||||
<div id="forum_topic_create_form"class="rowblock topic_create_form quick_create_form auto_hide"aria-label="{{lang "quick_topic.aria"}}">
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
</div>
|
||||
|
||||
{{if .CurrentUser.Loggedin}}
|
||||
{{template "topics_mod_floater.html"}}
|
||||
{{template "topics_mod_floater.html" .}}
|
||||
|
||||
{{if .ForumList}}
|
||||
{{/** TODO: Have a seperate forum list for moving topics? Maybe an AJAX forum search compatible with plugin_guilds? **/}}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
<div class="mod_floater_body">
|
||||
<select class="mod_floater_options">
|
||||
<option value="delete">{{lang "topic_list.moderate_delete"}}</option>
|
||||
<option value="lock">{{lang "topic_list.moderate_lock"}}</option>
|
||||
<option value="move">{{lang "topic_list.moderate_move"}}</option>
|
||||
{{if .CanLock}}<option value="lock">{{lang "topic_list.moderate_lock"}}</option>{{end}}
|
||||
{{if .CanMove}}<option value="move">{{lang "topic_list.moderate_move"}}</option>{{end}}
|
||||
</select>
|
||||
<button class="mod_floater_submit">{{lang "topic_list.moderate_run"}}</button>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue