diff --git a/admin.go b/admin.go index f19ef17..f8e7047 100644 --- a/admin.go +++ b/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) } } diff --git a/templates/new.html b/templates/new.html index 981c622..9e771d7 100644 --- a/templates/new.html +++ b/templates/new.html @@ -2,15 +2,17 @@
Found {{.Found}} books.
-{{with .Books}} - {{range .}} +{{range .Books}} + {{$titleFound := .TitleFound}} + {{$authorFound := .AuthorFound}} + {{with .B}}{{if .CoverSmall}}{{end}}
{{.Title}}
- {{if .Author}}Author: {{range .Author}}{{.}}, {{end}}
{{end}}
+
{{.Title}} ({{$titleFound}})
+ {{if .Author}}Author: {{range .Author}}{{.}}, {{end}} ({{$authorFound}})
{{end}}
{{if .Publisher}}Publisher: {{.Publisher}}
{{end}}
{{if .Subject}}Tags: {{range .Subject}}{{.}}, {{end}}
{{end}}
{{if .Date}}Date: {{.Date}}
{{end}}
diff --git a/trantor.go b/trantor.go
index 896fd77..457a45f 100644
--- a/trantor.go
+++ b/trantor.go
@@ -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))