aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2019-04-14 23:19:25 +0200
committerPřemysl Janouch <p@janouch.name>2019-04-14 23:19:25 +0200
commit608ba10eecb1f5c02eb41b288d2af5ce2de3f4f5 (patch)
tree7d9eec29eff7b917a33fb8ab90efcc3f6a2f5da7
parent8d9b6f75d0b75e9495b3a963f02bd26acd989b26 (diff)
downloadsklad-608ba10eecb1f5c02eb41b288d2af5ce2de3f4f5.tar.gz
sklad-608ba10eecb1f5c02eb41b288d2af5ce2de3f4f5.tar.xz
sklad-608ba10eecb1f5c02eb41b288d2af5ce2de3f4f5.zip
sklad: show the number of members of each series
-rw-r--r--cmd/sklad/db.go6
-rw-r--r--cmd/sklad/main.go6
-rw-r--r--cmd/sklad/series.tmpl19
3 files changed, 23 insertions, 8 deletions
diff --git a/cmd/sklad/db.go b/cmd/sklad/db.go
index def18a5..0aba510 100644
--- a/cmd/sklad/db.go
+++ b/cmd/sklad/db.go
@@ -16,6 +16,10 @@ type Series struct {
Description string // what kind of containers this is for
}
+func (s *Series) Containers() []*Container {
+ return indexMembers[s.Prefix]
+}
+
type ContainerId string
type Container struct {
@@ -60,6 +64,7 @@ var (
dbLog *os.File
indexSeries = map[string]*Series{}
+ indexMembers = map[string][]*Container{}
indexContainer = map[ContainerId]*Container{}
indexChildren = map[ContainerId][]*Container{}
@@ -184,6 +189,7 @@ func loadDatabase() error {
}
}
indexChildren[pv.Parent] = append(indexChildren[pv.Parent], pv)
+ indexMembers[pv.Series] = append(indexMembers[pv.Series], pv)
}
// Validate that no container is a parent of itself on any level.
diff --git a/cmd/sklad/main.go b/cmd/sklad/main.go
index 32dd68b..fd675b1 100644
--- a/cmd/sklad/main.go
+++ b/cmd/sklad/main.go
@@ -129,9 +129,9 @@ func handleSeries(w http.ResponseWriter, r *http.Request) {
return
}
- allSeries := map[string]string{}
+ allSeries := map[string]*Series{}
for _, s := range indexSeries {
- allSeries[s.Prefix] = s.Description
+ allSeries[s.Prefix] = s
}
prefix := r.FormValue("prefix")
@@ -145,7 +145,7 @@ func handleSeries(w http.ResponseWriter, r *http.Request) {
params := struct {
Prefix string
Description string
- AllSeries map[string]string
+ AllSeries map[string]*Series
}{
Prefix: prefix,
Description: description,
diff --git a/cmd/sklad/series.tmpl b/cmd/sklad/series.tmpl
index 4956e3a..01e2539 100644
--- a/cmd/sklad/series.tmpl
+++ b/cmd/sklad/series.tmpl
@@ -21,15 +21,24 @@
</form>
</section>
-{{ range $prefix, $desc := .AllSeries }}
+{{ range .AllSeries }}
<section>
<header>
- <h3><a href="/series?prefix={{ $prefix }}">{{ $prefix }}</a></h3>
- <form method=post action="/series?prefix={{ $prefix }}">
- <input type=text name=description value="{{ $desc }}"
+ <h3><a href="/series?prefix={{ .Prefix }}">{{ .Prefix }}</a></h3>
+{{ with $count := len .Containers }}
+{{ if eq $count 1 }}
+ <p>{{ $count }} obal
+{{ else if and (ge $count 2) (le $count 4) }}
+ <p>{{ $count }} obaly
+{{ else if gt $count 0 }}
+ <p>{{ $count }} obalů
+{{ end }}
+{{ end }}
+ <form method=post action="/series?prefix={{ .Prefix }}">
+ <input type=text name=description value="{{ .Description }}"
><input type=submit value="Uložit">
</form>
- <form method=post action="/series?prefix={{ $prefix }}&amp;remove">
+ <form method=post action="/series?prefix={{ .Prefix }}&amp;remove">
<input type=submit value="Odstranit">
</form>
</header>