From e87780077926b419fb98c7d8e7c2a81525b6f617 Mon Sep 17 00:00:00 2001 From: Alexandros Kosiaris Date: Thu, 1 Jul 2021 20:25:58 +0300 Subject: [PATCH] ui: Expose markCategoryAsRead Why: It is nice to have the ability to mark an entire category as read in the UI. The API already exposes that functionality anyway, so for consistency reasons, expose it in the UI as well What: Add a new handler in the UI to markCategoryAsRead() and amend views and router to expose the functionality in the UI --- template/templates/views/categories.html | 11 ++++++ .../templates/views/category_entries.html | 9 +++++ ui/category_mark_as_read.go | 37 +++++++++++++++++++ ui/ui.go | 1 + 4 files changed, 58 insertions(+) create mode 100644 ui/category_mark_as_read.go diff --git a/template/templates/views/categories.html b/template/templates/views/categories.html index 00c77bd1..9d04d53e 100644 --- a/template/templates/views/categories.html +++ b/template/templates/views/categories.html @@ -49,6 +49,17 @@ data-url="{{ route "removeCategory" "categoryID" .ID }}">{{ icon "delete" }}{{ t "action.remove" }} {{ end }} + {{ if gt .TotalUnread 0 }} +
  • + {{ icon "read" }}{{ t "menu.mark_all_as_read" }} +
  • + {{ end }} diff --git a/template/templates/views/category_entries.html b/template/templates/views/category_entries.html index f4d76ae8..5aae2121 100644 --- a/template/templates/views/category_entries.html +++ b/template/templates/views/category_entries.html @@ -14,6 +14,15 @@ data-label-loading="{{ t "confirm.loading" }}" data-show-only-unread="{{ if .showOnlyUnreadEntries }}1{{ end }}">{{ t "menu.mark_page_as_read" }} +
  • + {{ t "menu.mark_all_as_read" }} +
  • {{ end }} {{ if .showOnlyUnreadEntries }}
  • diff --git a/ui/category_mark_as_read.go b/ui/category_mark_as_read.go new file mode 100644 index 00000000..e7f12e37 --- /dev/null +++ b/ui/category_mark_as_read.go @@ -0,0 +1,37 @@ +// 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. + +package ui // import "miniflux.app/ui" + +import ( + "net/http" + "time" + + "miniflux.app/http/request" + "miniflux.app/http/response/html" + "miniflux.app/http/route" +) + +func (h *handler) markCategoryAsRead(w http.ResponseWriter, r *http.Request) { + userID := request.UserID(r) + categoryID := request.RouteInt64Param(r, "categoryID") + + category, err := h.store.Category(userID, categoryID) + if err != nil { + html.ServerError(w, r, err) + return + } + + if category == nil { + html.NotFound(w, r) + return + } + + if err = h.store.MarkCategoryAsRead(userID, categoryID, time.Now()); err != nil { + html.ServerError(w, r, err) + return + } + + html.Redirect(w, r, route.Path(h.router, "categories")) +} diff --git a/ui/ui.go b/ui/ui.go index 5775427e..798de962 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -93,6 +93,7 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) { 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) + uiRouter.HandleFunc("/category/{categoryID}/mark-all-as-read", handler.markCategoryAsRead).Name("markCategoryAsRead").Methods(http.MethodPost) // Entry pages. uiRouter.HandleFunc("/entry/status", handler.updateEntriesStatus).Name("updateEntriesStatus").Methods(http.MethodPost)