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({
|
||||
|
||||
Reference in New Issue
Block a user