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)