mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Add title tags to dashboard stats to show percent change from previous period
This commit is contained in:
@@ -98,7 +98,41 @@ Discourse.Report = Discourse.Model.extend({
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}.property('type')
|
||||
}.property('type'),
|
||||
|
||||
percentChangeString: function(val1, val2) {
|
||||
var val = ((val1 - val2) / val2) * 100;
|
||||
if( isNaN(val) || !isFinite(val) ) {
|
||||
return null;
|
||||
} else if( val > 0 ) {
|
||||
return '+' + val.toFixed(0) + '%';
|
||||
} else {
|
||||
return val.toFixed(0) + '%';
|
||||
}
|
||||
},
|
||||
|
||||
changeTitle: function(val1, val2, prevPeriodString) {
|
||||
var title = '';
|
||||
var percentChange = this.percentChangeString(val1, val2);
|
||||
if( percentChange ) {
|
||||
title += percentChange + ' change. ';
|
||||
}
|
||||
title += 'Was ' + val2 + ' ' + prevPeriodString + '.';
|
||||
return title;
|
||||
},
|
||||
|
||||
yesterdayCountTitle: function() {
|
||||
return this.changeTitle( this.valueAt(1), this.valueAt(2),'two days ago');
|
||||
}.property('data'),
|
||||
|
||||
sevenDayCountTitle: function() {
|
||||
return this.changeTitle( this.sumDays(1,7), this.sumDays(8,14), 'two weeks ago');
|
||||
}.property('data'),
|
||||
|
||||
thirtyDayCountTitle: function() {
|
||||
return this.changeTitle( this.sumDays(1,30), this.get('prev30Days'), 'in the previous 30 day period');
|
||||
}.property('data')
|
||||
|
||||
});
|
||||
|
||||
Discourse.Report.reopenClass({
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<a {{bindAttr href="reportUrl"}}>{{title}}</a>
|
||||
</td>
|
||||
<td class="value">{{todayCount}}</td>
|
||||
<td {{bindAttr class=":value yesterdayTrend"}}>{{yesterdayCount}} <i class="icon up icon-caret-up"></i><i class="icon down icon-caret-down"></i></td>
|
||||
<td {{bindAttr class=":value sevenDayTrend"}}>{{lastSevenDaysCount}} <i class="icon up icon-caret-up"></i><i class="icon down icon-caret-down"></i></td>
|
||||
<td {{bindAttr class=":value thirtyDayTrend"}}>{{lastThirtyDaysCount}} <i class="icon up icon-caret-up"></i><i class="icon down icon-caret-down"></i></td>
|
||||
<td {{bindAttr class=":value yesterdayTrend"}} {{bindAttr title="yesterdayCountTitle"}}>{{yesterdayCount}} <i class="icon up icon-caret-up"></i><i class="icon down icon-caret-down"></i></td>
|
||||
<td {{bindAttr class=":value sevenDayTrend"}} {{bindAttr title="sevenDayCountTitle"}}>{{lastSevenDaysCount}} <i class="icon up icon-caret-up"></i><i class="icon down icon-caret-down"></i></td>
|
||||
<td {{bindAttr class=":value thirtyDayTrend"}} {{bindAttr title="thirtyDayCountTitle"}}>{{lastThirtyDaysCount}} <i class="icon up icon-caret-up"></i><i class="icon down icon-caret-down"></i></td>
|
||||
<td class="value">{{total}}</td>
|
||||
</tr>
|
||||
Reference in New Issue
Block a user