Skip to content

Commit

Permalink
Fill drop down with already seen record classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bittersweet committed Oct 11, 2015
1 parent 2245bc7 commit 1f5c01d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 11 additions & 1 deletion endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,22 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {
func handleNew(w http.ResponseWriter, r *http.Request) {
defer trackTime(time.Now(), "handleNew")

classes := []string{}
err := db.Select(&classes, "SELECT distinct(class) FROM incoming")
if err != nil {
log.Fatal("db.Select incoming ", err)
}

t, err := template.ParseFiles("templates/new.html")
if err != nil {
log.Fatal("ParseFiles", err)
}

err = t.Execute(w, nil)
data := map[string]interface{}{
"classes": classes,
}

err = t.Execute(w, data)
if err != nil {
log.Fatal("t.Execute", err)
}
Expand Down
5 changes: 3 additions & 2 deletions templates/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
</select>
<br><br>
<select name="class">
<option value="User">User</option>
<option value="Review">Review</option>
{{ range $class := .classes }}
<option value="{{$class}}">{{$class}}</option>
{{ end }}
</select>
<br><br>
<textarea rows="4" cols="50" name="template" id="template"></textarea>
Expand Down

0 comments on commit 1f5c01d

Please sign in to comment.