2018-04-30 01:35:04 +02: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-08 03:42:43 +02:00
|
|
|
package ui // import "miniflux.app/ui"
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-08-25 06:51:50 +02: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-30 01:35:04 +02:00
|
|
|
)
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
func (h *handler) showFeedEntriesPage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
user, err := h.store.UserByID(request.UserID(r))
|
2018-04-30 01:35:04 +02:00
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-09-24 06:02:26 +02:00
|
|
|
feedID := request.RouteInt64Param(r, "feedID")
|
2018-11-11 20:28:29 +01:00
|
|
|
feed, err := h.store.FeedByID(user.ID, feedID)
|
2018-04-30 01:35:04 +02:00
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if feed == nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
html.NotFound(w, r)
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
offset := request.QueryIntParam(r, "offset", 0)
|
2018-11-11 20:28:29 +01:00
|
|
|
builder := h.store.NewEntryQueryBuilder(user.ID)
|
2018-04-30 01:35:04 +02:00
|
|
|
builder.WithFeedID(feed.ID)
|
|
|
|
builder.WithoutStatus(model.EntryStatusRemoved)
|
|
|
|
builder.WithOrder(model.DefaultSortingOrder)
|
|
|
|
builder.WithDirection(user.EntryDirection)
|
|
|
|
builder.WithOffset(offset)
|
|
|
|
builder.WithLimit(nbItemsPerPage)
|
|
|
|
|
|
|
|
entries, err := builder.GetEntries()
|
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
count, err := builder.CountEntries()
|
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
sess := session.New(h.store, request.SessionID(r))
|
|
|
|
view := view.New(h.tpl, r, sess)
|
2018-04-30 01:35:04 +02:00
|
|
|
view.Set("feed", feed)
|
|
|
|
view.Set("entries", entries)
|
|
|
|
view.Set("total", count)
|
2018-11-11 20:28:29 +01:00
|
|
|
view.Set("pagination", getPagination(route.Path(h.router, "feedEntries", "feedID", feed.ID), count, offset))
|
2018-04-30 01:35:04 +02:00
|
|
|
view.Set("menu", "feeds")
|
|
|
|
view.Set("user", user)
|
2018-11-11 20:28:29 +01:00
|
|
|
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
|
|
|
view.Set("countErrorFeeds", h.store.CountErrorFeeds(user.ID))
|
|
|
|
view.Set("hasSaveEntry", h.store.HasSaveEntry(user.ID))
|
2018-04-30 01:35:04 +02:00
|
|
|
|
2018-07-07 05:39:28 +02:00
|
|
|
html.OK(w, r, view.Render("feed_entries"))
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|