sklad: show the number of members of each series
This commit is contained in:
parent
8d9b6f75d0
commit
608ba10eec
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 }}&remove">
|
||||
<form method=post action="/series?prefix={{ .Prefix }}&remove">
|
||||
<input type=submit value="Odstranit">
|
||||
</form>
|
||||
</header>
|
||||
|
|
Loading…
Reference in New Issue