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
|
Description string // what kind of containers this is for
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Series) Containers() []*Container {
|
||||||
|
return indexMembers[s.Prefix]
|
||||||
|
}
|
||||||
|
|
||||||
type ContainerId string
|
type ContainerId string
|
||||||
|
|
||||||
type Container struct {
|
type Container struct {
|
||||||
|
@ -60,6 +64,7 @@ var (
|
||||||
dbLog *os.File
|
dbLog *os.File
|
||||||
|
|
||||||
indexSeries = map[string]*Series{}
|
indexSeries = map[string]*Series{}
|
||||||
|
indexMembers = map[string][]*Container{}
|
||||||
indexContainer = map[ContainerId]*Container{}
|
indexContainer = map[ContainerId]*Container{}
|
||||||
indexChildren = map[ContainerId][]*Container{}
|
indexChildren = map[ContainerId][]*Container{}
|
||||||
|
|
||||||
|
@ -184,6 +189,7 @@ func loadDatabase() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indexChildren[pv.Parent] = append(indexChildren[pv.Parent], pv)
|
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.
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
allSeries := map[string]string{}
|
allSeries := map[string]*Series{}
|
||||||
for _, s := range indexSeries {
|
for _, s := range indexSeries {
|
||||||
allSeries[s.Prefix] = s.Description
|
allSeries[s.Prefix] = s
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix := r.FormValue("prefix")
|
prefix := r.FormValue("prefix")
|
||||||
|
@ -145,7 +145,7 @@ func handleSeries(w http.ResponseWriter, r *http.Request) {
|
||||||
params := struct {
|
params := struct {
|
||||||
Prefix string
|
Prefix string
|
||||||
Description string
|
Description string
|
||||||
AllSeries map[string]string
|
AllSeries map[string]*Series
|
||||||
}{
|
}{
|
||||||
Prefix: prefix,
|
Prefix: prefix,
|
||||||
Description: description,
|
Description: description,
|
||||||
|
|
|
@ -21,15 +21,24 @@
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{{ range $prefix, $desc := .AllSeries }}
|
{{ range .AllSeries }}
|
||||||
<section>
|
<section>
|
||||||
<header>
|
<header>
|
||||||
<h3><a href="/series?prefix={{ $prefix }}">{{ $prefix }}</a></h3>
|
<h3><a href="/series?prefix={{ .Prefix }}">{{ .Prefix }}</a></h3>
|
||||||
<form method=post action="/series?prefix={{ $prefix }}">
|
{{ with $count := len .Containers }}
|
||||||
<input type=text name=description value="{{ $desc }}"
|
{{ 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">
|
><input type=submit value="Uložit">
|
||||||
</form>
|
</form>
|
||||||
<form method=post action="/series?prefix={{ $prefix }}&remove">
|
<form method=post action="/series?prefix={{ .Prefix }}&remove">
|
||||||
<input type=submit value="Odstranit">
|
<input type=submit value="Odstranit">
|
||||||
</form>
|
</form>
|
||||||
</header>
|
</header>
|
||||||
|
|
Loading…
Reference in New Issue