update .link_most_viewed properly on page transitions

reduce variable lengths
remove redundant thaw
This commit is contained in:
Azareal 2020-12-18 11:04:07 +10:00
parent fbcbfd9e96
commit 43bace814d
5 changed files with 23 additions and 22 deletions

View File

@ -17,7 +17,7 @@ var ErrAlreadyReported = errors.New("This item has already been reported")
// The report system mostly wraps around the topic system for simplicty
type ReportStore interface {
Create(title, content string, user *User, itemType string, itemID int) (int, error)
Create(title, content string, u *User, itemType string, itemID int) (int, error)
}
type DefaultReportStore struct {

View File

@ -240,7 +240,7 @@ func (s *DefaultTopicStore) Create(fid int, name, content string, uid int, ip st
return 0, err
}
tid = int(lastID)
TopicListThaw.Thaw()
//TopicListThaw.Thaw() // redundant
return tid, Forums.AddTopic(tid, uid, fid)
}

View File

@ -665,6 +665,8 @@ function mainInit(){
history.pushState(obj,obj.Title,obj.Url);
rebuildPaginator(d.LastPage);
rebindPaginator();
$(".link_select .link_option .link_recent").attr("href",url+q);
$(".link_select .link_option .link_most_viewed").attr("href",url+q);
}).catch(e => {
log("Unable to get script "+url+q+"&js=1",e);
console.trace();

View File

@ -4,7 +4,7 @@ import (
"net/http"
c "github.com/Azareal/Gosora/common"
"github.com/Azareal/Gosora/common/phrases"
p "github.com/Azareal/Gosora/common/phrases"
)
// A blank list to fill out that parameter in Page for routes which don't use it
@ -43,12 +43,12 @@ func renderTemplate(tmplName string, w http.ResponseWriter, r *http.Request, h *
return nil
}
func buildBasePage(w http.ResponseWriter, r *http.Request, user *c.User, titlePhrase, zone string) (*c.BasePanelPage, c.RouteError) {
header, stats, ferr := c.PanelUserCheck(w, r, user)
func buildBasePage(w http.ResponseWriter, r *http.Request, u *c.User, titlePhrase, zone string) (*c.BasePanelPage, c.RouteError) {
h, stats, ferr := c.PanelUserCheck(w, r, u)
if ferr != nil {
return nil, ferr
}
header.Title = phrases.GetTitlePhrase("panel_" + titlePhrase)
h.Title = p.GetTitlePhrase("panel_" + titlePhrase)
return &c.BasePanelPage{header, stats, zone, c.ReportForumID}, nil
return &c.BasePanelPage{h, stats, zone, c.ReportForumID}, nil
}

View File

@ -10,7 +10,7 @@ import (
qgen "github.com/Azareal/Gosora/query_gen"
)
func PollVote(w http.ResponseWriter, r *http.Request, user *c.User, sPollID string) c.RouteError {
func PollVote(w http.ResponseWriter, r *http.Request, u *c.User, sPollID string) c.RouteError {
pollID, err := strconv.Atoi(sPollID)
if err != nil {
return c.PreError("The provided PollID is not a valid number.", w, r)
@ -44,19 +44,19 @@ func PollVote(w http.ResponseWriter, r *http.Request, user *c.User, sPollID stri
}
// TODO: Add hooks to make use of headerLite
_, ferr := c.SimpleForumUserCheck(w, r, user, topic.ParentID)
_, ferr := c.SimpleForumUserCheck(w, r, u, topic.ParentID)
if ferr != nil {
return ferr
}
if !user.Perms.ViewTopic {
return c.NoPermissions(w, r, user)
if !u.Perms.ViewTopic {
return c.NoPermissions(w, r, u)
}
optionIndex, err := strconv.Atoi(r.PostFormValue("poll_option_input"))
optIndex, err := strconv.Atoi(r.PostFormValue("poll_option_input"))
if err != nil {
return c.LocalError("Malformed input", w, r, user)
return c.LocalError("Malformed input", w, r, u)
}
err = poll.CastVote(optionIndex, user.ID, user.GetIP())
err = poll.CastVote(optIndex, u.ID, u.GetIP())
if err != nil {
return c.InternalError(err, w, r)
}
@ -65,7 +65,7 @@ func PollVote(w http.ResponseWriter, r *http.Request, user *c.User, sPollID stri
return nil
}
func PollResults(w http.ResponseWriter, r *http.Request, user *c.User, sPollID string) c.RouteError {
func PollResults(w http.ResponseWriter, r *http.Request, u *c.User, sPollID string) c.RouteError {
//log.Print("in PollResults")
pollID, err := strconv.Atoi(sPollID)
if err != nil {
@ -85,24 +85,23 @@ func PollResults(w http.ResponseWriter, r *http.Request, user *c.User, sPollID s
}
defer rows.Close()
optionList := ""
optList := ""
var votes int
for rows.Next() {
err := rows.Scan(&votes)
if err != nil {
return c.InternalError(err, w, r)
}
optionList += strconv.Itoa(votes) + ","
optList += strconv.Itoa(votes) + ","
}
err = rows.Err()
if err != nil {
if err = rows.Err(); err != nil {
return c.InternalError(err, w, r)
}
// TODO: Implement a version of this which doesn't rely so much on sequential order
if len(optionList) > 0 {
optionList = optionList[:len(optionList)-1]
if len(optList) > 0 {
optList = optList[:len(optList)-1]
}
w.Write([]byte("[" + optionList + "]"))
w.Write([]byte("[" + optList + "]"))
return nil
}