diff options
Diffstat (limited to 'internal/ui')
-rw-r--r-- | internal/ui/entry_tag.go | 90 | ||||
-rw-r--r-- | internal/ui/tag_entries_all.go | 65 | ||||
-rw-r--r-- | internal/ui/ui.go | 4 |
3 files changed, 159 insertions, 0 deletions
diff --git a/internal/ui/entry_tag.go b/internal/ui/entry_tag.go new file mode 100644 index 00000000..cf153a8b --- /dev/null +++ b/internal/ui/entry_tag.go @@ -0,0 +1,90 @@ +// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package ui // import "miniflux.app/v2/internal/ui" + +import ( + "net/http" + "net/url" + + "miniflux.app/v2/internal/http/request" + "miniflux.app/v2/internal/http/response/html" + "miniflux.app/v2/internal/http/route" + "miniflux.app/v2/internal/model" + "miniflux.app/v2/internal/storage" + "miniflux.app/v2/internal/ui/session" + "miniflux.app/v2/internal/ui/view" +) + +func (h *handler) showTagEntryPage(w http.ResponseWriter, r *http.Request) { + user, err := h.store.UserByID(request.UserID(r)) + if err != nil { + html.ServerError(w, r, err) + return + } + + tagName, err := url.PathUnescape(request.RouteStringParam(r, "tagName")) + if err != nil { + html.ServerError(w, r, err) + return + } + entryID := request.RouteInt64Param(r, "entryID") + + builder := h.store.NewEntryQueryBuilder(user.ID) + builder.WithTags([]string{tagName}) + builder.WithEntryID(entryID) + builder.WithoutStatus(model.EntryStatusRemoved) + + entry, err := builder.GetEntry() + if err != nil { + html.ServerError(w, r, err) + return + } + + if entry == nil { + html.NotFound(w, r) + return + } + + if user.MarkReadOnView && entry.Status == model.EntryStatusUnread { + err = h.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusRead) + if err != nil { + html.ServerError(w, r, err) + return + } + + entry.Status = model.EntryStatusRead + } + + entryPaginationBuilder := storage.NewEntryPaginationBuilder(h.store, user.ID, entry.ID, user.EntryOrder, user.EntryDirection) + entryPaginationBuilder.WithTags([]string{tagName}) + prevEntry, nextEntry, err := entryPaginationBuilder.Entries() + if err != nil { + html.ServerError(w, r, err) + return + } + + nextEntryRoute := "" + if nextEntry != nil { + nextEntryRoute = route.Path(h.router, "tagEntry", "tagName", url.PathEscape(tagName), "entryID", nextEntry.ID) + } + + prevEntryRoute := "" + if prevEntry != nil { + prevEntryRoute = route.Path(h.router, "tagEntry", "tagName", url.PathEscape(tagName), "entryID", prevEntry.ID) + } + + sess := session.New(h.store, request.SessionID(r)) + view := view.New(h.tpl, r, sess) + view.Set("entry", entry) + view.Set("prevEntry", prevEntry) + view.Set("nextEntry", nextEntry) + view.Set("nextEntryRoute", nextEntryRoute) + view.Set("prevEntryRoute", prevEntryRoute) + view.Set("user", user) + view.Set("countUnread", h.store.CountUnreadEntries(user.ID)) + view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID)) + view.Set("hasSaveEntry", h.store.HasSaveEntry(user.ID)) + + html.OK(w, r, view.Render("entry")) +} diff --git a/internal/ui/tag_entries_all.go b/internal/ui/tag_entries_all.go new file mode 100644 index 00000000..a7f6fb02 --- /dev/null +++ b/internal/ui/tag_entries_all.go @@ -0,0 +1,65 @@ +// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package ui // import "miniflux.app/v2/internal/ui" + +import ( + "net/http" + "net/url" + + "miniflux.app/v2/internal/http/request" + "miniflux.app/v2/internal/http/response/html" + "miniflux.app/v2/internal/http/route" + "miniflux.app/v2/internal/model" + "miniflux.app/v2/internal/ui/session" + "miniflux.app/v2/internal/ui/view" +) + +func (h *handler) showTagEntriesAllPage(w http.ResponseWriter, r *http.Request) { + user, err := h.store.UserByID(request.UserID(r)) + if err != nil { + html.ServerError(w, r, err) + return + } + + tagName, err := url.PathUnescape(request.RouteStringParam(r, "tagName")) + if err != nil { + html.ServerError(w, r, err) + return + } + + offset := request.QueryIntParam(r, "offset", 0) + builder := h.store.NewEntryQueryBuilder(user.ID) + builder.WithoutStatus(model.EntryStatusRemoved) + builder.WithTags([]string{tagName}) + builder.WithSorting("status", "asc") + builder.WithSorting(user.EntryOrder, user.EntryDirection) + builder.WithOffset(offset) + builder.WithLimit(user.EntriesPerPage) + + entries, err := builder.GetEntries() + if err != nil { + html.ServerError(w, r, err) + return + } + + count, err := builder.CountEntries() + if err != nil { + html.ServerError(w, r, err) + return + } + + sess := session.New(h.store, request.SessionID(r)) + view := view.New(h.tpl, r, sess) + view.Set("tagName", tagName) + view.Set("total", count) + view.Set("entries", entries) + view.Set("pagination", getPagination(route.Path(h.router, "tagEntriesAll", "tagName", url.PathEscape(tagName)), count, offset, user.EntriesPerPage)) + view.Set("user", user) + view.Set("countUnread", h.store.CountUnreadEntries(user.ID)) + view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID)) + view.Set("hasSaveEntry", h.store.HasSaveEntry(user.ID)) + view.Set("showOnlyUnreadEntries", false) + + html.OK(w, r, view.Render("tag_entries")) +} diff --git a/internal/ui/ui.go b/internal/ui/ui.go index 6d8e729c..d6641c01 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -93,6 +93,10 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) { uiRouter.HandleFunc("/category/{categoryID}/remove", handler.removeCategory).Name("removeCategory").Methods(http.MethodPost) uiRouter.HandleFunc("/category/{categoryID}/mark-all-as-read", handler.markCategoryAsRead).Name("markCategoryAsRead").Methods(http.MethodPost) + // Tag pages. + uiRouter.HandleFunc("/tags/{tagName}/entries/all", handler.showTagEntriesAllPage).Name("tagEntriesAll").Methods(http.MethodGet) + uiRouter.HandleFunc("/tags/{tagName}/entry/{entryID}", handler.showTagEntryPage).Name("tagEntry").Methods(http.MethodGet) + // Entry pages. uiRouter.HandleFunc("/entry/status", handler.updateEntriesStatus).Name("updateEntriesStatus").Methods(http.MethodPost) uiRouter.HandleFunc("/entry/save/{entryID}", handler.saveEntry).Name("saveEntry").Methods(http.MethodPost) |