search_entries.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. func (h *handler) showSearchEntriesPage(w http.ResponseWriter, r *http.Request) {
  15. user, err := h.store.UserByID(request.UserID(r))
  16. if err != nil {
  17. html.ServerError(w, r, err)
  18. return
  19. }
  20. searchQuery := request.QueryStringParam(r, "q", "")
  21. offset := request.QueryIntParam(r, "offset", 0)
  22. builder := h.store.NewEntryQueryBuilder(user.ID)
  23. builder.WithSearchQuery(searchQuery)
  24. builder.WithoutStatus(model.EntryStatusRemoved)
  25. builder.WithOffset(offset)
  26. builder.WithLimit(user.EntriesPerPage)
  27. entries, err := builder.GetEntries()
  28. if err != nil {
  29. html.ServerError(w, r, err)
  30. return
  31. }
  32. count, err := builder.CountEntries()
  33. if err != nil {
  34. html.ServerError(w, r, err)
  35. return
  36. }
  37. sess := session.New(h.store, request.SessionID(r))
  38. view := view.New(h.tpl, r, sess)
  39. pagination := getPagination(route.Path(h.router, "searchEntries"), count, offset, user.EntriesPerPage)
  40. pagination.SearchQuery = searchQuery
  41. view.Set("searchQuery", searchQuery)
  42. view.Set("entries", entries)
  43. view.Set("total", count)
  44. view.Set("pagination", pagination)
  45. view.Set("menu", "search")
  46. view.Set("user", user)
  47. view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
  48. view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
  49. view.Set("hasSaveEntry", h.store.HasSaveEntry(user.ID))
  50. html.OK(w, r, view.Render("search_entries"))
  51. }