Skip to content

Commit

Permalink
feat: add button to show only starred entries per category
Browse files Browse the repository at this point in the history
fixes #1468
  • Loading branch information
kmein committed Aug 29, 2024
1 parent 8708a10 commit a3cb886
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/locale/translations/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions internal/template/templates/views/category_entries.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ <h1 id="page-header-title" dir="auto">
{{ if .showOnlyUnreadEntries }}
<li>
<a class="page-link" href="{{ route "categoryEntriesAll" "categoryID" .category.ID }}">{{ icon "show-all-entries" }}{{ t "menu.show_all_entries" }}</a>
<a class="page-link" href="{{ route "categoryEntriesStarred" "categoryID" .category.ID }}">{{ icon "star" }}{{ t "menu.show_only_starred_entries" }}</a>
</li>
{{ else if .showOnlyStarredEntries }}
<li>
<a class="page-link" href="{{ route "categoryEntries" "categoryID" .category.ID }}">{{ icon "show-unread-entries" }}{{ t "menu.show_only_unread_entries" }}</a>
<a class="page-link" href="{{ route "categoryEntriesAll" "categoryID" .category.ID }}">{{ icon "show-all-entries" }}{{ t "menu.show_all_entries" }}</a>
</li>
{{ else }}
<li>
<a class="page-link" href="{{ route "categoryEntries" "categoryID" .category.ID }}">{{ icon "show-unread-entries" }}{{ t "menu.show_only_unread_entries" }}</a>
<a class="page-link" href="{{ route "categoryEntriesStarred" "categoryID" .category.ID }}">{{ icon "star" }}{{ t "menu.show_only_starred_entries" }}</a>
</li>
{{ end }}
<li>
Expand Down
71 changes: 71 additions & 0 deletions internal/ui/category_entries_starred.go
Original file line number Diff line number Diff line change
@@ -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"))
}
1 change: 1 addition & 0 deletions internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a3cb886

Please sign in to comment.