From 4a1fe520e8aae6b220784ccfb34a6e7559e4cce7 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 21 Sep 2024 10:09:58 +0200 Subject: Implement /coins/mintages in Go templates --- src/countries.go | 52 ++++++------ src/http.go | 4 +- src/templates.go | 23 +++++- src/templates/coins-mintages.html.tmpl | 143 +++++++++++++++++++++++++++++++++ 4 files changed, 193 insertions(+), 29 deletions(-) create mode 100644 src/templates/coins-mintages.html.tmpl 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" }} +
+ {{ template "navbar" . }} +

{{ .T "Euro Coin Mintages" }}

+
+
+

+ {{ .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." }} +

+
+ {{ if eq .Code "nl" }} +

{{ .T "Additional Notes" }}

+ + {{ end }} +
+
+
+ +
+ {{ 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")) }} +
+
+ +
+
+
{{ .T "Standard Issue Coins" }}
+ + + + {{ with $p := .Printer }} + {{ range denoms }} + + {{ end }} + {{ end }} + + + {{ $p := .Printer }} + {{ $type := .Type }} + {{ range .Mintages.Standard }} + + + {{ range (index .Mintages (strToCtype $type)) }} + {{ if eq . -1 }} + + {{ else if eq . 0 }} + + {{ else }} + + {{ end }} + + {{ end }} + + {{ end }} + +
{{ .T "Year" }}{{ $p.Money . false }}
+ {{- .Year -}} + {{- if ne .Mintmark "" -}} +  {{ .Mintmark }} + {{- end -}} + {{ $p.T "Unknown" }}{{ $p.N . }}
+
+ {{ if ne (len .Mintages.Commemorative) 0 }} +
+
{{ .T "Commemorative Coins" }}
+ + + + + + + + {{ $p := .Printer }} + {{ $type := .Type }} + {{ range .Mintages.Commemorative }} + + + + + {{ with (index .Mintage (strToCtype $type)) }} + {{ if eq . -1 }} + + {{ else if eq . 0 }} + + {{ else }} + + {{ end }} + {{ end }} + + {{ end }} + +
{{ .T "Year" }}{{ .T "Commemorated Issue" }}{{ .T "Mintage" }}
+ {{- .Year -}} + {{- if ne .Mintmark "" -}} +  {{ .Mintmark }} + {{- end -}} + {{ .Name }}{{ $p.T "Unknown" }}{{ $p.N . }}
+
+ {{ end }} +
+
+{{ end }} + +{{ define "coin-type-radio" }} + +{{ end }} -- cgit v1.2.3