From 1c9f0005763f73376d767639fd989d389b6f0e53 Mon Sep 17 00:00:00 2001 From: pennae Date: Sun, 25 Apr 2021 13:47:59 +0200 Subject: [PATCH] show #unread per category in category list, not #feeds the number of feeds in the category is currently displayed twice, and a lot less useful than the number of unread items in the category. --- locale/translations/de_DE.json | 1 + locale/translations/en_US.json | 3 ++- locale/translations/es_ES.json | 3 ++- locale/translations/fr_FR.json | 3 ++- locale/translations/it_IT.json | 3 ++- locale/translations/ja_JP.json | 3 ++- locale/translations/nl_NL.json | 3 ++- locale/translations/pl_PL.json | 3 ++- locale/translations/pt_BR.json | 3 ++- locale/translations/ru_RU.json | 3 ++- locale/translations/tr_TR.json | 1 + locale/translations/zh_CN.json | 3 ++- model/category.go | 9 +++++---- storage/category.go | 8 ++++++-- template/templates/views/categories.html | 2 +- 15 files changed, 34 insertions(+), 17 deletions(-) diff --git a/locale/translations/de_DE.json b/locale/translations/de_DE.json index 587a5df7..fd19b982 100644 --- a/locale/translations/de_DE.json +++ b/locale/translations/de_DE.json @@ -92,6 +92,7 @@ "Es gibt %d Abonnement.", "Es gibt %d Abonnements." ], + "page.categories.unread_counter": "Anzahl der ungelesenen Artikel", "page.new_category.title": "Neue Kategorie", "page.new_user.title": "Neuer Benutzer", "page.edit_category.title": "Kategorie bearbeiten: %s", diff --git a/locale/translations/en_US.json b/locale/translations/en_US.json index f5fce3a6..42cfc070 100644 --- a/locale/translations/en_US.json +++ b/locale/translations/en_US.json @@ -92,6 +92,7 @@ "There is %d feed.", "There are %d feeds." ], + "page.categories.unread_counter": "Number of unread entries", "page.new_category.title": "New Category", "page.new_user.title": "New User", "page.edit_category.title": "Edit Category: %s", @@ -352,4 +353,4 @@ "%d year ago", "%d years ago" ] -} \ No newline at end of file +} diff --git a/locale/translations/es_ES.json b/locale/translations/es_ES.json index 058ba192..fe7a1583 100644 --- a/locale/translations/es_ES.json +++ b/locale/translations/es_ES.json @@ -92,6 +92,7 @@ "Hay %d fuente.", "Hay %d fuentes." ], + "page.categories.unread_counter": "Número de entradas no leídas", "page.new_category.title": "Nueva categoría", "page.new_user.title": "Nuevo usario", "page.edit_category.title": "Editar categoría: %s", @@ -352,4 +353,4 @@ "hace %d año", "hace %d años" ] -} \ No newline at end of file +} diff --git a/locale/translations/fr_FR.json b/locale/translations/fr_FR.json index bc38a322..7f90c103 100644 --- a/locale/translations/fr_FR.json +++ b/locale/translations/fr_FR.json @@ -92,6 +92,7 @@ "Il y a %d abonnement.", "Il y a %d abonnements." ], + "page.categories.unread_counter": "Nombre d'entrées non lues", "page.new_category.title": "Nouvelle catégorie", "page.new_user.title": "Nouvel Utilisateur", "page.edit_category.title": "Modification de la catégorie : %s", @@ -372,4 +373,4 @@ "You are not authorized to access this resource (invalid username/password)": "Vous n'êtes pas autorisé à accéder à cette ressource (nom d'utilisateur / mot de passe incorrect)", "Unable to fetch this resource (Status Code = %d)": "Impossible de récupérer cette ressource (code=%d)", "Resource not found (404), this feed doesn't exists anymore, check the feed URL": "Page introuvable (404), cet abonnement n'existe plus, vérifiez l'adresse du flux" -} \ No newline at end of file +} diff --git a/locale/translations/it_IT.json b/locale/translations/it_IT.json index ce9a4cb8..2e215a09 100644 --- a/locale/translations/it_IT.json +++ b/locale/translations/it_IT.json @@ -92,6 +92,7 @@ "C'è %d feed.", "Ci sono %d feed." ], + "page.categories.unread_counter": "Numero di voci non lette", "page.new_category.title": "Nuova categoria", "page.new_user.title": "Nuovo utente", "page.edit_category.title": "Modifica categoria: %s", @@ -352,4 +353,4 @@ "%d anno fa", "%d anni fa" ] -} \ No newline at end of file +} diff --git a/locale/translations/ja_JP.json b/locale/translations/ja_JP.json index 788716a4..f327ac7f 100644 --- a/locale/translations/ja_JP.json +++ b/locale/translations/ja_JP.json @@ -92,6 +92,7 @@ "%d 個の記事があります。", "%d 個の記事があります。" ], + "page.categories.unread_counter": "未読記事の数", "page.new_category.title": "新規カテゴリ", "page.new_user.title": "新規ユーザー", "page.edit_category.title": "カテゴリーを編集: %s", @@ -352,4 +353,4 @@ "%d 年前", "%d 年前" ] -} \ No newline at end of file +} diff --git a/locale/translations/nl_NL.json b/locale/translations/nl_NL.json index 1743a14d..2b9dd4bf 100644 --- a/locale/translations/nl_NL.json +++ b/locale/translations/nl_NL.json @@ -92,6 +92,7 @@ "Er is %d feed.", "Er zijn %d feeds." ], + "page.categories.unread_counter": "Aantal ongelezen vermeldingen", "page.new_category.title": "Nieuwe categorie", "page.new_user.title": "Nieuwe gebruiker", "page.edit_category.title": "Bewerken van categorie: %s", @@ -370,4 +371,4 @@ "This website is temporarily unreachable (original error: %q)": "Deze website is tijdelijk onbereikbaar (originele error: %q)", "This website is permanently unreachable (original error: %q)": "Deze website is permanent onbereikbaar (originele error: %q)", "Website unreachable, the request timed out after %d seconds": "Website onbereikbaar, de request gaf een timeout na %d seconden" -} \ No newline at end of file +} diff --git a/locale/translations/pl_PL.json b/locale/translations/pl_PL.json index 3b59e246..a0e95b9c 100644 --- a/locale/translations/pl_PL.json +++ b/locale/translations/pl_PL.json @@ -93,6 +93,7 @@ "Są %d kanały.", "Jest %d kanałów." ], + "page.categories.unread_counter": "Liczba nieprzeczytanych wpisów", "page.new_category.title": "Nowa kategoria", "page.new_user.title": "Nowy użytkownik", "page.edit_category.title": "Edycja Kategorii: %s", @@ -378,4 +379,4 @@ "This website is temporarily unreachable (original error: %q)": "Ta strona jest tymczasowo niedostępna (błąd: %q)", "This website is permanently unreachable (original error: %q)": "Ta strona jest niedostępna (błąd: %q)", "Website unreachable, the request timed out after %d seconds": "Strona internetowa nieosiągalna, żądanie wygasło po %d sekundach" -} \ No newline at end of file +} diff --git a/locale/translations/pt_BR.json b/locale/translations/pt_BR.json index 8e6d361c..e99110a6 100644 --- a/locale/translations/pt_BR.json +++ b/locale/translations/pt_BR.json @@ -92,6 +92,7 @@ "Existe %d fonte.", "Existem %d fontes." ], + "page.categories.unread_counter": "Numero de itens não lidos", "page.new_category.title": "Nova categoria", "page.new_user.title": "Novo usuário", "page.edit_category.title": "Editar categoria: %s", @@ -352,4 +353,4 @@ "há %d ano", "há %d anos" ] -} \ No newline at end of file +} diff --git a/locale/translations/ru_RU.json b/locale/translations/ru_RU.json index cad1d952..18a02cc3 100644 --- a/locale/translations/ru_RU.json +++ b/locale/translations/ru_RU.json @@ -93,6 +93,7 @@ "Есть %d подписки.", "Есть %d подписок." ], + "page.categories.unread_counter": "Количество непрочитанных записей", "page.new_category.title": "Новая категория", "page.new_user.title": "Новый пользователь", "page.edit_category.title": "Изменить категорию: %s", @@ -360,4 +361,4 @@ "%d года назад", "%d лет назад" ] -} \ No newline at end of file +} diff --git a/locale/translations/tr_TR.json b/locale/translations/tr_TR.json index 1093a32b..8081bb8f 100644 --- a/locale/translations/tr_TR.json +++ b/locale/translations/tr_TR.json @@ -92,6 +92,7 @@ "%d besleme var.", "%d besleme var." ], + "page.categories.unread_counter": "Okunmamış iletilerin sayısı", "page.new_category.title": "Yeni Kategori", "page.new_user.title": "Yeni Kullanıcı", "page.edit_category.title": "Kategoriyi Düzenle: %s", diff --git a/locale/translations/zh_CN.json b/locale/translations/zh_CN.json index 71e1a2df..9ed3e934 100644 --- a/locale/translations/zh_CN.json +++ b/locale/translations/zh_CN.json @@ -91,6 +91,7 @@ "page.categories.feed_count": [ "有 %d 个源" ], + "page.categories.unread_counter": "未读条目数", "page.new_category.title": "新分类", "page.new_user.title": "新用户", "page.edit_category.title": "编辑分类 : %s", @@ -363,4 +364,4 @@ "This website is temporarily unreachable (original error: %q)": "该网站暂时不可达 (原始错误: %q)", "This website is permanently unreachable (original error: %q)": "该网站永久不可达 (原始错误: %q)", "Website unreachable, the request timed out after %d seconds": "网站不可达, 请求已在 %d 秒后超时" -} \ No newline at end of file +} diff --git a/model/category.go b/model/category.go index 5d8498ad..35f1b8d1 100644 --- a/model/category.go +++ b/model/category.go @@ -8,10 +8,11 @@ import "fmt" // Category represents a feed category. type Category struct { - ID int64 `json:"id"` - Title string `json:"title"` - UserID int64 `json:"user_id"` - FeedCount int `json:"-"` + ID int64 `json:"id"` + Title string `json:"title"` + UserID int64 `json:"user_id"` + FeedCount int `json:"-"` + TotalUnread int `json:"-"` } func (c *Category) String() string { diff --git a/storage/category.go b/storage/category.go index dde112da..37220a2f 100644 --- a/storage/category.go +++ b/storage/category.go @@ -116,7 +116,11 @@ func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error c.id, c.user_id, c.title, - (SELECT count(*) FROM feeds WHERE feeds.category_id=c.id) AS count + (SELECT count(*) FROM feeds WHERE feeds.category_id=c.id) AS count, + (SELECT count(*) + FROM feeds + JOIN entries ON (feeds.id = entries.feed_id) + WHERE feeds.category_id = c.id AND entries.status = 'unread') FROM categories c WHERE user_id=$1 @@ -132,7 +136,7 @@ func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error categories := make(model.Categories, 0) for rows.Next() { var category model.Category - if err := rows.Scan(&category.ID, &category.UserID, &category.Title, &category.FeedCount); err != nil { + if err := rows.Scan(&category.ID, &category.UserID, &category.Title, &category.FeedCount, &category.TotalUnread); err != nil { return nil, fmt.Errorf(`store: unable to fetch category row: %v`, err) } diff --git a/template/templates/views/categories.html b/template/templates/views/categories.html index 0ccc4bc4..00c77bd1 100644 --- a/template/templates/views/categories.html +++ b/template/templates/views/categories.html @@ -20,7 +20,7 @@ {{ .Title }} - ({{ .FeedCount }}) + ({{ .TotalUnread }})