diff --git a/public/language/en-GB/admin/general/dashboard.json b/public/language/en-GB/admin/general/dashboard.json index cfec2cd754..5ff9d61ba1 100644 --- a/public/language/en-GB/admin/general/dashboard.json +++ b/public/language/en-GB/admin/general/dashboard.json @@ -14,9 +14,12 @@ "page-views-custom-help": "Enter a date range of page views you would like to view. If no date picker is available, the accepted format is YYYY-MM-DD", "page-views-custom-error": "Please enter a valid date range in the format YYYY-MM-DD", - "stats.day": "Day", - "stats.week": "Week", - "stats.month": "Month", + "stats.yesterday": "Yesterday", + "stats.today": "Today", + "stats.last-week": "Last Week", + "stats.this-week": "This Week", + "stats.last-month": "Last Month", + "stats.this-month": "This Month", "stats.all": "All Time", "updates": "Updates", diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js index 80f06a4612..885d045602 100644 --- a/src/controllers/admin/dashboard.js +++ b/src/controllers/admin/dashboard.js @@ -129,12 +129,38 @@ async function getStatsForSet(set, field) { }; const now = Date.now(); - return await utils.promiseParallel({ - day: db.sortedSetCount(set, now - terms.day, '+inf'), - week: db.sortedSetCount(set, now - terms.week, '+inf'), - month: db.sortedSetCount(set, now - terms.month, '+inf'), + const results = await utils.promiseParallel({ + yesterday: db.sortedSetCount(set, now - (terms.day * 2), now - terms.day), + today: db.sortedSetCount(set, now - terms.day, '+inf'), + lastweek: db.sortedSetCount(set, now - (terms.week * 2), now - terms.week), + thisweek: db.sortedSetCount(set, now - terms.week, '+inf'), + lastmonth: db.sortedSetCount(set, now - (terms.month * 2), now - terms.month), + thismonth: db.sortedSetCount(set, now - terms.month, '+inf'), alltime: getGlobalField(field), }); + function textClass(num) { + if (num > 0) { + return 'text-success'; + } else if (num < 0) { + return 'text-danger'; + } + return 'text-warning'; + } + + function increasePercent(last, now) { + const percent = last ? (now - last) / last * 100 : 0; + return percent.toFixed(1); + } + results.dayIncrease = increasePercent(results.yesterday, results.today); + results.dayTextClass = textClass(results.dayIncrease); + + results.weekIncrease = increasePercent(results.lastweek, results.thisweek); + results.weekTextClass = textClass(results.weekIncrease); + + results.monthIncrease = increasePercent(results.lastmonth, results.thismonth); + results.monthTextClass = textClass(results.monthIncrease); + + return results; } async function getGlobalField(field) { diff --git a/src/views/admin/general/dashboard.tpl b/src/views/admin/general/dashboard.tpl index fac43fe73e..5ca72fb616 100644 --- a/src/views/admin/general/dashboard.tpl +++ b/src/views/admin/general/dashboard.tpl @@ -35,36 +35,47 @@
- -
-
-
{stats.name}
-
-
-
- {stats.day} -
[[admin/general/dashboard:stats.day]]
-
-
- {stats.week} -
[[admin/general/dashboard:stats.week]]
-
-
- {stats.month} -
[[admin/general/dashboard:stats.month]]
-
-
- {stats.alltime} -
[[admin/general/dashboard:stats.all]]
-
-
-
-
-
- +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
[[admin/general/dashboard:stats.yesterday]][[admin/general/dashboard:stats.today]][[admin/general/dashboard:stats.last-week]][[admin/general/dashboard:stats.this-week]][[admin/general/dashboard:stats.last-month]][[admin/general/dashboard:stats.this-month]][[admin/general/dashboard:stats.all]]
{stats.name}{stats.yesterday}{stats.today}{stats.dayIncrease}%{stats.lastweek}{stats.thisweek}{stats.weekIncrease}%{stats.lastmonth}{stats.thismonth}{stats.monthIncrease}%{stats.alltime}
+
+