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 @@ <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}} 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))