Fix level bar UI.

Reduce boilerplate.
This commit is contained in:
Azareal 2021-07-28 17:43:38 +10:00
parent 0cffbbb3cd
commit 0ff56af36f
12 changed files with 60 additions and 39 deletions

View File

@ -32,9 +32,10 @@ type DefaultActivityStream struct {
func NewDefaultActivityStream(acc *qgen.Accumulator) (*DefaultActivityStream, error) {
as := "activity_stream"
cols := "actor,targetUser,event,elementType,elementID,createdAt,extra"
return &DefaultActivityStream{
add: acc.Insert(as).Columns("actor,targetUser,event,elementType,elementID,createdAt,extra").Fields("?,?,?,?,?,UTC_TIMESTAMP(),?").Prepare(),
get: acc.Select(as).Columns("actor,targetUser,event,elementType,elementID,createdAt,extra").Where("asid=?").Prepare(),
add: acc.Insert(as).Columns(cols).Fields("?,?,?,?,?,UTC_TIMESTAMP(),?").Prepare(),
get: acc.Select(as).Columns(cols).Where("asid=?").Prepare(),
delete: acc.Delete(as).Where("asid=?").Prepare(),
deleteByParams: acc.Delete(as).Where("event=? AND elementID=? AND elementType=?").Prepare(),
deleteByParamsExtra: acc.Delete(as).Where("event=? AND elementID=? AND elementType=? AND extra=?").Prepare(),

View File

@ -179,9 +179,9 @@ func (s *DefaultAttachmentStore) BulkMiniGetList(originTable string, ids []int)
func (s *DefaultAttachmentStore) FGet(id int) (*Attachment, error) {
a := &Attachment{ID: id}
err := s.fget.QueryRow(id).Scan(&a.OriginTable, &a.OriginID, &a.SectionTable, &a.SectionID, &a.UploadedBy, &a.Path, &a.Extra)
if err != nil {
return nil, err
e := s.fget.QueryRow(id).Scan(&a.OriginTable, &a.OriginID, &a.SectionTable, &a.SectionID, &a.UploadedBy, &a.Path, &a.Extra)
if e != nil {
return nil, e
}
a.Ext = strings.TrimPrefix(filepath.Ext(a.Path), ".")
if len(a.Ext) == 0 {

View File

@ -61,7 +61,7 @@ func (g *Group) ChangeRank(isAdmin, isMod, isBanned bool) (err error) {
if err != nil {
return err
}
Groups.Reload(g.ID)
_ = Groups.Reload(g.ID)
return nil
}
@ -70,7 +70,7 @@ func (g *Group) Update(name, tag string) (err error) {
if err != nil {
return err
}
Groups.Reload(g.ID)
_ = Groups.Reload(g.ID)
return nil
}

View File

@ -405,11 +405,14 @@ func AccountEdit(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header)
// Normalise the score so that the user sees their relative progress to the next level rather than showing them their total score
prevScore := c.GetLevelScore(u.Level)
currentScore := u.Score - prevScore
score := u.Score
//score = 23
currentScore := score - prevScore
nextScore := c.GetLevelScore(u.Level+1) - prevScore
perc := int(math.Ceil((float64(nextScore) / float64(currentScore)) * 100))
//perc := int(math.Ceil((float64(nextScore) / float64(currentScore)) * 100)) * 2
perc := int(math.Floor((float64(currentScore) / float64(nextScore)) * 100)) // * 2
pi := c.Account{h, "dashboard", "account_own_edit", c.AccountDashPage{h, mfaSetup, currentScore, nextScore, u.Level + 1, perc * 2}}
pi := c.Account{h, "dashboard", "account_own_edit", c.AccountDashPage{h, mfaSetup, currentScore, nextScore, u.Level + 1, perc}}
return renderTemplate("account", w, r, h, pi)
}
@ -833,20 +836,24 @@ func AccountBlocked(w http.ResponseWriter, r *http.Request, user *c.User, h *c.H
func LevelList(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c.RouteError {
h.Title = p.GetTitlePhrase("account_level_list")
fScores := c.GetLevels(20)
fScores := c.GetLevels(21)
levels := make([]c.LevelListItem, len(fScores))
for i, fScore := range fScores {
if i == 0 {
continue
}
var status string
if u.Level > i {
if u.Level > (i - 1) {
status = "complete"
} else if u.Level < i {
} else if u.Level < (i - 1) {
status = "future"
} else {
status = "inprogress"
}
iScore := int(math.Ceil(fScore))
perc := int(math.Ceil((fScore / float64(u.Score)) * 100))
levels[i] = c.LevelListItem{i, iScore, status, perc * 2}
//perc := int(math.Ceil((fScore/float64(u.Score))*100)) * 2
perc := int(math.Ceil((float64(u.Score) / fScore) * 100))
levels[i] = c.LevelListItem{i - 1, iScore, status, perc}
}
return renderTemplate("level_list", w, r, h, c.LevelListPage{h, levels[1:]})

View File

@ -118,14 +118,14 @@ func PagesEditSubmit(w http.ResponseWriter, r *http.Request, u *c.User, spid str
return c.LocalError("No body was provided for this page", w, r, u)
}
page, err := c.Pages.Get(pid)
p, err := c.Pages.Get(pid)
if err != nil {
return c.NotFound(w, r, nil)
}
page.Name = name
page.Title = title
page.Body = body
err = page.Commit()
p.Name = name
p.Title = title
p.Body = body
err = p.Commit()
if err != nil {
return c.InternalError(err, w, r)
}

View File

@ -2,6 +2,7 @@ package routes
import (
"database/sql"
"math"
"net/http"
"time"
@ -97,8 +98,11 @@ func ViewProfile(w http.ResponseWriter, r *http.Request, user *c.User, h *c.Head
// Normalise the score so that the user sees their relative progress to the next level rather than showing them their total score
prevScore := c.GetLevelScore(puser.Level)
currentScore := puser.Score - prevScore
score := puser.Score
//score = 23
currentScore := score - prevScore
nextScore := c.GetLevelScore(puser.Level+1) - prevScore
perc := int(math.Floor((float64(currentScore) / float64(nextScore)) * 100))
var blocked, blockedInv bool
if user.Loggedin {
blocked, err = c.UserBlocks.IsBlockedBy(user.ID, puser.ID)
@ -121,6 +125,6 @@ func ViewProfile(w http.ResponseWriter, r *http.Request, user *c.User, h *c.Head
canMessage = false
}
ppage := c.ProfilePage{h, reList, *puser, currentScore, nextScore, blocked, canMessage, canComment, showComments}
ppage := c.ProfilePage{h, reList, *puser, currentScore, nextScore, perc, blocked, canMessage, canComment, showComments}
return renderTemplate("profile", w, r, h, ppage)
}

View File

@ -20,13 +20,6 @@
</div>
<div id="dash_right" class="coldyn_item">
<div class="rowitem">{{if not .MFASetup}}<a href="/user/edit/mfa/setup/">{{lang "account_dash_2fa_setup"}}</a>{{else}}<a href="/user/edit/mfa/">{{lang "account_dash_2fa_manage"}}</a>{{end}} <span class="dash_security">{{lang "account_dash_security_notice"}}</span></div>
<div class="rowitem level_inprogress">
<div class="levelBit">
<a href="/user/levels/">{{level .CurrentUser.Level}}</a>
</div>
<div class="progressWrap" style="width:{{.Percentage}}%;">
<div>{{.CurrentScore}} / {{.NextScore}}</div>
</div>
</div>
{{template "account_own_edit_level.html" .}}
</div>
</div>

View File

@ -0,0 +1,8 @@
<div class="rowitem level_inprogress">
<div class="levelBit"{{if ne .CurrentScore 0}}style="width:{{.Percentage}}%;"{{end}}>
<a href="/user/levels/">{{level .CurrentUser.Level}}</a>
</div>
<div class="progressWrap"{{/**{{if ne .CurrentScore 0}}style="width:{{.Percentage}}%;"{{end}}**/}}>
<div>{{.CurrentScore}} / {{.NextScore}}</div>
</div>
</div>

View File

@ -6,9 +6,9 @@
{{range .Levels}}
<div class="rowblock">
<div class="rowitem passive rowmsg level_{{.Status}}">
<div class="levelBit">{{level .Level}}</div>
<div class="progressWrap"{{if eq .Status "inprogress"}}style="width:{{.Percentage}}%;"{{end}}>
<div>Score: {{.Score}}</div>
<div class="levelBit"{{if eq .Status "inprogress"}}style="width:{{.Percentage}}%;"{{end}}>{{level .Level}}</div>
<div class="progressWrap"{{/**{{if eq .Status "inprogress"}}style="width:{{.Percentage}}%;"{{end}}**/}}>
<div>{{if eq .Status "inprogress"}}{{$.CurrentUser.Score}} / {{.Score}}{{else if eq .Status "complete"}}{{.Score}} / {{.Score}}{{else}}Next: {{.Score}}{{end}}</div>
</div>
</div>
</div>

View File

@ -14,10 +14,10 @@
<div class="levelBlock">
<div class="rowitem passive">
<div class="profile_menu_item level_inprogress">
<div class="levelBit">
<div class="levelBit"{{if ne .CurrentScore 0}}style="width:{{.Percentage}}%"{{end}}>
<a>{{level .ProfileOwner.Level}}</a>
</div>
<div class="progressWrap"{{if ne .CurrentScore 0}}style="width:40%"{{end}}>
<div class="progressWrap"{{/**{{if ne .CurrentScore 0}}style="width:40%"{{end}}**/}}>
<div>{{.CurrentScore}} / {{.NextScore}}</div>
</div>
</div>

View File

@ -1220,6 +1220,9 @@ input[type=checkbox]:not(:checked):hover + label .sel {
.level_complete, .level_future, .level_inprogress, .progressWrap {
display: flex;
}
.level_inprogress {
position: relative;
}
.level_complete {
background-color: rgb(68, 93, 68) !important;
width: 100%;
@ -1245,20 +1248,25 @@ input[type=checkbox]:not(:checked):hover + label .sel {
padding-bottom: 12px;
padding-left: 12px;
border-radius: 3px;
width: 100%;
/*width: 100%;*/
}
.level_inprogress:not(.level_zero) .levelBit {
background-color: rgb(68, 93, 68) !important;
}
.level_inprogress .levelBit {
display: inline;
position: absolute;
z-index: 1;
}
.level_inprogress .levelBit a {
white-space: nowrap;
}
.level_inprogress .progressWrap {
width: 100%;
/*width: 100%;*/
padding-left: 0px;
padding-right: 12px;
background-color: rgb(68, 68, 68) !important;
/*background-color: rgb(68, 68, 68) !important;*/
z-index: 2;
}
.level_inprogress .progressWrap div {
margin-left: auto;