Compare commits
	
		
			No commits in common. "3d98454543f4494fd267e851b48d58a05aea11dc" and "e003427f9f86b0b3898cca67b39a96e391fd1b16" have entirely different histories.
		
	
	
		
			3d98454543
			...
			e003427f9f
		
	
		
| @ -53,7 +53,7 @@ | ||||
| 	<a href=/series>Řady</a> | ||||
| 
 | ||||
| 	<form method=get action=/search> | ||||
| 	<input type=text name=q autofocus><input type=submit value="Hledat"> | ||||
| 	<input type=text name=q><input type=submit value="Hledat"> | ||||
| 	</form> | ||||
| 
 | ||||
| 	<form method=post action=/logout> | ||||
|  | ||||
| @ -1,23 +1,22 @@ | ||||
| {{ define "Title" }}{{/* | ||||
| */}}{{ if .Container }}{{ .Container.Id }}{{ else }}Obaly{{ end }}{{ end }} | ||||
| {{ define "Title" }}{{ or .Id "Obaly" }}{{ end }} | ||||
| {{ define "Content" }} | ||||
| 
 | ||||
| {{ if .Container }} | ||||
| {{ if .Id }} | ||||
| 
 | ||||
| <section> | ||||
| <header> | ||||
| 	<h2>{{ .Container.Id }}</h2> | ||||
| 	<form method=post action="/label?id={{ .Container.Id }}"> | ||||
| 	<h2>{{ .Id }}</h2> | ||||
| 	<form method=post action="/label?id={{ .Id }}"> | ||||
| 	<input type=submit value="Vytisknout štítek"> | ||||
| 	</form> | ||||
| 	<form method=post action="/?id={{ .Container.Id }}&remove"> | ||||
| 	<form method=post action="/?id={{ .Id }}&remove"> | ||||
| 	<input type=submit value="Odstranit"> | ||||
| 	</form> | ||||
| </header> | ||||
| 
 | ||||
| <form method=post action="/?id={{ .Container.Id }}"> | ||||
| <form method=post action="/?id={{ .Id }}"> | ||||
| <textarea name=description rows=5> | ||||
| {{ .Container.Description }} | ||||
| {{ .Description }} | ||||
| </textarea> | ||||
| <footer> | ||||
| 	<div> | ||||
| @ -25,14 +24,14 @@ | ||||
| 		<select name=series id=series> | ||||
| {{ range $prefix, $desc := .AllSeries }} | ||||
| 			<option value="{{ $prefix }}" | ||||
| 				{{ if eq $prefix $.Container.Series }}selected{{ end }} | ||||
| 				{{ if eq $prefix $.Series }}selected{{ end }} | ||||
| 				>{{ $prefix }} — {{ $desc }}</option> | ||||
| {{ end }} | ||||
| 		</select> | ||||
| 	</div> | ||||
| 	<div> | ||||
| 		<label for=parent>Nadobal:</label> | ||||
| 		<input type=text name=parent id=parent value="{{ .Container.Parent }}"> | ||||
| 		<input type=text name=parent id=parent value="{{ .Parent }}"> | ||||
| 	</div> | ||||
| 	<input type=submit value="Uložit"> | ||||
| </footer> | ||||
| @ -55,6 +54,7 @@ | ||||
| 		<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="/?id={{ .Id }}">{{ .Id }}</a></h3> | ||||
| 	<h3><a href="/container?id={{ .Id }}">{{ .Id }}</a></h3> | ||||
| 	<form method=post action="/label?id={{ .Id }}"> | ||||
| 	<input type=submit value="Vytisknout štítek"> | ||||
| 	</form> | ||||
| @ -85,12 +85,6 @@ | ||||
| {{ 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,8 +13,6 @@ 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 | ||||
| @ -22,15 +20,12 @@ 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 | ||||
|  | ||||
| @ -6,7 +6,7 @@ | ||||
| 
 | ||||
| <form method=post> | ||||
| <label for=password>Heslo:</label> | ||||
| <input type=password name=password id=password autofocus | ||||
| <input type=password name=password id=password | ||||
| ><input type=submit value="Přihlásit"> | ||||
| </form> | ||||
| 
 | ||||
|  | ||||
| @ -92,23 +92,34 @@ 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 := ContainerId(r.FormValue("id")); id == "" { | ||||
| 		children = indexChildren[""] | ||||
| 	} else if c, ok := indexContainer[id]; ok { | ||||
| 		children = c.Children() | ||||
| 		container = c | ||||
| 	if id == "" { | ||||
| 		children = indexChildren[id] | ||||
| 	} else if container, ok := indexContainer[id]; ok { | ||||
| 		children = indexChildren[id] | ||||
| 		description = container.Description | ||||
| 		series = container.Series | ||||
| 		parent = container.Parent | ||||
| 	} | ||||
| 
 | ||||
| 	params := struct { | ||||
| 		Container *Container | ||||
| 		Id          ContainerId | ||||
| 		Description string | ||||
| 		Children    []*Container | ||||
| 		Series      string | ||||
| 		Parent      ContainerId | ||||
| 		AllSeries   map[string]string | ||||
| 	}{ | ||||
| 		Container: container, | ||||
| 		Id:          id, | ||||
| 		Description: description, | ||||
| 		Children:    children, | ||||
| 		Series:      series, | ||||
| 		Parent:      parent, | ||||
| 		AllSeries:   allSeries, | ||||
| 	} | ||||
| 
 | ||||
| @ -160,7 +171,6 @@ 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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user