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) { func NewDefaultActivityStream(acc *qgen.Accumulator) (*DefaultActivityStream, error) {
as := "activity_stream" as := "activity_stream"
cols := "actor,targetUser,event,elementType,elementID,createdAt,extra"
return &DefaultActivityStream{ return &DefaultActivityStream{
add: acc.Insert(as).Columns("actor,targetUser,event,elementType,elementID,createdAt,extra").Fields("?,?,?,?,?,UTC_TIMESTAMP(),?").Prepare(), add: acc.Insert(as).Columns(cols).Fields("?,?,?,?,?,UTC_TIMESTAMP(),?").Prepare(),
get: acc.Select(as).Columns("actor,targetUser,event,elementType,elementID,createdAt,extra").Where("asid=?").Prepare(), get: acc.Select(as).Columns(cols).Where("asid=?").Prepare(),
delete: acc.Delete(as).Where("asid=?").Prepare(), delete: acc.Delete(as).Where("asid=?").Prepare(),
deleteByParams: acc.Delete(as).Where("event=? AND elementID=? AND elementType=?").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(), 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) { func (s *DefaultAttachmentStore) FGet(id int) (*Attachment, error) {
a := &Attachment{ID: id} a := &Attachment{ID: id}
err := s.fget.QueryRow(id).Scan(&a.OriginTable, &a.OriginID, &a.SectionTable, &a.SectionID, &a.UploadedBy, &a.Path, &a.Extra) e := s.fget.QueryRow(id).Scan(&a.OriginTable, &a.OriginID, &a.SectionTable, &a.SectionID, &a.UploadedBy, &a.Path, &a.Extra)
if err != nil { if e != nil {
return nil, err return nil, e
} }
a.Ext = strings.TrimPrefix(filepath.Ext(a.Path), ".") a.Ext = strings.TrimPrefix(filepath.Ext(a.Path), ".")
if len(a.Ext) == 0 { if len(a.Ext) == 0 {

View File

@ -61,7 +61,7 @@ func (g *Group) ChangeRank(isAdmin, isMod, isBanned bool) (err error) {
if err != nil { if err != nil {
return err return err
} }
Groups.Reload(g.ID) _ = Groups.Reload(g.ID)
return nil return nil
} }
@ -70,7 +70,7 @@ func (g *Group) Update(name, tag string) (err error) {
if err != nil { if err != nil {
return err return err
} }
Groups.Reload(g.ID) _ = Groups.Reload(g.ID)
return nil 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 // 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) prevScore := c.GetLevelScore(u.Level)
currentScore := u.Score - prevScore score := u.Score
//score = 23
currentScore := score - prevScore
nextScore := c.GetLevelScore(u.Level+1) - 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) 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 { func LevelList(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c.RouteError {
h.Title = p.GetTitlePhrase("account_level_list") h.Title = p.GetTitlePhrase("account_level_list")
fScores := c.GetLevels(20) fScores := c.GetLevels(21)
levels := make([]c.LevelListItem, len(fScores)) levels := make([]c.LevelListItem, len(fScores))
for i, fScore := range fScores { for i, fScore := range fScores {
if i == 0 {
continue
}
var status string var status string
if u.Level > i { if u.Level > (i - 1) {
status = "complete" status = "complete"
} else if u.Level < i { } else if u.Level < (i - 1) {
status = "future" status = "future"
} else { } else {
status = "inprogress" status = "inprogress"
} }
iScore := int(math.Ceil(fScore)) iScore := int(math.Ceil(fScore))
perc := int(math.Ceil((fScore / float64(u.Score)) * 100)) //perc := int(math.Ceil((fScore/float64(u.Score))*100)) * 2
levels[i] = c.LevelListItem{i, iScore, status, perc * 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:]}) 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) 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 { if err != nil {
return c.NotFound(w, r, nil) return c.NotFound(w, r, nil)
} }
page.Name = name p.Name = name
page.Title = title p.Title = title
page.Body = body p.Body = body
err = page.Commit() err = p.Commit()
if err != nil { if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }

View File

@ -2,6 +2,7 @@ package routes
import ( import (
"database/sql" "database/sql"
"math"
"net/http" "net/http"
"time" "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 // 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) prevScore := c.GetLevelScore(puser.Level)
currentScore := puser.Score - prevScore score := puser.Score
//score = 23
currentScore := score - prevScore
nextScore := c.GetLevelScore(puser.Level+1) - prevScore nextScore := c.GetLevelScore(puser.Level+1) - prevScore
perc := int(math.Floor((float64(currentScore) / float64(nextScore)) * 100))
var blocked, blockedInv bool var blocked, blockedInv bool
if user.Loggedin { if user.Loggedin {
blocked, err = c.UserBlocks.IsBlockedBy(user.ID, puser.ID) 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 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) return renderTemplate("profile", w, r, h, ppage)
} }

View File

@ -20,13 +20,6 @@
</div> </div>
<div id="dash_right" class="coldyn_item"> <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">{{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"> {{template "account_own_edit_level.html" .}}
<div class="levelBit">
<a href="/user/levels/">{{level .CurrentUser.Level}}</a>
</div>
<div class="progressWrap" style="width:{{.Percentage}}%;">
<div>{{.CurrentScore}} / {{.NextScore}}</div>
</div>
</div>
</div> </div>
</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

@ -15,7 +15,7 @@
{{if .IP}}<div class="rowblock rowlist bgavatars micro_grid{{if .ItemList}} has_items{{end}}"> {{if .IP}}<div class="rowblock rowlist bgavatars micro_grid{{if .ItemList}} has_items{{end}}">
{{range .ItemList}}<div class="rowitem"style="background-image:url('{{.Avatar}}');"> {{range .ItemList}}<div class="rowitem"style="background-image:url('{{.Avatar}}');">
<img src="{{.Avatar}}"class="bgsub"alt="Avatar"aria-hidden="true"> <img src="{{.Avatar}}"class="bgsub"alt="Avatar"aria-hidden="true">
<a class="rowTitle" href="{{.Link}}">{{.Name}}</a> <a class="rowTitle"href="{{.Link}}">{{.Name}}</a>
</div> </div>
{{else}}<div class="rowitem rowmsg">{{lang "ip_search_no_users"}}</div>{{end}} {{else}}<div class="rowitem rowmsg">{{lang "ip_search_no_users"}}</div>{{end}}
</div>{{end}} </div>{{end}}

View File

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

View File

@ -14,10 +14,10 @@
<div class="levelBlock"> <div class="levelBlock">
<div class="rowitem passive"> <div class="rowitem passive">
<div class="profile_menu_item level_inprogress"> <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> <a>{{level .ProfileOwner.Level}}</a>
</div> </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>{{.CurrentScore}} / {{.NextScore}}</div>
</div> </div>
</div> </div>

View File

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