unread_entries.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // ShowUnreadPage render the page with all unread entries.
  15. func (c *Controller) ShowUnreadPage(w http.ResponseWriter, r *http.Request) {
  16. sess := session.New(c.store, request.SessionID(r))
  17. view := view.New(c.tpl, r, sess)
  18. user, err := c.store.UserByID(request.UserID(r))
  19. if err != nil {
  20. html.ServerError(w, r, err)
  21. return
  22. }
  23. offset := request.QueryIntParam(r, "offset", 0)
  24. builder := c.store.NewEntryQueryBuilder(user.ID)
  25. builder.WithStatus(model.EntryStatusUnread)
  26. countUnread, err := builder.CountEntries()
  27. if err != nil {
  28. html.ServerError(w, r, err)
  29. return
  30. }
  31. if offset >= countUnread {
  32. offset = 0
  33. }
  34. builder = c.store.NewEntryQueryBuilder(user.ID)
  35. builder.WithStatus(model.EntryStatusUnread)
  36. builder.WithOrder(model.DefaultSortingOrder)
  37. builder.WithDirection(user.EntryDirection)
  38. builder.WithOffset(offset)
  39. builder.WithLimit(nbItemsPerPage)
  40. entries, err := builder.GetEntries()
  41. if err != nil {
  42. html.ServerError(w, r, err)
  43. return
  44. }
  45. view.Set("entries", entries)
  46. view.Set("pagination", c.getPagination(route.Path(c.router, "unread"), countUnread, offset))
  47. view.Set("menu", "unread")
  48. view.Set("user", user)
  49. view.Set("countUnread", countUnread)
  50. view.Set("countErrorFeeds", c.store.CountErrorFeeds(user.ID))
  51. view.Set("hasSaveEntry", c.store.HasSaveEntry(user.ID))
  52. html.OK(w, r, view.Render("unread_entries"))
  53. }