summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-09-21 10:09:58 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-09-21 10:09:58 +0200
commit4a1fe520e8aae6b220784ccfb34a6e7559e4cce7 (patch)
tree67ca0d2c601575d68c341c55c8b8897071870690 /src
parent492f2df4e93fa151e7809203bca7b92379694665 (diff)
Implement /coins/mintages in Go templates
Diffstat (limited to 'src')
-rw-r--r--src/countries.go52
-rw-r--r--src/http.go4
-rw-r--r--src/templates.go23
-rw-r--r--src/templates/coins-mintages.html.tmpl143
4 files changed, 193 insertions, 29 deletions
diff --git a/src/countries.go b/src/countries.go
index de1c919..3fa764b 100644
--- a/src/countries.go
+++ b/src/countries.go
@@ -8,39 +8,39 @@ import (
)
type country struct {
- code, name string
+ Code, Name string
}
func sortedCountries(p Printer) []country {
xs := []country{
- {code: "ad", name: p.T("Andorra")},
- {code: "at", name: p.T("Austria")},
- {code: "be", name: p.T("Belgium")},
- {code: "cy", name: p.T("Cyprus")},
- {code: "de", name: p.T("Germany")},
- {code: "ee", name: p.T("Estonia")},
- {code: "es", name: p.T("Spain")},
- {code: "fi", name: p.T("Finland")},
- {code: "fr", name: p.T("France")},
- {code: "gr", name: p.T("Greece")},
- {code: "hr", name: p.T("Croatia")},
- {code: "ie", name: p.T("Ireland")},
- {code: "it", name: p.T("Italy")},
- {code: "lt", name: p.T("Lithuania")},
- {code: "lu", name: p.T("Luxembourg")},
- {code: "lv", name: p.T("Latvia")},
- {code: "mc", name: p.T("Monaco")},
- {code: "mt", name: p.T("Malta")},
- {code: "nl", name: p.T("Netherlands")},
- {code: "pt", name: p.T("Portugal")},
- {code: "si", name: p.T("Slovenia")},
- {code: "sk", name: p.T("Slovakia")},
- {code: "sm", name: p.T("San Marino")},
- {code: "va", name: p.T("Vatican City")},
+ {Code: "ad", Name: p.T("Andorra")},
+ {Code: "at", Name: p.T("Austria")},
+ {Code: "be", Name: p.T("Belgium")},
+ {Code: "cy", Name: p.T("Cyprus")},
+ {Code: "de", Name: p.T("Germany")},
+ {Code: "ee", Name: p.T("Estonia")},
+ {Code: "es", Name: p.T("Spain")},
+ {Code: "fi", Name: p.T("Finland")},
+ {Code: "fr", Name: p.T("France")},
+ {Code: "gr", Name: p.T("Greece")},
+ {Code: "hr", Name: p.T("Croatia")},
+ {Code: "ie", Name: p.T("Ireland")},
+ {Code: "it", Name: p.T("Italy")},
+ {Code: "lt", Name: p.T("Lithuania")},
+ {Code: "lu", Name: p.T("Luxembourg")},
+ {Code: "lv", Name: p.T("Latvia")},
+ {Code: "mc", Name: p.T("Monaco")},
+ {Code: "mt", Name: p.T("Malta")},
+ {Code: "nl", Name: p.T("Netherlands")},
+ {Code: "pt", Name: p.T("Portugal")},
+ {Code: "si", Name: p.T("Slovenia")},
+ {Code: "sk", Name: p.T("Slovakia")},
+ {Code: "sm", Name: p.T("San Marino")},
+ {Code: "va", Name: p.T("Vatican City")},
}
c := collate.New(language.MustParse(p.Locale.Bcp))
slices.SortFunc(xs, func(x, y country) int {
- return c.CompareString(x.name, y.name)
+ return c.CompareString(x.Name, y.Name)
})
return xs
}
diff --git a/src/http.go b/src/http.go
index 8ca7564..395aefd 100644
--- a/src/http.go
+++ b/src/http.go
@@ -118,9 +118,9 @@ func mintageHandler(next http.Handler) http.Handler {
td.Code = strings.ToLower(r.FormValue("code"))
if !slices.ContainsFunc(td.Countries, func(c country) bool {
- return c.code == td.Code
+ return c.Code == td.Code
}) {
- td.Code = td.Countries[0].code
+ td.Code = td.Countries[0].Code
}
td.Type = strings.ToLower(r.FormValue("type"))
diff --git a/src/templates.go b/src/templates.go
index 6649b28..f0558f3 100644
--- a/src/templates.go
+++ b/src/templates.go
@@ -24,12 +24,15 @@ var (
"/": buildTemplate("index"),
"/about": buildTemplate("about"),
"/coins": buildTemplate("coins"),
+ "/coins/mintages": buildTemplate("coins-mintages"),
"/jargon": buildTemplate("jargon"),
"/language": buildTemplate("language"),
}
funcmap = map[string]any{
- "safe": asHTML,
+ "denoms": denoms,
"locales": locales,
+ "safe": asHTML,
+ "strToCtype": strToCtype,
"toUpper": strings.ToUpper,
"tuple": templateMakeTuple,
}
@@ -50,6 +53,13 @@ func asHTML(s string) template.HTML {
return template.HTML(s)
}
+func denoms() [8]float64 {
+ return [8]float64{
+ 0.01, 0.02, 0.05, 0.10,
+ 0.20, 0.50, 1.00, 2.00,
+ }
+}
+
func locales() []locale {
return Locales[:]
}
@@ -58,6 +68,17 @@ func templateMakeTuple(args ...any) []any {
return args
}
+func strToCtype(s string) int {
+ switch s {
+ case "nifc":
+ return mintage.TypeNIFC
+ case "proof":
+ return mintage.TypeProof
+ default:
+ return mintage.TypeCirc
+ }
+}
+
func (td templateData) T(fmt string, args ...any) string {
return td.Printer.T(fmt, args...)
}
diff --git a/src/templates/coins-mintages.html.tmpl b/src/templates/coins-mintages.html.tmpl
new file mode 100644
index 0000000..646203a
--- /dev/null
+++ b/src/templates/coins-mintages.html.tmpl
@@ -0,0 +1,143 @@
+{{ define "content" }}
+<header>
+ {{ template "navbar" . }}
+ <h1>{{ .T "Euro Coin Mintages" }}</h1>
+</header>
+<main>
+ <p>
+ {{ .T "Here you’ll be able to view all the known mintages for all coins. You’ll also be able to filter on country, denomination, etc. If you have any mintage data that’s missing from our site, feel free to contact us." }}
+ </p>
+ <hr />
+ {{ if eq .Code "nl" }}
+ <h2>{{ .T "Additional Notes" }}</h2>
+ <ul>
+ <li>
+ {{ .T "Most coins from the years 2003–2016 are listed as NIFC coins while other popular sources such as Numista claim they were minted for circulation. For more information on why others are wrong, %sclick here%s." `<a href="#TODO">` `</a>` }}
+ </li>
+ <li>
+ {{ .T "In 2003 Numista calculated a total of %d coins issued for coin sets per denomination. Our own calculations found only %d. Numista also forgot to include the many hundred thousand coins from the coin roll sets that were produced." 217503 177003 }}
+ </li>
+ </ul>
+ {{ end }}
+ <section>
+ <form>
+ <div class="grid">
+ <label for="country-dd">
+ {{ .T "Country" }}
+ <select id="country-dd" name="code">
+ {{ $code := .Code }}
+ {{ range .Countries }}
+ <option
+ value={{ .Code }}
+ {{ if eq .Code $code }}
+ selected
+ {{ end }}
+ >
+ {{ .Name }}
+ </option>
+ {{ end }}
+ </select>
+ </label>
+ <fieldset>
+ {{ template "coin-type-radio"
+ (tuple .Type "circ" (.T "Circulation Coins")) }}
+ {{ template "coin-type-radio"
+ (tuple .Type "nifc" (.T "NIFC / BU Sets")) }}
+ {{ template "coin-type-radio"
+ (tuple .Type "proof" (.T "Proof Coins")) }}
+ </fieldset>
+ </div>
+ <button type="submit">{{ .T "Filter" }}</button>
+ </form>
+ <figure>
+ <figcaption>{{ .T "Standard Issue Coins" }}</figcaption>
+ <table class="mintage-table" role="grid">
+ <thead>
+ <th>{{ .T "Year" }}</th>
+ {{ with $p := .Printer }}
+ {{ range denoms }}
+ <th>{{ $p.Money . false }}</th>
+ {{ end }}
+ {{ end }}
+ </thead>
+ <tbody>
+ {{ $p := .Printer }}
+ {{ $type := .Type }}
+ {{ range .Mintages.Standard }}
+ <tr>
+ <th scope="col">
+ {{- .Year -}}
+ {{- if ne .Mintmark "" -}}
+ &nbsp;<sub><small>{{ .Mintmark }}</small></sub>
+ {{- end -}}
+ </th>
+ {{ range (index .Mintages (strToCtype $type)) }}
+ {{ if eq . -1 }}
+ <td>{{ $p.T "Unknown" }}</td>
+ {{ else if eq . 0 }}
+ <td>—</td>
+ {{ else }}
+ <td>{{ $p.N . }}</td>
+ {{ end }}
+ </td>
+ {{ end }}
+ </tr>
+ {{ end }}
+ </tbody>
+ </table>
+ </figure>
+ {{ if ne (len .Mintages.Commemorative) 0 }}
+ <figure>
+ <figcaption>{{ .T "Commemorative Coins" }}</figcaption>
+ <table class="mintage-table-cc" role="grid">
+ <thead>
+ <th>{{ .T "Year" }}</th>
+ <th>{{ .T "Commemorated Issue" }}</th>
+ <th>{{ .T "Mintage" }}</th>
+ </thead>
+ <tbody>
+ {{ $p := .Printer }}
+ {{ $type := .Type }}
+ {{ range .Mintages.Commemorative }}
+ <tr>
+ <th scope="col">
+ {{- .Year -}}
+ {{- if ne .Mintmark "" -}}
+ &nbsp;<sub><small>{{ .Mintmark }}</small></sub>
+ {{- end -}}
+ </th>
+ <!-- TODO: Translate commemorative names -->
+ <td>{{ .Name }}</td>
+ {{ with (index .Mintage (strToCtype $type)) }}
+ {{ if eq . -1 }}
+ <td>{{ $p.T "Unknown" }}</td>
+ {{ else if eq . 0 }}
+ <td>—</td>
+ {{ else }}
+ <td>{{ $p.N . }}</td>
+ {{ end }}
+ {{ end }}
+ </tr>
+ {{ end }}
+ </tbody>
+ </table>
+ </figure>
+ {{ end }}
+ </section>
+</main>
+{{ end }}
+
+{{ define "coin-type-radio" }}
+<label for=compact-{{ index . 1 }}>
+ <input
+ id=compact-{{ index . 1 }}
+ name="type"
+ type="radio"
+ value={{ index . 1 }}
+ {{ if eq (index . 0) (index . 1) }}
+ checked
+ {{ end }}
+ />
+ {{ index . 2 }}
+</label>
+{{ end }}