From fad9ad2be4fc800f8710e2a498cc8f536af8827c Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 17 Nov 2019 19:44:12 -0800 Subject: Display list of feeds per category --- ui/category_feeds.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ ui/category_update.go | 2 +- ui/ui.go | 1 + 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 ui/category_feeds.go (limited to 'ui') diff --git a/ui/category_feeds.go b/ui/category_feeds.go new file mode 100644 index 0000000..202fc3e --- /dev/null +++ b/ui/category_feeds.go @@ -0,0 +1,52 @@ +// Copyright 2019 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. + +package ui // import "miniflux.app/ui" + +import ( + "net/http" + + "miniflux.app/http/request" + "miniflux.app/http/response/html" + "miniflux.app/ui/session" + "miniflux.app/ui/view" +) + +func (h *handler) showCategoryFeedsPage(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 + } + + feeds, err := h.store.FeedsByCategoryWithCounters(user.ID, categoryID) + 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("feeds", feeds) + view.Set("total", len(feeds)) + view.Set("menu", "categories") + view.Set("user", user) + view.Set("countUnread", h.store.CountUnreadEntries(user.ID)) + view.Set("countErrorFeeds", h.store.CountErrorFeeds(user.ID)) + + html.OK(w, r, view.Render("category_feeds")) +} diff --git a/ui/category_update.go b/ui/category_update.go index 026f991..591063a 100644 --- a/ui/category_update.go +++ b/ui/category_update.go @@ -66,5 +66,5 @@ func (h *handler) updateCategory(w http.ResponseWriter, r *http.Request) { return } - html.Redirect(w, r, route.Path(h.router, "categories")) + html.Redirect(w, r, route.Path(h.router, "categoryFeeds", "categoryID", categoryID)) } diff --git a/ui/ui.go b/ui/ui.go index dd1a9d8..dabc2fc 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -74,6 +74,7 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool, feedHa uiRouter.HandleFunc("/categories", handler.showCategoryListPage).Name("categories").Methods("GET") uiRouter.HandleFunc("/category/create", handler.showCreateCategoryPage).Name("createCategory").Methods("GET") uiRouter.HandleFunc("/category/save", handler.saveCategory).Name("saveCategory").Methods("POST") + uiRouter.HandleFunc("/category/{categoryID}/feeds", handler.showCategoryFeedsPage).Name("categoryFeeds").Methods("GET") uiRouter.HandleFunc("/category/{categoryID}/entries", handler.showCategoryEntriesPage).Name("categoryEntries").Methods("GET") uiRouter.HandleFunc("/category/{categoryID}/entries/all", handler.showCategoryEntriesAllPage).Name("categoryEntriesAll").Methods("GET") uiRouter.HandleFunc("/category/{categoryID}/edit", handler.showEditCategoryPage).Name("editCategory").Methods("GET") -- cgit v1.2.3