From 3d98454543f4494fd267e851b48d58a05aea11dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sun, 14 Apr 2019 19:12:31 +0200 Subject: sklad: cleanup, add comment Child containers now show a linear list of subcontainers. --- sklad/container.tmpl | 28 +++++++++++++++++----------- sklad/db.go | 9 +++++++-- sklad/main.go | 36 +++++++++++++----------------------- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/sklad/container.tmpl b/sklad/container.tmpl index cbc8ea4..4bacae8 100644 --- a/sklad/container.tmpl +++ b/sklad/container.tmpl @@ -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 }}
-

{{ .Id }}

-
+

{{ .Container.Id }}

+
-
+
-
+
@@ -24,14 +25,14 @@
- +
@@ -54,7 +55,6 @@ @@ -74,7 +74,7 @@ {{ range .Children }}
-

{{ .Id }}

+

{{ .Id }}

@@ -85,6 +85,12 @@ {{ if .Description }}

{{ .Description }} {{ end }} +{{ if .Children }} +

+{{ range .Children }} +{{ .Id }} +{{ end }} +{{ end }}

{{ else }}

Obal je prázdný. diff --git a/sklad/db.go b/sklad/db.go index 3420c23..300c1bd 100644 --- a/sklad/db.go +++ b/sklad/db.go @@ -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 diff --git a/sklad/main.go b/sklad/main.go index a2a7143..1a9442a 100644 --- a/sklad/main.go +++ b/sklad/main.go @@ -92,35 +92,24 @@ 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 - Children []*Container - Series string - Parent ContainerId - AllSeries map[string]string + Container *Container + Children []*Container + AllSeries map[string]string }{ - Id: id, - Description: description, - Children: children, - Series: series, - Parent: parent, - AllSeries: allSeries, + Container: container, + Children: children, + AllSeries: allSeries, } executeTemplate("container.tmpl", w, ¶ms) @@ -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{}{} -- cgit v1.2.3