GET categories returns total_unread & feed_count
This commit is contained in:
parent
b13c7e328a
commit
fa3de272e8
4 changed files with 17 additions and 8 deletions
|
@ -97,12 +97,20 @@ func (h *handler) markCategoryAsRead(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (h *handler) getCategories(w http.ResponseWriter, r *http.Request) {
|
||||
categories, err := h.store.Categories(request.UserID(r))
|
||||
var categories model.Categories
|
||||
var err error
|
||||
includeCounts := request.QueryStringParam(r, "counts", "false")
|
||||
|
||||
if includeCounts == "true" {
|
||||
categories, err = h.store.CategoriesWithFeedCount(request.UserID(r))
|
||||
} else {
|
||||
categories, err = h.store.Categories(request.UserID(r))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
json.OK(w, r, categories)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ type Category struct {
|
|||
Title string `json:"title"`
|
||||
UserID int64 `json:"user_id"`
|
||||
HideGlobally bool `json:"hide_globally"`
|
||||
FeedCount int `json:"-"`
|
||||
TotalUnread int `json:"-"`
|
||||
FeedCount *int `json:"feed_count,omitempty"`
|
||||
TotalUnread *int `json:"total_unread,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Category) String() string {
|
||||
|
|
|
@ -107,6 +107,7 @@ func (f *funcMap) Map() template.FuncMap {
|
|||
"nonce": func() string {
|
||||
return crypto.GenerateRandomStringHex(16)
|
||||
},
|
||||
"deRef": func(i *int) int { return *i },
|
||||
|
||||
// These functions are overrode at runtime after the parsing.
|
||||
"elapsed": func(timezone string, t time.Time) string {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
{{ else }}
|
||||
<div class="items">
|
||||
{{ range .categories }}
|
||||
<article role="article" class="item category-item {{if gt .TotalUnread 0 }} category-has-unread{{end}}">
|
||||
<article role="article" class="item category-item {{if gt (deRef .TotalUnread) 0 }} category-has-unread{{end}}">
|
||||
<div class="item-header" dir="auto">
|
||||
<span class="item-title">
|
||||
<a href="{{ route "categoryEntries" "categoryID" .ID }}">{{ .Title }}</a>
|
||||
|
@ -25,7 +25,7 @@
|
|||
<div class="item-meta">
|
||||
<ul class="item-meta-info">
|
||||
<li class="item-meta-info-feed-count">
|
||||
{{ if eq .FeedCount 0 }}{{ t "page.categories.no_feed" }}{{ else }}{{ plural "page.categories.feed_count" .FeedCount .FeedCount }}{{ end }}
|
||||
{{ if eq (deRef .FeedCount) 0 }}{{ t "page.categories.no_feed" }}{{ else }}{{ plural "page.categories.feed_count" (deRef .FeedCount) (deRef .FeedCount) }}{{ end }}
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="item-meta-icons">
|
||||
|
@ -38,7 +38,7 @@
|
|||
<li class="item-meta-icons-edit">
|
||||
<a href="{{ route "editCategory" "categoryID" .ID }}">{{ icon "edit" }}<span class="icon-label">{{ t "menu.edit_category" }}</span></a>
|
||||
</li>
|
||||
{{ if eq .FeedCount 0 }}
|
||||
{{ if eq (deRef .FeedCount) 0 }}
|
||||
<li class="item-meta-icons-delete">
|
||||
<a href="#"
|
||||
data-confirm="true"
|
||||
|
@ -49,7 +49,7 @@
|
|||
data-url="{{ route "removeCategory" "categoryID" .ID }}">{{ icon "delete" }}<span class="icon-label">{{ t "action.remove" }}</span></a>
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ if gt .TotalUnread 0 }}
|
||||
{{ if gt (deRef .TotalUnread) 0 }}
|
||||
<li class="item-meta-icons-mark-as-read">
|
||||
<a href="#"
|
||||
data-confirm="true"
|
||||
|
|
Loading…
Reference in a new issue