From b4223a717c95e88f3b3efdd3e6426dce940f485d Mon Sep 17 00:00:00 2001 From: vednoc Date: Fri, 16 Jul 2021 00:55:35 +0200 Subject: [PATCH] feat(dashboard): summarize new daily users/styles --- handlers/core/dashboard.go | 23 +++++++++++++++++++++++ views/core/dashboard.html | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/handlers/core/dashboard.go b/handlers/core/dashboard.go index d605877a..96e83ae3 100644 --- a/handlers/core/dashboard.go +++ b/handlers/core/dashboard.go @@ -3,6 +3,7 @@ package core import ( "log" "sort" + "time" "github.com/gofiber/fiber/v2" @@ -11,8 +12,15 @@ import ( "userstyles.world/modules/charts" ) +type stats struct { + NewUsers int + NewStyles int +} + func Dashboard(c *fiber.Ctx) error { u, _ := jwt.User(c) + t := time.Now().Format("2006-01-02") + s := stats{} // Don't allow regular users to see this page. if u.Role < models.Moderator { @@ -31,6 +39,13 @@ func Dashboard(c *fiber.Ctx) error { }) } + // Summary of new styles. + for _, v := range styles { + if v.CreatedAt.Format("2006-01-02") == t { + s.NewStyles++ + } + } + sort.Slice(styles, func(i, j int) bool { return styles[i].ID > styles[j].ID }) @@ -44,6 +59,13 @@ func Dashboard(c *fiber.Ctx) error { }) } + // Summary of new users. + for _, v := range users { + if v.CreatedAt.Format("2006-01-02") == t { + s.NewUsers++ + } + } + // Render user history. var userHistory string if len(users) > 0 { @@ -77,6 +99,7 @@ func Dashboard(c *fiber.Ctx) error { "User": u, "Styles": styles, "Users": users, + "Summary": s, "DailyHistory": dailyHistory, "TotalHistory": totalHistory, "UserHistory": userHistory, diff --git a/views/core/dashboard.html b/views/core/dashboard.html index f83a798c..a3008cd7 100644 --- a/views/core/dashboard.html +++ b/views/core/dashboard.html @@ -22,6 +22,12 @@

Dashboard

WIP functionality to help with moderation.

+
+

Summary

+

{{ len .Users }} users ({{ .Summary.NewUsers }} today)

+

{{ len .Styles }} styles ({{ .Summary.NewStyles }} today)

+
+

History

Learn more about style statistics in the FAQ.