sklad: cleanup, add comment
Child containers now show a linear list of subcontainers.
This commit is contained in:
parent
fbb76679f3
commit
3d98454543
|
@ -1,22 +1,23 @@
|
|||
{{ define "Title" }}{{ or .Id "Obaly" }}{{ end }}
|
||||
{{ define "Title" }}{{/*
|
||||
*/}}{{ if .Container }}{{ .Container.Id }}{{ else }}Obaly{{ end }}{{ end }}
|
||||
{{ define "Content" }}
|
||||
|
||||
{{ if .Id }}
|
||||
{{ if .Container }}
|
||||
|
||||
<section>
|
||||
<header>
|
||||
<h2>{{ .Id }}</h2>
|
||||
<form method=post action="/label?id={{ .Id }}">
|
||||
<h2>{{ .Container.Id }}</h2>
|
||||
<form method=post action="/label?id={{ .Container.Id }}">
|
||||
<input type=submit value="Vytisknout štítek">
|
||||
</form>
|
||||
<form method=post action="/?id={{ .Id }}&remove">
|
||||
<form method=post action="/?id={{ .Container.Id }}&remove">
|
||||
<input type=submit value="Odstranit">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<form method=post action="/?id={{ .Id }}">
|
||||
<form method=post action="/?id={{ .Container.Id }}">
|
||||
<textarea name=description rows=5>
|
||||
{{ .Description }}
|
||||
{{ .Container.Description }}
|
||||
</textarea>
|
||||
<footer>
|
||||
<div>
|
||||
|
@ -24,14 +25,14 @@
|
|||
<select name=series id=series>
|
||||
{{ range $prefix, $desc := .AllSeries }}
|
||||
<option value="{{ $prefix }}"
|
||||
{{ if eq $prefix $.Series }}selected{{ end }}
|
||||
{{ if eq $prefix $.Container.Series }}selected{{ end }}
|
||||
>{{ $prefix }} — {{ $desc }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<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>
|
||||
<input type=submit value="Uložit">
|
||||
</footer>
|
||||
|
@ -54,7 +55,6 @@
|
|||
<select name=series id=series>
|
||||
{{ range $prefix, $desc := .AllSeries }}
|
||||
<option value="{{ $prefix }}"
|
||||
{{ if eq $prefix $.Series }}selected{{ end }}
|
||||
>{{ $prefix }} — {{ $desc }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
|
@ -74,7 +74,7 @@
|
|||
{{ range .Children }}
|
||||
<section>
|
||||
<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 }}">
|
||||
<input type=submit value="Vytisknout štítek">
|
||||
</form>
|
||||
|
@ -85,6 +85,12 @@
|
|||
{{ if .Description }}
|
||||
<p>{{ .Description }}
|
||||
{{ end }}
|
||||
{{ if .Children }}
|
||||
<p>
|
||||
{{ range .Children }}
|
||||
<a href="/?id={{ .Id }}">{{ .Id }}</a>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</section>
|
||||
{{ else }}
|
||||
<p>Obal je prázdný.
|
||||
|
|
|
@ -13,6 +13,8 @@ type Series struct {
|
|||
Description string // what kind of containers this is for
|
||||
}
|
||||
|
||||
type ContainerId string
|
||||
|
||||
type Container struct {
|
||||
Series string // PK: what series does this belong to
|
||||
Number uint // PK: order within the series
|
||||
|
@ -20,12 +22,15 @@ type Container struct {
|
|||
Description string // description and/or contents of this container
|
||||
}
|
||||
|
||||
type ContainerId string
|
||||
|
||||
func (c *Container) Id() ContainerId {
|
||||
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 {
|
||||
Password string // password for web users
|
||||
Prefix string // prefix for all container IDs
|
||||
|
|
|
@ -92,34 +92,23 @@ func handleContainer(w http.ResponseWriter, r *http.Request) {
|
|||
allSeries[s.Prefix] = s.Description
|
||||
}
|
||||
|
||||
var container *Container
|
||||
children := []*Container{}
|
||||
id := ContainerId(r.FormValue("id"))
|
||||
description := ""
|
||||
series := ""
|
||||
parent := ContainerId("")
|
||||
|
||||
if id == "" {
|
||||
children = indexChildren[id]
|
||||
} else if container, ok := indexContainer[id]; ok {
|
||||
children = indexChildren[id]
|
||||
description = container.Description
|
||||
series = container.Series
|
||||
parent = container.Parent
|
||||
if id := ContainerId(r.FormValue("id")); id == "" {
|
||||
children = indexChildren[""]
|
||||
} else if c, ok := indexContainer[id]; ok {
|
||||
children = c.Children()
|
||||
container = c
|
||||
}
|
||||
|
||||
params := struct {
|
||||
Id ContainerId
|
||||
Description string
|
||||
Container *Container
|
||||
Children []*Container
|
||||
Series string
|
||||
Parent ContainerId
|
||||
AllSeries map[string]string
|
||||
}{
|
||||
Id: id,
|
||||
Description: description,
|
||||
Container: container,
|
||||
Children: children,
|
||||
Series: series,
|
||||
Parent: parent,
|
||||
AllSeries: allSeries,
|
||||
}
|
||||
|
||||
|
@ -171,6 +160,7 @@ func handleSearch(w http.ResponseWriter, r *http.Request) {
|
|||
_ = query
|
||||
|
||||
// TODO: Query the database for exact matches and fulltext.
|
||||
// - Will want to show the full path from the root "" container.
|
||||
|
||||
params := struct{}{}
|
||||
|
||||
|
|
Loading…
Reference in New Issue