aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-06-23 18:39:58 +0000
committerMax Magorsch <arzano@gentoo.org>2020-06-23 18:39:58 +0000
commitde72bc872d6b49ef996c7aedcf8f48cff98599cd (patch)
treee0e58e5330ab51bf5f47338b957f141512c8f7c7
parentHide messages where the date is null (diff)
downloadarchives-de72bc872d6b49ef996c7aedcf8f48cff98599cd.tar.gz
archives-de72bc872d6b49ef996c7aedcf8f48cff98599cd.tar.bz2
archives-de72bc872d6b49ef996c7aedcf8f48cff98599cd.zip
Format Messaage count when browsing lists
Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r--pkg/app/home/home.go4
-rw-r--r--pkg/app/home/utils.go22
-rw-r--r--pkg/app/list/utils.go6
-rw-r--r--pkg/utils/utils.go22
-rw-r--r--web/templates/list/browse.tmpl4
5 files changed, 33 insertions, 25 deletions
diff --git a/pkg/app/home/home.go b/pkg/app/home/home.go
index 06bd324..ced6ec6 100644
--- a/pkg/app/home/home.go
+++ b/pkg/app/home/home.go
@@ -8,7 +8,9 @@ import (
"archives/pkg/config"
"archives/pkg/database"
"archives/pkg/models"
+ "archives/pkg/utils"
"net/http"
+ "strconv"
"time"
)
@@ -60,7 +62,7 @@ func ComputeTemplateData() interface{} {
}{
MailingLists: mailingLists,
PopularThreads: popularThreads,
- MessageCount: formatMessageCount(getAllMessagesCount()),
+ MessageCount: utils.FormatMessageCount(strconv.Itoa(getAllMessagesCount())),
CurrentMonth: time.Now().Format("2006-01"),
}
}
diff --git a/pkg/app/home/utils.go b/pkg/app/home/utils.go
index 76af3c7..cb2e45e 100644
--- a/pkg/app/home/utils.go
+++ b/pkg/app/home/utils.go
@@ -8,7 +8,6 @@ import (
"github.com/go-pg/pg/v10"
"html/template"
"net/http"
- "strconv"
)
// renderIndexTemplate renders all templates used for the landing page
@@ -34,24 +33,3 @@ func getAllMessagesCount() int {
`)
return messsageCount
}
-
-// formatMessageCount returns the formatted number of
-// messages containing a thousands comma
-func formatMessageCount(messageCount int) string {
- packages := strconv.Itoa(messageCount)
- if len(string(messageCount)) == 9 {
- return packages[:3] + "," + packages[3:6] + "," + packages[6:]
- } else if len(packages) == 8 {
- return packages[:2] + "," + packages[2:5] + "," + packages[5:]
- } else if len(packages) == 7 {
- return packages[:1] + "," + packages[1:4] + "," + packages[4:]
- } else if len(packages) == 6 {
- return packages[:3] + "," + packages[3:]
- } else if len(packages) == 5 {
- return packages[:2] + "," + packages[2:]
- } else if len(packages) == 4 {
- return packages[:1] + "," + packages[1:]
- } else {
- return packages
- }
-}
diff --git a/pkg/app/list/utils.go b/pkg/app/list/utils.go
index 8a9e964..7899a88 100644
--- a/pkg/app/list/utils.go
+++ b/pkg/app/list/utils.go
@@ -4,8 +4,10 @@ package list
import (
"archives/pkg/models"
+ "archives/pkg/utils"
"html/template"
"net/http"
+ "strconv"
)
type ListData struct {
@@ -68,6 +70,10 @@ func renderBrowseTemplate(w http.ResponseWriter, lists interface{}) {
templates := template.Must(
template.Must(
template.New("Show").
+ Funcs(template.FuncMap{
+ "toString" : strconv.Itoa,
+ "formatCount" : utils.FormatMessageCount,
+ }).
ParseGlob("web/templates/layout/*.tmpl")).
ParseGlob("web/templates/list/*.tmpl"))
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
new file mode 100644
index 0000000..b1a5d31
--- /dev/null
+++ b/pkg/utils/utils.go
@@ -0,0 +1,22 @@
+package utils
+
+// formatMessageCount returns the formatted number of
+// messages containing a thousands comma
+func FormatMessageCount(messageCount string) string {
+ if len(messageCount) == 9 {
+ return messageCount[:3] + "," + messageCount[3:6] + "," + messageCount[6:]
+ } else if len(messageCount) == 8 {
+ return messageCount[:2] + "," + messageCount[2:5] + "," + messageCount[5:]
+ } else if len(messageCount) == 7 {
+ return messageCount[:1] + "," + messageCount[1:4] + "," + messageCount[4:]
+ } else if len(messageCount) == 6 {
+ return messageCount[:3] + "," + messageCount[3:]
+ } else if len(messageCount) == 5 {
+ return messageCount[:2] + "," + messageCount[2:]
+ } else if len(messageCount) == 4 {
+ return messageCount[:1] + "," + messageCount[1:]
+ } else {
+ return messageCount
+ }
+}
+
diff --git a/web/templates/list/browse.tmpl b/web/templates/list/browse.tmpl
index 9c2ea3f..de5257e 100644
--- a/web/templates/list/browse.tmpl
+++ b/web/templates/list/browse.tmpl
@@ -21,7 +21,7 @@
{{.Name}}
</span>
<h4 class="mb-0">
- <span class="badge badge-secondary badge-pill">{{.MessageCount}}</span>
+ <span class="badge badge-secondary badge-pill">{{formatCount (toString .MessageCount)}}</span>
</h4>
</a>
{{end}}
@@ -48,7 +48,7 @@
{{.Name}}
</span>
<h4 class="mb-0">
- <span class="badge badge-secondary badge-pill">{{.MessageCount}}</span>
+ <span class="badge badge-secondary badge-pill">{{formatCount (toString .MessageCount)}}</span>
</h4>
</a>
{{end}}