Browse Source

sklad: show the number of members of each series

master
Přemysl Janouch 9 months ago
parent
commit
608ba10eec
Signed by: Přemysl Janouch <p@janouch.name> GPG Key ID: A0420B94F92B9493
3 changed files with 23 additions and 8 deletions
  1. +6
    -0
      cmd/sklad/db.go
  2. +3
    -3
      cmd/sklad/main.go
  3. +14
    -5
      cmd/sklad/series.tmpl

+ 6
- 0
cmd/sklad/db.go View File

@@ -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.

+ 3
- 3
cmd/sklad/main.go View File

@@ -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,

+ 14
- 5
cmd/sklad/series.tmpl View File

@@ -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>

Loading…
Cancel
Save