From 4fabe52169e718af25b407533d775da3f3192015 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 6 May 2025 20:01:42 +0200 Subject: Show user statistics on profile (use pug mixin). --- public/style.css | 9 +++++++++ server.js | 4 +++- views/head.pug | 33 +++++++++++++++++++++++++++++++++ views/profile.pug | 14 ++++++++++++-- views/user.pug | 34 ++-------------------------------- 5 files changed, 59 insertions(+), 35 deletions(-) diff --git a/public/style.css b/public/style.css index bbbcbbd..7c0c07b 100644 --- a/public/style.css +++ b/public/style.css @@ -226,6 +226,15 @@ div.logo img { border: var(--thin-border); } +p.box { + white-space: pre-wrap; + font-style: italic; + padding: 8px 12px; + border: var(--thin-border); + box-shadow: var(--drop-shadow); + background-color: var(--color-text); +} + /* TABLES */ table { diff --git a/server.js b/server.js index 8067d84..8c8b52f 100644 --- a/server.js +++ b/server.js @@ -1687,12 +1687,14 @@ function annotate_games(list, user_id, unread, unseen) { } app.get("/profile", must_be_logged_in, function (req, res) { + var who = SQL_SELECT_USER_PROFILE.get(req.user.name) var mail = { notify: SQL_SELECT_USER_NOTIFY.get(req.user.user_id), is_verified: SQL_SELECT_USER_VERIFIED.get(req.user.user_id) } var webhook = SQL_SELECT_WEBHOOK.get(req.user.user_id) - res.render("profile.pug", { mail, webhook }) + var ratings = SQL_USER_RATINGS.all(req.user.user_id) + res.render("profile.pug", { who, mail, webhook, ratings }) }) app.get("/games", function (_req, res) { diff --git a/views/head.pug b/views/head.pug index 3707757..20fb9aa 100644 --- a/views/head.pug +++ b/views/head.pug @@ -212,3 +212,36 @@ mixin tourlist(seeds, pools, fin) +poollist(pools, "Active", TM_ICON_ACTIVE) div +poollist(fin, "Finished", TM_ICON_FINISHED) + +mixin userstats(who, ratings) + if (who.move_time_mean !== null) + h3 Response time + div Average response time: #{format_minutes(who.move_time_mean)} + if (who.move_time_q2 !== null) + div Median response time: #{format_minutes(who.move_time_q2)} + if (who.move_time_q1 !== null && who.move_time_q2 !== null) + div Middle half of response times: #{format_minutes(who.move_time_q1)} to #{format_minutes(who.move_time_q3)} + + h3 Timeouts + div Total number of timeouts: #{who.timeout_total} + div Games completed since last timeout: #{who.games_since_timeout} + + if ratings.length > 0 + h3 Most played games + table + thead + tr + th Title + th Count + th Last played + if user && user.user_id === 1 + th Elo + tbody + each row in ratings + tr + td + a.black(href="/" + row.title_id)= row.title_name + td.r= row.count + td.r= row.last + if user && user.user_id === 1 + td.r= row.rating diff --git a/views/profile.pug b/views/profile.pug index 39f1977..de6e5c4 100644 --- a/views/profile.pug +++ b/views/profile.pug @@ -7,9 +7,19 @@ html body include header article - h1= SITE_NAME + h1 Profile p Welcome, #{user.name}! + + if who.about + p.box= who.about + + p Member since #{human_date(who.ctime)}. + + +userstats(who, ratings) + + h3 Account + p Your mail address is #{user.mail} if ENABLE_MAIL @@ -30,7 +40,7 @@ html | Change user name br | Change profile text - br + p | Delete account if ENABLE_WEBHOOKS diff --git a/views/user.pug b/views/user.pug index c3e8925..b5859a2 100644 --- a/views/user.pug +++ b/views/user.pug @@ -24,7 +24,7 @@ html h1= who.name if who.about - p.about= who.about + p.box= who.about p Member since #{human_date(who.ctime)}. p Last seen #{human_date(who.atime)}. @@ -42,37 +42,7 @@ html br a(href="/contacts/add-enemy/"+who.name) Add to blacklist - if (who.move_time_mean !== null) - h3 Response time - div Average response time: #{format_minutes(who.move_time_mean)} - if (who.move_time_q2 !== null) - div Median response time: #{format_minutes(who.move_time_q2)} - if (who.move_time_q1 !== null && who.move_time_q2 !== null) - div Middle half of response times: #{format_minutes(who.move_time_q1)} to #{format_minutes(who.move_time_q3)} - - h3 Timeouts - div Total number of timeouts: #{who.timeout_total} - div Games completed since last timeout: #{who.games_since_timeout} - - if ratings.length > 0 - h3 Most played games - table - thead - tr - th Title - th Count - th Last played - if user && user.user_id === 1 - th Elo - tbody - each row in ratings - tr - td - a.black(href="/" + row.title_id)= row.title_name - td.r= row.count - td.r= row.last - if user && user.user_id === 1 - td.r= row.rating + +userstats(who, ratings) +tourlist(null, active_pools, finished_pools) -- cgit v1.2.3