search_entries.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui // import "miniflux.app/ui"
  5. import (
  6. "net/http"
  7. "miniflux.app/http/request"
  8. "miniflux.app/http/response/html"
  9. "miniflux.app/http/route"
  10. "miniflux.app/model"
  11. "miniflux.app/ui/session"
  12. "miniflux.app/ui/view"
  13. )
  14. // ShowSearchEntries shows all entries for the given feed.
  15. func (c *Controller) ShowSearchEntries(w http.ResponseWriter, r *http.Request) {
  16. user, err := c.store.UserByID(request.UserID(r))
  17. if err != nil {
  18. html.ServerError(w, err)
  19. return
  20. }
  21. searchQuery := request.QueryStringParam(r, "q", "")
  22. offset := request.QueryIntParam(r, "offset", 0)
  23. builder := c.store.NewEntryQueryBuilder(user.ID)
  24. builder.WithSearchQuery(searchQuery)
  25. builder.WithoutStatus(model.EntryStatusRemoved)
  26. builder.WithOrder(model.DefaultSortingOrder)
  27. builder.WithDirection(user.EntryDirection)
  28. builder.WithOffset(offset)
  29. builder.WithLimit(nbItemsPerPage)
  30. entries, err := builder.GetEntries()
  31. if err != nil {
  32. html.ServerError(w, err)
  33. return
  34. }
  35. count, err := builder.CountEntries()
  36. if err != nil {
  37. html.ServerError(w, err)
  38. return
  39. }
  40. sess := session.New(c.store, request.SessionID(r))
  41. view := view.New(c.tpl, r, sess)
  42. pagination := c.getPagination(route.Path(c.router, "searchEntries"), count, offset)
  43. pagination.SearchQuery = searchQuery
  44. view.Set("searchQuery", searchQuery)
  45. view.Set("entries", entries)
  46. view.Set("total", count)
  47. view.Set("pagination", pagination)
  48. view.Set("menu", "search")
  49. view.Set("user", user)
  50. view.Set("countUnread", c.store.CountUnreadEntries(user.ID))
  51. view.Set("countErrorFeeds", c.store.CountErrorFeeds(user.ID))
  52. view.Set("hasSaveEntry", c.store.HasSaveEntry(user.ID))
  53. html.OK(w, r, view.Render("search_entries"))
  54. }