2018-04-29 19:35:04 -04:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-10-07 21:42:43 -04:00
|
|
|
package ui // import "miniflux.app/ui"
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/http/request"
|
|
|
|
"miniflux.app/http/response/html"
|
|
|
|
"miniflux.app/http/route"
|
|
|
|
"miniflux.app/model"
|
|
|
|
"miniflux.app/ui/session"
|
|
|
|
"miniflux.app/ui/view"
|
2018-04-29 19:35:04 -04:00
|
|
|
)
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
func (h *handler) showFeedEntriesPage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
user, err := h.store.UserByID(request.UserID(r))
|
2018-04-29 19:35:04 -04:00
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-09-24 00:02:26 -04:00
|
|
|
feedID := request.RouteInt64Param(r, "feedID")
|
2018-11-11 14:28:29 -05:00
|
|
|
feed, err := h.store.FeedByID(user.ID, feedID)
|
2018-04-29 19:35:04 -04:00
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if feed == nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.NotFound(w, r)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
offset := request.QueryIntParam(r, "offset", 0)
|
2018-11-11 14:28:29 -05:00
|
|
|
builder := h.store.NewEntryQueryBuilder(user.ID)
|
2018-04-29 19:35:04 -04:00
|
|
|
builder.WithFeedID(feed.ID)
|
2018-12-14 03:54:25 -05:00
|
|
|
builder.WithStatus(model.EntryStatusUnread)
|
2023-06-19 17:00:10 -04:00
|
|
|
builder.WithSorting(user.EntryOrder, user.EntryDirection)
|
2018-04-29 19:35:04 -04:00
|
|
|
builder.WithOffset(offset)
|
2020-07-08 19:24:54 -04:00
|
|
|
builder.WithLimit(user.EntriesPerPage)
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
entries, err := builder.GetEntries()
|
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
count, err := builder.CountEntries()
|
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
sess := session.New(h.store, request.SessionID(r))
|
|
|
|
view := view.New(h.tpl, r, sess)
|
2018-04-29 19:35:04 -04:00
|
|
|
view.Set("feed", feed)
|
|
|
|
view.Set("entries", entries)
|
|
|
|
view.Set("total", count)
|
2020-07-08 19:24:54 -04:00
|
|
|
view.Set("pagination", getPagination(route.Path(h.router, "feedEntries", "feedID", feed.ID), count, offset, user.EntriesPerPage))
|
2018-04-29 19:35:04 -04:00
|
|
|
view.Set("menu", "feeds")
|
|
|
|
view.Set("user", user)
|
2018-11-11 14:28:29 -05:00
|
|
|
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
2020-09-27 19:01:06 -04:00
|
|
|
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
2018-11-11 14:28:29 -05:00
|
|
|
view.Set("hasSaveEntry", h.store.HasSaveEntry(user.ID))
|
2018-12-14 03:54:25 -05:00
|
|
|
view.Set("showOnlyUnreadEntries", true)
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2018-07-06 23:39:28 -04:00
|
|
|
html.OK(w, r, view.Render("feed_entries"))
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|