most viewed now works on dynamically loaded topic lists
show opts on empty forums
This commit is contained in:
parent
c6d18e5c18
commit
e47c531e5a
|
@ -201,6 +201,7 @@ type TopicListPage struct {
|
|||
ForumList []Forum
|
||||
DefaultForum int
|
||||
Sort TopicListSort
|
||||
SelectedFids []int
|
||||
QuickTools
|
||||
Paginator
|
||||
}
|
||||
|
@ -799,8 +800,8 @@ type AreYouSure struct {
|
|||
}
|
||||
|
||||
// TODO: Write a test for this
|
||||
func DefaultHeader(w http.ResponseWriter, user *User) *Header {
|
||||
return &Header{Site: Site, Theme: Themes[fallbackTheme], CurrentUser: user, Writer: w}
|
||||
func DefaultHeader(w http.ResponseWriter, u *User) *Header {
|
||||
return &Header{Site: Site, Theme: Themes[fallbackTheme], CurrentUser: u, Writer: w}
|
||||
}
|
||||
func SimpleDefaultHeader(w http.ResponseWriter) *Header {
|
||||
return &Header{Site: Site, Theme: Themes[fallbackTheme], CurrentUser: &GuestUser, Writer: w}
|
||||
|
|
|
@ -229,7 +229,7 @@ func compileCommons(c *tmpl.CTemplateSet, head, head2 *Header, forumList []Forum
|
|||
var topicsList []TopicsRowMut
|
||||
topic := Topic{1, "/topic/topic-title.1", "Topic Title", "The topic content.", 1, false, false, now, now, user3.ID, 1, 1, "", "::1", 1, 0, 1, 1, "classname", 0, "", nil}
|
||||
topicsList = append(topicsList, TopicsRowMut{&TopicsRow{topic, 1, user2, "", 0, user3, "General", "/forum/general.2"}, false})
|
||||
topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, QuickTools{false, false, false}, Paginator{[]int{1}, 1, 1}}
|
||||
topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, []int{1}, QuickTools{false, false, false}, Paginator{[]int{1}, 1, 1}}
|
||||
o.Add("topics", "c.TopicListPage", topicListPage)
|
||||
o.Add("topics_mini", "c.TopicListPage", topicListPage)
|
||||
|
||||
|
@ -313,7 +313,7 @@ func compileTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName string
|
|||
var topicsList []TopicsRowMut
|
||||
topic := Topic{1, "topic-title", "Topic Title", "The topic content.", 1, false, false, now, now, user3.ID, 1, 1, "", "::1", 1, 0, 1, 1, "classname", 0, "", nil}
|
||||
topicsList = append(topicsList, TopicsRowMut{&TopicsRow{topic, 0, user2, "", 0, user3, "General", "/forum/general.2"}, false})
|
||||
topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, QuickTools{false, false, false}, Paginator{[]int{1}, 1, 1}}
|
||||
topicListPage := TopicListPage{htitle("Topic List"), topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, []int{1}, QuickTools{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, false, false, Paginator{[]int{1}, 1, 1}}
|
||||
|
|
|
@ -389,7 +389,7 @@ func (tList *DefaultTopicList) GetListByCanSee(canSee []int, page, orderby int,
|
|||
// ? - Would it be useful, if we could post in social groups from /topics/?
|
||||
for _, fid := range canSee {
|
||||
f := Forums.DirtyGet(fid)
|
||||
if f.Name != "" && f.Active && (f.ParentType == "" || f.ParentType == "forum") && f.TopicCount != 0 {
|
||||
if f.Name != "" && f.Active && (f.ParentType == "" || f.ParentType == "forum") /*&& f.TopicCount != 0*/ {
|
||||
fcopy := f.Copy()
|
||||
// TODO: Add a hook here for plugin_guilds !!
|
||||
forumList = append(forumList, fcopy)
|
||||
|
@ -397,8 +397,8 @@ func (tList *DefaultTopicList) GetListByCanSee(canSee []int, page, orderby int,
|
|||
}
|
||||
|
||||
inSlice := func(haystack []int, needle int) bool {
|
||||
for _, item := range haystack {
|
||||
if needle == item {
|
||||
for _, it := range haystack {
|
||||
if needle == it {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -443,10 +443,10 @@ func (tList *DefaultTopicList) GetList(page, orderby int, filterIDs []int) (topi
|
|||
if err != nil {
|
||||
return nil, nil, Paginator{nil, 1, 1}, err
|
||||
}
|
||||
|
||||
//log.Printf("cCanSee: %+v\n", cCanSee)
|
||||
inSlice := func(haystack []int, needle int) bool {
|
||||
for _, item := range haystack {
|
||||
if needle == item {
|
||||
for _, it := range haystack {
|
||||
if needle == it {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -463,13 +463,14 @@ func (tList *DefaultTopicList) GetList(page, orderby int, filterIDs []int) (topi
|
|||
} else {
|
||||
canSee = cCanSee
|
||||
}
|
||||
//log.Printf("canSee: %+v\n", canSee)
|
||||
|
||||
// We need a list of the visible forums for Quick Topic
|
||||
// ? - Would it be useful, if we could post in social groups from /topics/?
|
||||
var topicCount int
|
||||
for _, fid := range canSee {
|
||||
f := Forums.DirtyGet(fid)
|
||||
if f.Name != "" && f.Active && (f.ParentType == "" || f.ParentType == "forum") && f.TopicCount != 0 {
|
||||
if f.Name != "" && f.Active && (f.ParentType == "" || f.ParentType == "forum") /*&& f.TopicCount != 0*/ {
|
||||
fcopy := f.Copy()
|
||||
// TODO: Add a hook here for plugin_guilds
|
||||
forumList = append(forumList, fcopy)
|
||||
|
@ -495,6 +496,9 @@ func (tList *DefaultTopicList) GetList(page, orderby int, filterIDs []int) (topi
|
|||
// TODO: Rename this to TopicListStore and pass back a TopicList instance holding the pagination data and topic list rather than passing them back one argument at a time
|
||||
// TODO: Make orderby an enum of sorts
|
||||
func (tList *DefaultTopicList) getList(page, orderby, topicCount int, argList []interface{}, qlist string) (topicList []*TopicsRow, paginator Paginator, err error) {
|
||||
if topicCount == 0 {
|
||||
return nil, Paginator{nil, 1, 1}, err
|
||||
}
|
||||
//log.Printf("argList: %+v\n",argList)
|
||||
//log.Printf("qlist: %+v\n",qlist)
|
||||
var orderq string
|
||||
|
|
|
@ -554,12 +554,12 @@ function mainInit(){
|
|||
|
||||
// TODO: Try to de-duplicate some of these fetch calls
|
||||
fetch(url+q+"&js=1",{credentials:"same-origin"})
|
||||
.then(resp => {
|
||||
if(!resp.ok) throw(url+q+"&js=1 failed to load");
|
||||
return resp.json();
|
||||
}).then(dat => {
|
||||
if(!"Topics" in dat) throw("no Topics in data");
|
||||
let topics = dat["Topics"];
|
||||
.then(r => {
|
||||
if(!r.ok) throw(url+q+"&js=1 failed to load");
|
||||
return r.json();
|
||||
}).then(d => {
|
||||
if(!"Topics" in d) throw("no Topics in data");
|
||||
let topics = d["Topics"];
|
||||
log("ajax navigated to different page");
|
||||
|
||||
// TODO: Fix the data race where the function hasn't been loaded yet
|
||||
|
@ -569,10 +569,10 @@ function mainInit(){
|
|||
|
||||
let obj = {Title:document.title,Url:url+q};
|
||||
history.pushState(obj,obj.Title,obj.Url);
|
||||
rebuildPaginator(dat.LastPage);
|
||||
rebuildPaginator(d.LastPage);
|
||||
rebindPaginator();
|
||||
}).catch(e => {
|
||||
log("Unable to get script '"+url+q+"&js=1"+"'",e);
|
||||
log("Unable to get script "+url+q+"&js=1",e);
|
||||
console.trace();
|
||||
});
|
||||
});
|
||||
|
@ -588,13 +588,13 @@ function mainInit(){
|
|||
let url = "//"+window.location.host+"/topics/?fids="+fid;
|
||||
|
||||
fetch(url+"&js=1",{credentials:"same-origin"})
|
||||
.then(resp => {
|
||||
if(!resp.ok) throw(url+"&js=1 failed to load");
|
||||
return resp.json();
|
||||
}).then(dat => {
|
||||
log("data",dat);
|
||||
if(!"Topics" in dat) throw("no Topics in data");
|
||||
let topics = dat["Topics"];
|
||||
.then(r => {
|
||||
if(!r.ok) throw(url+"&js=1 failed to load");
|
||||
return r.json();
|
||||
}).then(d => {
|
||||
log("data",d);
|
||||
if(!"Topics" in d) throw("no Topics in data");
|
||||
let topics = d["Topics"];
|
||||
log("ajax navigated to "+that.innerText);
|
||||
|
||||
// TODO: Fix the data race where the function hasn't been loaded yet
|
||||
|
@ -608,7 +608,7 @@ function mainInit(){
|
|||
else document.title = baseTitle;
|
||||
let obj = {Title:document.title,Url:url};
|
||||
history.pushState(obj,obj.Title,obj.Url);
|
||||
rebuildPaginator(dat.LastPage)
|
||||
rebuildPaginator(d.LastPage)
|
||||
rebindPaginator();
|
||||
|
||||
$(".filter_item").each(function(){
|
||||
|
@ -616,10 +616,12 @@ function mainInit(){
|
|||
});
|
||||
that.classList.add("filter_selected");
|
||||
$(".topic_list_title h1").text(that.innerText);
|
||||
$(".link_select .link_option .link_recent").attr("href","//"+window.location.host+"/topics/?fids="+fid);
|
||||
$(".link_select .link_option .link_most_viewed").attr("href","//"+window.location.host+"/topics/most-viewed/?fids="+fid);
|
||||
unbindPage();
|
||||
bindPage();
|
||||
}).catch(e => {
|
||||
log("Unable to get script '"+url+"&js=1"+"'",e);
|
||||
log("Unable to get script "+url+"&js=1",e);
|
||||
console.trace();
|
||||
});
|
||||
});
|
||||
|
@ -642,12 +644,12 @@ function mainInit(){
|
|||
|
||||
// TODO: Try to de-duplicate some of these fetch calls
|
||||
fetch(url+q+"&js=1",{credentials:"same-origin"})
|
||||
.then(resp => {
|
||||
if(!resp.ok) throw(url+q+"&js=1 failed to load");
|
||||
return resp.json();
|
||||
}).then(data => {
|
||||
if(!"Topics" in data) throw("no Topics in data");
|
||||
let topics = data["Topics"];
|
||||
.then(r => {
|
||||
if(!r.ok) throw(url+q+"&js=1 failed to load");
|
||||
return r.json();
|
||||
}).then(d => {
|
||||
if(!"Topics" in d) throw("no Topics in data");
|
||||
let topics = d["Topics"];
|
||||
log("ajax navigated to search page");
|
||||
|
||||
// TODO: Fix the data race where the function hasn't been loaded yet
|
||||
|
@ -661,10 +663,10 @@ function mainInit(){
|
|||
else document.title = baseTitle;
|
||||
let obj = {Title: document.title, Url: url+q};
|
||||
history.pushState(obj,obj.Title,obj.Url);
|
||||
rebuildPaginator(data.LastPage);
|
||||
rebuildPaginator(d.LastPage);
|
||||
rebindPaginator();
|
||||
}).catch(e => {
|
||||
log("Unable to get script '"+url+q+"&js=1"+"'",e);
|
||||
log("Unable to get script "+url+q+"&js=1",e);
|
||||
console.trace();
|
||||
});
|
||||
});
|
||||
|
@ -906,14 +908,14 @@ function mainInit(){
|
|||
}
|
||||
}
|
||||
return resp.text();
|
||||
}).then(dat => {
|
||||
document.querySelector("#back").outerHTML = dat;
|
||||
if(h!==null) h(dat);
|
||||
}).then(d => {
|
||||
document.querySelector("#back").outerHTML = d;
|
||||
if(h!==null) h(d);
|
||||
$(".elapsed").remove();
|
||||
let obj = {Title:document.title,Url:base};
|
||||
history.pushState(obj,obj.Title,obj.Url);
|
||||
}).catch(e => {
|
||||
log("Unable to get script '"+href+""+"'",e);
|
||||
log("Unable to get script "+href,e);
|
||||
console.trace();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -239,7 +239,8 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c.
|
|||
}
|
||||
|
||||
h.Title = phrases.GetTitlePhrase("topics_search")
|
||||
pi := c.TopicListPage{h, topicList2, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, c.QuickTools{canDelete, canLock, canMove}, pagi}
|
||||
//log.Printf("cfids: %+v\n", cfids)
|
||||
pi := c.TopicListPage{h, topicList2, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, cfids, c.QuickTools{canDelete, canLock, canMove}, pagi}
|
||||
return renderTemplate("topics", w, r, h, pi)
|
||||
}
|
||||
|
||||
|
@ -305,7 +306,7 @@ func TopicListCommon(w http.ResponseWriter, r *http.Request, user *c.User, h *c.
|
|||
topicList2[i] = c.TopicsRowMut{t, canMod}
|
||||
}
|
||||
|
||||
pi := c.TopicListPage{h, topicList2, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, c.QuickTools{canDelete, canLock, canMove}, pagi}
|
||||
pi := c.TopicListPage{h, topicList2, forumList, c.Config.DefaultForum, c.TopicListSort{torder, false}, fids, c.QuickTools{canDelete, canLock, canMove}, pagi}
|
||||
if r.FormValue("i") == "1" {
|
||||
return renderTemplate("topics_mini", w, r, h, pi)
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
<a href="#"class="filter_opt_label link_label"data-for="topic_list_filter_select">{{if eq .Sort.SortBy "mostviewed"}}{{lang "topic_list.most_viewed_filter"}}{{else}}{{lang "topic_list.most_recent_filter"}}{{end}} <span class="filter_opt_pointy">▾</span></a>
|
||||
<div id="topic_list_filter_select"class="link_select">
|
||||
<div class="link_option link_selected">
|
||||
<a href="/topics/">{{lang "topic_list.most_recent_filter"}}</a>
|
||||
<a class="link_recent"href="/topics/{{if .SelectedFids}}?fids={{range .SelectedFids}}{{.}}{{end}}{{end}}">{{lang "topic_list.most_recent_filter"}}</a>
|
||||
</div>
|
||||
<div class="link_option">
|
||||
<a href="/topics/most-viewed/">{{lang "topic_list.most_viewed_filter"}}</a>
|
||||
<a class="link_most_viewed"href="/topics/most-viewed/{{if .SelectedFids}}?fids={{range .SelectedFids}}{{.}}{{end}}{{end}}">{{lang "topic_list.most_viewed_filter"}}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue