Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Added sort parameter to pages
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Oct 21, 2017
1 parent c554b66 commit 33de809
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions modules/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,20 @@ func (s *Server) handleAuthor(w http.ResponseWriter, r *http.Request, p httprout
}

if aname != "" {
bl := s.Books.Filtered(func(book *models.Book) bool {
return book.Author != nil && book.Author.ID == p.ByName("id")
})
bl, _ = bl.SortBy("title-asc")
bl, _ = bl.SortBy(r.URL.Query().Get("sort"))

s.render.HTML(w, http.StatusOK, "author", map[string]interface{}{
"CurVersion": s.version,
"PageTitle": aname,
"ShowBar": true,
"ShowSearch": false,
"ShowViewSelector": true,
"Title": aname,
"Books": s.Books.Filtered(func(book *models.Book) bool {
return book.Author != nil && book.Author.ID == p.ByName("id")
}).Sorted(func(a, b *models.Book) bool {
return a.Title < b.Title
}),
"Books": bl,
})
return
}
Expand Down Expand Up @@ -375,6 +377,12 @@ func (s *Server) handleSeries(w http.ResponseWriter, r *http.Request, p httprout
}

if sname != "" {
bl := s.Books.Filtered(func(book *models.Book) bool {
return book.Series != nil && book.Series.ID == p.ByName("id")
})
bl, _ = bl.SortBy("seriesindex-asc")
bl, _ = bl.SortBy(r.URL.Query().Get("sort"))

s.render.HTML(w, http.StatusOK, "series", map[string]interface{}{
"CurVersion": s.version,
"PageTitle": sname,
Expand Down Expand Up @@ -406,14 +414,17 @@ func (s *Server) handleBookList(w http.ResponseWriter, r *http.Request, _ httpro
s.booksLock.RLock()
defer s.booksLock.RUnlock()

bl, _ := s.Books.SortBy("modified-desc")
bl, _ = bl.SortBy(r.URL.Query().Get("sort"))

s.render.HTML(w, http.StatusOK, "books", map[string]interface{}{
"CurVersion": s.version,
"PageTitle": "Books",
"ShowBar": true,
"ShowSearch": true,
"ShowViewSelector": true,
"Title": "",
"Books": s.Books,
"Books": bl,
})
}

Expand Down Expand Up @@ -455,6 +466,16 @@ func (s *Server) handleSearch(w http.ResponseWriter, r *http.Request, _ httprout
ql := strings.ToLower(q)

if len(q) != 0 {
bl := s.Books.Filtered(func(a *models.Book) bool {
matches := false
matches = matches || a.Author != nil && strings.Contains(strings.ToLower(a.Author.Name), ql)
matches = matches || strings.Contains(strings.ToLower(a.Title), ql)
matches = matches || a.Series != nil && strings.Contains(strings.ToLower(a.Series.Name), ql)
return matches
})
bl, _ = bl.SortBy("title-asc")
bl, _ = bl.SortBy(r.URL.Query().Get("sort"))

s.render.HTML(w, http.StatusOK, "search", map[string]interface{}{
"CurVersion": s.version,
"PageTitle": "Search Results",
Expand All @@ -463,13 +484,7 @@ func (s *Server) handleSearch(w http.ResponseWriter, r *http.Request, _ httprout
"ShowViewSelector": true,
"Title": "Search Results",
"Query": q,
"Books": s.Books.Filtered(func(a *models.Book) bool {
matches := false
matches = matches || a.Author != nil && strings.Contains(strings.ToLower(a.Author.Name), ql)
matches = matches || strings.Contains(strings.ToLower(a.Title), ql)
matches = matches || a.Series != nil && strings.Contains(strings.ToLower(a.Series.Name), ql)
return matches
}),
"Books": bl,
})
return
}
Expand Down

0 comments on commit 33de809

Please sign in to comment.