Display the number of results on new page
This commit is contained in:
parent
61d301df5b
commit
a9749e7136
3 changed files with 20 additions and 8 deletions
16
admin.go
16
admin.go
|
@ -112,13 +112,18 @@ func saveHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request)
|
|||
}
|
||||
}
|
||||
|
||||
type newBook struct {
|
||||
TitleFound int
|
||||
AuthorFound int
|
||||
B Book
|
||||
}
|
||||
type newData struct {
|
||||
S Status
|
||||
Found int
|
||||
Books []Book
|
||||
Books []newBook
|
||||
}
|
||||
|
||||
func newHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request) {
|
||||
func newHandler(coll *mgo.Collection, booksColl *mgo.Collection) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if len(r.URL.Path) > len("/new/") {
|
||||
http.ServeFile(w, r, r.URL.Path[1:])
|
||||
|
@ -135,7 +140,12 @@ func newHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request) {
|
|||
var data newData
|
||||
data.S = GetStatus(w, r)
|
||||
data.Found = num
|
||||
data.Books = res
|
||||
data.Books = make([]newBook, num)
|
||||
for i, b := range res {
|
||||
data.Books[i].B = b
|
||||
_, data.Books[i].TitleFound, _ = GetBook(booksColl, buildQuery("title:" + b.Title), 1)
|
||||
_, data.Books[i].AuthorFound, _ = GetBook(booksColl, buildQuery("author:" + strings.Join(b.Author, " author:")), 1)
|
||||
}
|
||||
loadTemplate(w, "new", data)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,15 +2,17 @@
|
|||
|
||||
<p class="centered">Found {{.Found}} books.</p>
|
||||
|
||||
{{with .Books}}
|
||||
{{range .}}
|
||||
{{range .Books}}
|
||||
{{$titleFound := .TitleFound}}
|
||||
{{$authorFound := .AuthorFound}}
|
||||
{{with .B}}
|
||||
<div class="row">
|
||||
<div class="span1">
|
||||
<p class="pull-right">{{if .CoverSmall}}<img src="{{.CoverSmall}}" alt="{{.Title}}" />{{end}}</p>
|
||||
</div>
|
||||
<div class="span9">
|
||||
<p><a href="/search/?q=title:{{.Title}}"><strong>{{.Title}}</strong></a><br />
|
||||
{{if .Author}}<strong>Author:</strong> {{range .Author}}<a href="/search/?q=author:{{.}}">{{.}}</a>, {{end}}<br />{{end}}
|
||||
<p><a href="/search/?q=title:{{.Title}}"><strong>{{.Title}}</strong></a> <small>({{$titleFound}})</small><br />
|
||||
{{if .Author}}<strong>Author:</strong> {{range .Author}}<a href="/search/?q=author:{{.}}">{{.}}</a>, {{end}} <small>({{$authorFound}})</small><br />{{end}}
|
||||
{{if .Publisher}}<strong>Publisher:</strong> <a href="/search/?q=publisher:{{.Publisher}}">{{.Publisher}}</a><br />{{end}}
|
||||
{{if .Subject}}<strong>Tags:</strong> {{range .Subject}}<a href="/search/?q=subject:{{.}}">{{.}}</a>, {{end}}<br />{{end}}
|
||||
{{if .Date}}<strong>Date:</strong> {{.Date}}<br />{{end}}
|
||||
|
|
|
@ -137,7 +137,7 @@ func main() {
|
|||
http.HandleFunc("/upload/", uploadHandler(newColl))
|
||||
http.HandleFunc("/login/", loginHandler(userColl))
|
||||
http.HandleFunc("/logout/", logoutHandler)
|
||||
http.HandleFunc("/new/", newHandler(newColl))
|
||||
http.HandleFunc("/new/", newHandler(newColl, coll))
|
||||
http.HandleFunc("/delnew/", deleteHandler(newColl, "/new/"))
|
||||
http.HandleFunc("/store/", storeHandler(newColl, coll))
|
||||
http.HandleFunc("/read/", readHandler(coll))
|
||||
|
|
Reference in a new issue