2023-02-04 10:32:39 +00:00
|
|
|
{{ define "title" -}}
|
|
|
|
{{( pgettext "Products" "title" )}}
|
|
|
|
{{- end }}
|
|
|
|
|
|
|
|
{{ define "content" }}
|
|
|
|
<nav>
|
|
|
|
<p>
|
|
|
|
<a href="{{ companyURI "/" }}">{{( pgettext "Home" "title" )}}</a> /
|
|
|
|
<a>{{( pgettext "Products" "title" )}}</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<a class="primary button"
|
|
|
|
href="{{ companyURI "/products/new" }}">{{( pgettext "New product" "action" )}}</a>
|
|
|
|
</p>
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
{{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.productsIndexPage*/ -}}
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>{{( pgettext "All" "product" )}}</th>
|
|
|
|
<th>{{( pgettext "Name" "title" )}}</th>
|
|
|
|
<th>{{( pgettext "Price" "title" )}}</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{{ with .Products }}
|
|
|
|
{{- range $product := . }}
|
|
|
|
<tr>
|
|
|
|
<td></td>
|
|
|
|
<td><a href="{{ companyURI "/products/"}}{{ .Slug }}">{{ .Name }}</a></td>
|
Convert from cents to “price” and back
I do not want to use floats in the Go lang application, because it is
not supposed to do anything with these values other than to print and
retrieve them from the user; all computations will be performed by
PostgreSQL in cents.
That means i have to “convert” from the price format that users expect
to see (e.g., 1.234,56) to cents (e.g., 123456) and back when passing
data between Go and PostgreSQL, and that conversion depends on the
currency’s decimal places.
At first i did everything in Go, but saw that i would need to do it in
a loop when retrieving the list of products, and immediately knew it was
a mistake—i needed a PL/pgSQL function for that.
I still need to convert from string to float, however, when printing the
value to the user. Because the string representation is in C, but i
need to format it according to the locale with golang/x/text. That
package has the information of how to correctly format numbers, but it
is in an internal package that i can not use, and numbers.Digit only
accepts numeric types, not a string.
2023-02-05 12:55:12 +00:00
|
|
|
<td>{{ .Price | formatPrice }}</td>
|
2023-02-04 10:32:39 +00:00
|
|
|
</tr>
|
|
|
|
{{- end }}
|
|
|
|
{{ else }}
|
|
|
|
<tr>
|
|
|
|
<td colspan="4">{{( gettext "No products added yet." )}}</td>
|
|
|
|
</tr>
|
|
|
|
{{ end }}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
{{- end }}
|