From 0ff56af36fe2d1a6465030075e02fb16d8ccd78d Mon Sep 17 00:00:00 2001 From: Azareal Date: Wed, 28 Jul 2021 17:43:38 +1000 Subject: [PATCH] Fix level bar UI. Reduce boilerplate. --- common/activity_stream.go | 5 +++-- common/attachments.go | 6 +++--- common/group.go | 4 ++-- routes/account.go | 23 +++++++++++++++-------- routes/panel/pages.go | 10 +++++----- routes/profile.go | 8 ++++++-- templates/account_own_edit.html | 9 +-------- templates/account_own_edit_level.html | 8 ++++++++ templates/ip_search.html | 2 +- templates/level_list.html | 6 +++--- templates/profile.html | 4 ++-- themes/nox/public/main.css | 14 +++++++++++--- 12 files changed, 60 insertions(+), 39 deletions(-) create mode 100644 templates/account_own_edit_level.html diff --git a/common/activity_stream.go b/common/activity_stream.go index 11714a09..952528a1 100644 --- a/common/activity_stream.go +++ b/common/activity_stream.go @@ -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(), diff --git a/common/attachments.go b/common/attachments.go index 0f448e7b..b4774339 100644 --- a/common/attachments.go +++ b/common/attachments.go @@ -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 { diff --git a/common/group.go b/common/group.go index 831b84d0..42e77ad0 100644 --- a/common/group.go +++ b/common/group.go @@ -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 } diff --git a/routes/account.go b/routes/account.go index 4c687c90..d8768bc4 100644 --- a/routes/account.go +++ b/routes/account.go @@ -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:]}) diff --git a/routes/panel/pages.go b/routes/panel/pages.go index 5d67cf9a..3c27b971 100644 --- a/routes/panel/pages.go +++ b/routes/panel/pages.go @@ -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) } diff --git a/routes/profile.go b/routes/profile.go index f4946ad8..9d7d507a 100644 --- a/routes/profile.go +++ b/routes/profile.go @@ -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) } diff --git a/templates/account_own_edit.html b/templates/account_own_edit.html index 20bd005a..cc642343 100644 --- a/templates/account_own_edit.html +++ b/templates/account_own_edit.html @@ -20,13 +20,6 @@
{{if not .MFASetup}}{{lang "account_dash_2fa_setup"}}{{else}}{{lang "account_dash_2fa_manage"}}{{end}} {{lang "account_dash_security_notice"}}
-
- -
-
{{.CurrentScore}} / {{.NextScore}}
-
-
+ {{template "account_own_edit_level.html" .}}
\ No newline at end of file diff --git a/templates/account_own_edit_level.html b/templates/account_own_edit_level.html new file mode 100644 index 00000000..683f04ee --- /dev/null +++ b/templates/account_own_edit_level.html @@ -0,0 +1,8 @@ +
+ +
+
{{.CurrentScore}} / {{.NextScore}}
+
+
\ No newline at end of file diff --git a/templates/ip_search.html b/templates/ip_search.html index 3fd86fbb..83cca2ea 100644 --- a/templates/ip_search.html +++ b/templates/ip_search.html @@ -15,7 +15,7 @@ {{if .IP}}
{{range .ItemList}} {{else}}
{{lang "ip_search_no_users"}}
{{end}}
{{end}} diff --git a/templates/level_list.html b/templates/level_list.html index f8644ebf..d8fd2f79 100644 --- a/templates/level_list.html +++ b/templates/level_list.html @@ -6,9 +6,9 @@ {{range .Levels}}
-
{{level .Level}}
-
-
Score: {{.Score}}
+
{{level .Level}}
+
+
{{if eq .Status "inprogress"}}{{$.CurrentUser.Score}} / {{.Score}}{{else if eq .Status "complete"}}{{.Score}} / {{.Score}}{{else}}Next: {{.Score}}{{end}}
diff --git a/templates/profile.html b/templates/profile.html index 8a14552a..e15299e6 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -14,10 +14,10 @@
-
+ -
+
{{.CurrentScore}} / {{.NextScore}}
diff --git a/themes/nox/public/main.css b/themes/nox/public/main.css index 0bf25977..61a25b16 100644 --- a/themes/nox/public/main.css +++ b/themes/nox/public/main.css @@ -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;