history_entries.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2017 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/context"
  8. "miniflux.app/http/request"
  9. "miniflux.app/http/response/html"
  10. "miniflux.app/http/route"
  11. "miniflux.app/model"
  12. "miniflux.app/ui/session"
  13. "miniflux.app/ui/view"
  14. )
  15. // ShowHistoryPage renders the page with all read entries.
  16. func (c *Controller) ShowHistoryPage(w http.ResponseWriter, r *http.Request) {
  17. ctx := context.New(r)
  18. user, err := c.store.UserByID(ctx.UserID())
  19. if err != nil {
  20. html.ServerError(w, err)
  21. return
  22. }
  23. offset := request.QueryIntParam(r, "offset", 0)
  24. builder := c.store.NewEntryQueryBuilder(user.ID)
  25. builder.WithStatus(model.EntryStatusRead)
  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, ctx)
  41. view := view.New(c.tpl, ctx, sess)
  42. view.Set("entries", entries)
  43. view.Set("total", count)
  44. view.Set("pagination", c.getPagination(route.Path(c.router, "history"), count, offset))
  45. view.Set("menu", "history")
  46. view.Set("user", user)
  47. view.Set("countUnread", c.store.CountUnreadEntries(user.ID))
  48. view.Set("countErrorFeeds", c.store.CountErrorFeeds(user.ID))
  49. view.Set("hasSaveEntry", c.store.HasSaveEntry(user.ID))
  50. html.OK(w, r, view.Render("history_entries"))
  51. }