history_entries.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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
  5. import (
  6. "net/http"
  7. "github.com/miniflux/miniflux/http/context"
  8. "github.com/miniflux/miniflux/http/request"
  9. "github.com/miniflux/miniflux/http/response/html"
  10. "github.com/miniflux/miniflux/http/route"
  11. "github.com/miniflux/miniflux/model"
  12. "github.com/miniflux/miniflux/ui/session"
  13. "github.com/miniflux/miniflux/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("hasSaveEntry", c.store.HasSaveEntry(user.ID))
  49. html.OK(w, view.Render("history_entries"))
  50. }