sklad: cleanup, add comment

Child containers now show a linear list of subcontainers.
This commit is contained in:
Přemysl Eric Janouch 2019-04-14 19:12:31 +02:00
parent fbb76679f3
commit 3d98454543
Signed by: p
GPG Key ID: A0420B94F92B9493
3 changed files with 37 additions and 36 deletions

View File

@ -1,22 +1,23 @@
{{ define "Title" }}{{ or .Id "Obaly" }}{{ end }} {{ define "Title" }}{{/*
*/}}{{ if .Container }}{{ .Container.Id }}{{ else }}Obaly{{ end }}{{ end }}
{{ define "Content" }} {{ define "Content" }}
{{ if .Id }} {{ if .Container }}
<section> <section>
<header> <header>
<h2>{{ .Id }}</h2> <h2>{{ .Container.Id }}</h2>
<form method=post action="/label?id={{ .Id }}"> <form method=post action="/label?id={{ .Container.Id }}">
<input type=submit value="Vytisknout štítek"> <input type=submit value="Vytisknout štítek">
</form> </form>
<form method=post action="/?id={{ .Id }}&amp;remove"> <form method=post action="/?id={{ .Container.Id }}&amp;remove">
<input type=submit value="Odstranit"> <input type=submit value="Odstranit">
</form> </form>
</header> </header>
<form method=post action="/?id={{ .Id }}"> <form method=post action="/?id={{ .Container.Id }}">
<textarea name=description rows=5> <textarea name=description rows=5>
{{ .Description }} {{ .Container.Description }}
</textarea> </textarea>
<footer> <footer>
<div> <div>
@ -24,14 +25,14 @@
<select name=series id=series> <select name=series id=series>
{{ range $prefix, $desc := .AllSeries }} {{ range $prefix, $desc := .AllSeries }}
<option value="{{ $prefix }}" <option value="{{ $prefix }}"
{{ if eq $prefix $.Series }}selected{{ end }} {{ if eq $prefix $.Container.Series }}selected{{ end }}
>{{ $prefix }} &mdash; {{ $desc }}</option> >{{ $prefix }} &mdash; {{ $desc }}</option>
{{ end }} {{ end }}
</select> </select>
</div> </div>
<div> <div>
<label for=parent>Nadobal:</label> <label for=parent>Nadobal:</label>
<input type=text name=parent id=parent value="{{ .Parent }}"> <input type=text name=parent id=parent value="{{ .Container.Parent }}">
</div> </div>
<input type=submit value="Uložit"> <input type=submit value="Uložit">
</footer> </footer>
@ -54,7 +55,6 @@
<select name=series id=series> <select name=series id=series>
{{ range $prefix, $desc := .AllSeries }} {{ range $prefix, $desc := .AllSeries }}
<option value="{{ $prefix }}" <option value="{{ $prefix }}"
{{ if eq $prefix $.Series }}selected{{ end }}
>{{ $prefix }} &mdash; {{ $desc }}</option> >{{ $prefix }} &mdash; {{ $desc }}</option>
{{ end }} {{ end }}
</select> </select>
@ -74,7 +74,7 @@
{{ range .Children }} {{ range .Children }}
<section> <section>
<header> <header>
<h3><a href="/container?id={{ .Id }}">{{ .Id }}</a></h3> <h3><a href="/?id={{ .Id }}">{{ .Id }}</a></h3>
<form method=post action="/label?id={{ .Id }}"> <form method=post action="/label?id={{ .Id }}">
<input type=submit value="Vytisknout štítek"> <input type=submit value="Vytisknout štítek">
</form> </form>
@ -85,6 +85,12 @@
{{ if .Description }} {{ if .Description }}
<p>{{ .Description }} <p>{{ .Description }}
{{ end }} {{ end }}
{{ if .Children }}
<p>
{{ range .Children }}
<a href="/?id={{ .Id }}">{{ .Id }}</a>
{{ end }}
{{ end }}
</section> </section>
{{ else }} {{ else }}
<p>Obal je prázdný. <p>Obal je prázdný.

View File

@ -13,6 +13,8 @@ type Series struct {
Description string // what kind of containers this is for Description string // what kind of containers this is for
} }
type ContainerId string
type Container struct { type Container struct {
Series string // PK: what series does this belong to Series string // PK: what series does this belong to
Number uint // PK: order within the series Number uint // PK: order within the series
@ -20,12 +22,15 @@ type Container struct {
Description string // description and/or contents of this container Description string // description and/or contents of this container
} }
type ContainerId string
func (c *Container) Id() ContainerId { func (c *Container) Id() ContainerId {
return ContainerId(fmt.Sprintf("%s%s%d", db.Prefix, c.Series, c.Number)) return ContainerId(fmt.Sprintf("%s%s%d", db.Prefix, c.Series, c.Number))
} }
func (c *Container) Children() []*Container {
// TODO: Sort this by Id, or maybe even return a map[string]*Container.
return indexChildren[c.Id()]
}
type Database struct { type Database struct {
Password string // password for web users Password string // password for web users
Prefix string // prefix for all container IDs Prefix string // prefix for all container IDs

View File

@ -92,34 +92,23 @@ func handleContainer(w http.ResponseWriter, r *http.Request) {
allSeries[s.Prefix] = s.Description allSeries[s.Prefix] = s.Description
} }
var container *Container
children := []*Container{} children := []*Container{}
id := ContainerId(r.FormValue("id"))
description := ""
series := ""
parent := ContainerId("")
if id == "" { if id := ContainerId(r.FormValue("id")); id == "" {
children = indexChildren[id] children = indexChildren[""]
} else if container, ok := indexContainer[id]; ok { } else if c, ok := indexContainer[id]; ok {
children = indexChildren[id] children = c.Children()
description = container.Description container = c
series = container.Series
parent = container.Parent
} }
params := struct { params := struct {
Id ContainerId Container *Container
Description string
Children []*Container Children []*Container
Series string
Parent ContainerId
AllSeries map[string]string AllSeries map[string]string
}{ }{
Id: id, Container: container,
Description: description,
Children: children, Children: children,
Series: series,
Parent: parent,
AllSeries: allSeries, AllSeries: allSeries,
} }
@ -171,6 +160,7 @@ func handleSearch(w http.ResponseWriter, r *http.Request) {
_ = query _ = query
// TODO: Query the database for exact matches and fulltext. // TODO: Query the database for exact matches and fulltext.
// - Will want to show the full path from the root "" container.
params := struct{}{} params := struct{}{}