-
Notifications
You must be signed in to change notification settings - Fork 1
/
templates.go
154 lines (143 loc) · 5.1 KB
/
templates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
const frameTemplate = `<!DOCTYPE html>
<html>
<head>
<title>Excalibur - Netrunner tournament</title>
<style>
table { border-collapse: collapse; }
td, th { padding: 0.4em 0.8em; border-bottom: 1px solid #aaaaaa; }
th { font-weight: bold }
td.winner {font-weight: bold }
td.corp { border-bottom: 2px solid #0000aa; }
td.runner { border-bottom: 2px solid #aa0000; }
li { padding-bottom: 0.4em; }
</style>
</head>
<body>
{{template "content" .}}
</body>
</html>
`
const menuTemplate = `<h1>Tournament menu</h1>
<ul>
<li><a href="/players">Players</a></li>
<li><a href="/standings">Standings</a></li>
<li><a href="/matches">Current Round Matches</a></li>
<li><a href="/rounds">All rounds</a></li>
<li><form action="/finishRound" method="POST"><input type="submit" value="Finish round"></form></li>
<li><form action="/nextRound" method="POST"><input type="submit" value="Start next round"></form></li>
<li><a href="/saves">History/undo</a></li>
</ul>
`
const playerListTemplate = `<h1>Players</h1>
{{if .Players}}<table>
{{range .Players}}<form action="/players/change" method="POST"><input type="hidden" name="player-id" value="{{.PlayerID}}"><tr><td>{{.Name}}{{if or .Corp .Runner}} ({{.Corp}}{{if and .Corp .Runner}}, {{end}}{{.Runner}}){{end}}</td><td><a href="/players/change?player-id={{.PlayerID}}">edit</a></td><td>{{if .Dropped}}Dropped <input type="submit" name="re-add" value="Re-add">{{else}}<input type="submit" name="drop" value="Drop">{{end}}</td></tr></form>
{{end}}</table>
{{end}}
<p><a href="/players/add">Add player</a></p>
<p><a href="/">Menu</a></p>
`
const savesTemplate = `<h1>Saved tournament states</h1>
{{if .}}<p>Note that newer states are at the bottom</p>
<table>
<tr><th>Last action</th><th></th></tr>
{{range .}}<tr>
<td>{{.Reason}}</td>
<td>
<form action="/load" method="POST">
<input type="hidden" name="save-number" value="{{.Number}}">
<input type="hidden" name="save-reason" value="{{.Reason}}">
<input type="submit" value="Load">
</form>
</td>
</tr>{{end}}
</table>
{{else}}
<p>No saves.</p>
{{end}}
`
const standingsTemplate = `{{$t := .}}<h1>Standings</h1>
{{if .Standings}}<table id="standings">
<tr><th>Player</th><th>Pts</th><th>SoS</th><th>XSoS</th></tr>
{{range .Standings}}{{$p := ($t.Player .)}}<tr><td>{{$p.Name}}</td><td>{{$p.Prestige}}</td><td>{{printf "%.3f" $p.SoS}}</td><td>{{printf "%.3f" $p.XSoS}}</td></tr>
{{end}}
</table>
{{end}}
<p><a href="/">Menu</a></p>
`
const playerFormTemplate = `<h1>{{if .add}}Add{{else}}Edit{{end}} player</h1>
{{if .error}}<p><strong>Error: {{.error}}</p></strong>{{end}}
<form action="{{.saveurl}}" method="POST">
<label>Name: <input type="text" name="name" autofocus{{if .name}} value="{{.name}}"{{end}}></label><br>
{{- if .id}}<input type="hidden" name="player-id" value="{{.id}}">{{end -}}
<label>Corp: <input type="text" name="corp"{{if .corp}} value="{{.corp}}"{{end}}></label><br>
<label>Runner: <input type="text" name="runner"{{if .runner}} value="{{.runner}}"{{end}}></label><br>
<input type="submit" {{if .add}}name="add" value="Add"{{else}}name="edit" value="Change"{{end}}>
</form>
`
const matchesTemplate = `{{$t := .Tournament}}{{$roundNum := .Number}}<h1>Round {{$roundNum}}</h1>
<table><tr><th>#</th><th>Corp</th><th>Runner</th><th>Result</th></tr>
{{range .Matches}}
<tr>
<th>{{.Number}}</th>
<td class="corp
{{- if .Game.CorpWin}} winner{{end -}}
">{{($t.Player .Game.Pairing.Corp).Name}}</td>
<td class="runner
{{- if .Game.RunnerWin}} winner{{end -}}
{{- if .IsBye}} bye{{end -}}
">
{{- if not .IsBye -}}
{{($t.Player .Game.Pairing.Runner).Name}}
{{- else -}}
BYE
{{- end -}}
</td>
<td class="result
{{- if not .IsBye}} bye{{end -}}
">
{{- if .IsBye -}}
BYE
{{- else if .Game.Concluded}}
{{- if or .Game.CorpWin .Game.RunnerWin}}
{{- if .Game.CorpWin -}}
Corp win
{{- else -}}
Runner win
{{- end}}
{{- if.Game.ModifiedWin}} (time)
{{- end}}
{{- else -}}
Tie
{{- end -}}
{{- end -}}
{{if not .IsBye}}
{{- if .Game.Concluded}} ({{end -}}
<a href="/recordResult?round={{$roundNum}}&match={{.Number}}">
{{- if .Game.Concluded}}edit{{else}}record{{end -}}
</a>
{{- if .Game.Concluded}}){{end}}
{{- end -}}
</td>
</tr>
{{end}}
</table>
<p><a href="/">Menu</a></p>
`
const noMatchesTemplate = `<h1>Matches</h1>
<p>No matches</p>
`
const roundsTemplate = `{{range .Rounds}}{{template "round" .}}{{end}}`
const recordMatchTemplate = `<h1>{{if .winner}}Update{{else}}Record{{end}} match result</h1>
<form action="{{.recordurl}}" method="POST">
<input type="hidden" name="round" value="{{.roundNum}}">
<input type="hidden" name="match" value="{{.matchNum}}">
<p>Winner:</p>
<label><input type="radio" name="winner" value="corp"{{if .corpWin}} checked{{end}}> {{.corp}} (Corp)</label><br>
<label><input type="radio" name="winner" value="tie"{{if .tie}} checked{{end}}> Tie</label><br>
<label><input type="radio" name="winner" value="runner"{{if .runnerWin}} checked{{end}}> {{.runner}} (Runner)</label></p>
<p><label><input type="checkbox" name="timed"{{if .timed}} checked{{end}}> Timed/modified win</label></p>
<p><input type="submit" value="Record"></p>
</form>
`
const errorTemplate = `{{if .}}<p><strong>Error: {{.}}</strong></p>{{end}}`