From 5c38688783fec13fb6e387547bc5176548394d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Thu, 29 Aug 2024 14:27:10 +0200 Subject: [PATCH] feat: add button to show only starred entries per category fixes #1468 --- internal/locale/translations/de_DE.json | 1 + internal/locale/translations/en_US.json | 1 + .../templates/views/category_entries.html | 13 ++++ internal/ui/category_entries_starred.go | 71 +++++++++++++++++++ internal/ui/ui.go | 1 + 5 files changed, 87 insertions(+) create mode 100644 internal/ui/category_entries_starred.go diff --git a/internal/locale/translations/de_DE.json b/internal/locale/translations/de_DE.json index 3de1e04e..c8debd4e 100644 --- a/internal/locale/translations/de_DE.json +++ b/internal/locale/translations/de_DE.json @@ -41,6 +41,7 @@ "menu.mark_all_as_read": "Alle als gelesen markieren", "menu.show_all_entries": "Zeige alle Artikel", "menu.show_only_unread_entries": "Nur ungelesene Artikel anzeigen", + "menu.show_only_starred_entries": "Nur markierte Artikel anzeigen", "menu.refresh_feed": "Aktualisieren", "menu.refresh_all_feeds": "Alle Abonnements im Hintergrund aktualisieren", "menu.edit_feed": "Bearbeiten", diff --git a/internal/locale/translations/en_US.json b/internal/locale/translations/en_US.json index 87c5af58..1af4ed0b 100644 --- a/internal/locale/translations/en_US.json +++ b/internal/locale/translations/en_US.json @@ -40,6 +40,7 @@ "menu.mark_page_as_read": "Mark this page as read", "menu.mark_all_as_read": "Mark all as read", "menu.show_all_entries": "Show all entries", + "menu.show_only_starred_entries": "Show only starred entries", "menu.show_only_unread_entries": "Show only unread entries", "menu.refresh_feed": "Refresh", "menu.refresh_all_feeds": "Refresh all feeds in the background", diff --git a/internal/template/templates/views/category_entries.html b/internal/template/templates/views/category_entries.html index a610bf61..19007f3e 100644 --- a/internal/template/templates/views/category_entries.html +++ b/internal/template/templates/views/category_entries.html @@ -41,10 +41,23 @@
  • {{ icon "show-all-entries" }}{{ t "menu.show_all_entries" }}
  • +
  • + {{ icon "star" }}{{ t "menu.show_only_starred_entries" }} +
  • + {{ else if .showOnlyStarredEntries }} +
  • + {{ icon "show-unread-entries" }}{{ t "menu.show_only_unread_entries" }} +
  • +
  • + {{ icon "show-all-entries" }}{{ t "menu.show_all_entries" }} +
  • {{ else }}
  • {{ icon "show-unread-entries" }}{{ t "menu.show_only_unread_entries" }}
  • +
  • + {{ icon "star" }}{{ t "menu.show_only_starred_entries" }} +
  • {{ end }}
  • {{ icon "feeds" }}{{ t "menu.feeds" }} diff --git a/internal/ui/category_entries_starred.go b/internal/ui/category_entries_starred.go new file mode 100644 index 00000000..41f9bd46 --- /dev/null +++ b/internal/ui/category_entries_starred.go @@ -0,0 +1,71 @@ +// 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" + + "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) showCategoryEntriesStarredPage(w http.ResponseWriter, r *http.Request) { + user, err := h.store.UserByID(request.UserID(r)) + if err != nil { + html.ServerError(w, r, err) + return + } + + categoryID := request.RouteInt64Param(r, "categoryID") + category, err := h.store.Category(request.UserID(r), categoryID) + if err != nil { + html.ServerError(w, r, err) + return + } + + if category == nil { + html.NotFound(w, r) + return + } + + offset := request.QueryIntParam(r, "offset", 0) + builder := h.store.NewEntryQueryBuilder(user.ID) + builder.WithCategoryID(category.ID) + builder.WithSorting(user.EntryOrder, user.EntryDirection) + builder.WithoutStatus(model.EntryStatusRemoved) + builder.WithStarred(true) + 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("category", category) + view.Set("total", count) + view.Set("entries", entries) + view.Set("pagination", getPagination(route.Path(h.router, "categoryEntriesStarred", "categoryID", category.ID), count, offset, user.EntriesPerPage)) + view.Set("menu", "categories") + 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("showOnlyStarredEntries", true) + + html.OK(w, r, view.Render("category_entries")) +} diff --git a/internal/ui/ui.go b/internal/ui/ui.go index d6641c01..b0cbd57a 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -88,6 +88,7 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) { uiRouter.HandleFunc("/category/{categoryID}/entries", handler.showCategoryEntriesPage).Name("categoryEntries").Methods(http.MethodGet) uiRouter.HandleFunc("/category/{categoryID}/entries/refresh", handler.refreshCategoryEntriesPage).Name("refreshCategoryEntriesPage").Methods(http.MethodGet) uiRouter.HandleFunc("/category/{categoryID}/entries/all", handler.showCategoryEntriesAllPage).Name("categoryEntriesAll").Methods(http.MethodGet) + uiRouter.HandleFunc("/category/{categoryID}/entries/starred", handler.showCategoryEntriesStarredPage).Name("categoryEntriesStarred").Methods(http.MethodGet) uiRouter.HandleFunc("/category/{categoryID}/edit", handler.showEditCategoryPage).Name("editCategory").Methods(http.MethodGet) uiRouter.HandleFunc("/category/{categoryID}/update", handler.updateCategory).Name("updateCategory").Methods(http.MethodPost) uiRouter.HandleFunc("/category/{categoryID}/remove", handler.removeCategory).Name("removeCategory").Methods(http.MethodPost)