Made the elo system work. Colorized the leaderboard. Better data structure. Improved the HTML. Custom form system. Added Sessions

This commit is contained in:
Jonas Hahn
2025-08-25 14:56:59 +02:00
parent 4b4377a24e
commit f5e5d5632d
20 changed files with 492 additions and 289 deletions

View File

@@ -8,12 +8,10 @@
<title>QRank</title>
<!-- Also apple support -->
<link rel="icon" type="image/png" href="/assets/favicon.ico">
<link rel="apple-touch-icon" href="/assets/favicon.ico">
<link rel="shortcut icon" href="/assets/favicon.ico">
<link rel="icon" type="image/png" href="/assets/favicon.png">
<!-- Only one stylesheet for now -->
<link rel="stylesheet" href="/assets/styles.css">
<link rel="stylesheet" type="text/css" href="/assets/styles.css">
</head>
<body>
@@ -38,15 +36,7 @@
</div>
<div class="container">
<!-- Information messages for the user -->
{{if .Error}}
<div class="alert alert-error">{{.Error}}</div>
{{end}}
{{if .Success}}
<div class="alert alert-success">{{.Success}}</div>
{{end}}
{{if .Message}}
<div class="alert alert-info">{{.Message}}</div>
{{end}}
{{if .Message}}<div class="message">{{.Message}}</div>{{end}}
<!-- This is shorthand for a define along with a template -->
{{block "content" .}}{{end}}

View File

@@ -12,25 +12,25 @@
<div style="flex:1;min-width:180px">
<h3>Team A</h3>
<label class="label">Player A1</label>
<input class="input" name="a1" {{if .a1}}value="{{.a1}}"{{else}}value="{{.CurrentUser.Username}}"{{end}} placeholder="username or email">
<input class="input" name="a1" {{if (index .Form "a1")}}value="{{index .Form "a1"}}"{{else}}value="{{.CurrentUser.Username}}"{{end}} placeholder="username or email">
<div style="height:6px"></div>
<label class="label">Player A2 (optional)</label>
<input class="input" name="a2" {{if .a2}}value="{{.a2}}"{{end}} placeholder="username or email">
<input class="input" name="a2" value="{{index .Form "a2"}}" placeholder="username or email">
<div style="height:12px"></div>
<label class="label">Score A</label>
<input class="input" type="number" name="scoreA" {{if .scoreA}}value="{{.scoreA}}"{{else}}value="0"{{end}} min="0" max="10" required>
<input class="input" type="number" name="scoreA" value="{{index .Form "scoreA"}}" placeholder="0" min="0" max="10" required>
</div>
<div style="flex:1;min-width:180px">
<h3>Team B</h3>
<label class="label">Player B1</label>
<input class="input" name="b1" {{if .b1}}value="{{.b1}}"{{end}} placeholder="username or email">
<input class="input" name="b1" value="{{index .Form "b1"}}" placeholder="username or email">
<div style="height:6px"></div>
<label class="label">Player B2 (optional)</label>
<input class="input" name="b2" {{if .b2}}value="{{.b2}}"{{end}} placeholder="username or email">
<input class="input" name="b2" value="{{index .Form "b2"}}" placeholder="username or email">
<div style="height:12px"></div>
<label class="label">Score B</label>
<input class="input" type="number" name="scoreB" {{if .scoreB}}value="{{.scoreB}}"{{else}}value="0"{{end}} min="0" max="10" required>
<input class="input" type="number" name="scoreB" value="{{index .Form "scoreB"}}" placeholder="0" min="0" max="10" required>
</div>
</div>

View File

@@ -7,10 +7,11 @@
<div class="small">{{fmtTime .CreatedAt}}</div>
<div>
{{if .Table}}<span class="badge">{{.Table.Name}}</span> {{end}}
{{if .WinnerIsA}}{{range .PlayersA}}{{.Username}} {{end}}{{.ScoreA}}/{{.ScoreB}}{{else}}{{range .PlayersB}}{{.Username}} {{end}}{{.ScoreB}}/{{.ScoreA}}{{end}}
{{if .WinnerIsA}}<span style="color: goldenrod;"> {{range .PlayersA}}{{.Username}} {{end}}{{.ScoreA}}</span>/{{.ScoreB}}
{{else}} <span style="color: goldenrod;"> {{range .PlayersB}}{{.Username}} {{end}}{{.ScoreB}}</span>/{{.ScoreA}}{{end}}
</div>
<div class="small">
{{range .PlayersA}}@{{.Username}} {{end}}vs {{range .PlayersB}}@{{.Username}} {{end}}
{{range .PlayersA}}@{{.Username}} <span style="color: chocolate;">{{.DeltaElo}}</span> {{end}}vs {{range .PlayersB}}@{{.Username}} <span style="color: chocolate;">{{.DeltaElo}}</span> {{end}}
</div>
</li>
{{else}}

View File

@@ -1,9 +1,9 @@
{{define "content"}}
<div class="card">
<h2>Leaderboard (by wins)</h2>
<h2>Leaderboard</h2>
<ol>
{{range .Rows}}
<li>@<a href="/u/{{.Slug}}">{{.Username}}</a> - {{.Wins}} wins ({{.Games}} games)</li>
{{range .Users}}
<li><a href="/user/{{.Slug}}">@{{.Username}}</a> - {{.Elo}}</li>
{{else}}
<li class="small">No players yet.</li>
{{end}}

View File

@@ -1,14 +1,15 @@
{{define "content"}}
<div class="card">
<h2>@{{.Viewed.Username}}</h2>
<p class="small">Joined {{fmtTime .Viewed.CreatedAt}}</p>
<p>Game score {{.Stats.Games}}/{{.Stats.Wins}}/{{.Stats.Losses}}</p>
<h2>@{{.User.Username}}</h2>
<p class="small">Joined {{fmtTime .User.CreatedAt}}</p>
<p>Game score {{.User.GameCount}}/{{.User.WinCount}}/{{.User.LossCount}}</p>
<p>Current Elo {{.User.Elo}}</p>
{{if .Own}}
<hr>
<h3>Update your profile</h3>
<form method="POST" action="/me">
<label class="label">Username</label>
<input class="input" name="username" value="{{.Viewed.Username}}" required>
<input class="input" name="username" value="{{.User.Username}}" required>
<div style="height:8px"></div>
<button class="btn btn-primary">Save</button>
</form>