aboutsummaryrefslogtreecommitdiff
path: root/pkg/app
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 /pkg/app
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>
Diffstat (limited to 'pkg/app')
-rw-r--r--pkg/app/home/home.go4
-rw-r--r--pkg/app/home/utils.go22
-rw-r--r--pkg/app/list/utils.go6
3 files changed, 9 insertions, 23 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"))