mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Refactor some report javascript to get rid of some helpers
This commit is contained in:
parent
75703cfc6a
commit
b6a6581b3c
@ -1,42 +1,3 @@
|
|||||||
/**
|
|
||||||
Get the y value of a report data point by its index. Negative indexes start from the end.
|
|
||||||
|
|
||||||
@method reportValueY
|
|
||||||
@for Handlebars
|
|
||||||
**/
|
|
||||||
Handlebars.registerHelper('valueAtDaysAgo', function(property, i) {
|
|
||||||
var data = Ember.Handlebars.get(this, property);
|
|
||||||
if( data ) {
|
|
||||||
var wantedDate = Date.create(i + ' days ago', 'en').format('{yyyy}-{MM}-{dd}');
|
|
||||||
var item = data.find( function(d, i, arr) { return d.x === wantedDate; } );
|
|
||||||
if( item ) {
|
|
||||||
return item.y;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
Sum the given number of data points from the report, starting at the most recent.
|
|
||||||
|
|
||||||
@method sumLast
|
|
||||||
@for Handlebars
|
|
||||||
**/
|
|
||||||
Handlebars.registerHelper('sumLast', function(property, numDays) {
|
|
||||||
var data = Ember.Handlebars.get(this, property);
|
|
||||||
if( data ) {
|
|
||||||
var earliestDate = Date.create(numDays + ' days ago', 'en');
|
|
||||||
var sum = 0;
|
|
||||||
data.each(function(d){
|
|
||||||
if(Date.create(d.x) >= earliestDate) {
|
|
||||||
sum += d.y;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return the count of users at the given trust level.
|
Return the count of users at the given trust level.
|
||||||
|
|
||||||
|
@ -29,6 +29,30 @@ Discourse.Report = Discourse.Model.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
todayCount: function() {
|
||||||
|
return this.valueAt(0);
|
||||||
|
}.property('data'),
|
||||||
|
|
||||||
|
yesterdayCount: function() {
|
||||||
|
return this.valueAt(1);
|
||||||
|
}.property('data'),
|
||||||
|
|
||||||
|
lastSevenDaysCount: function() {
|
||||||
|
return this.sumDays(1,7);
|
||||||
|
}.property('data'),
|
||||||
|
|
||||||
|
lastThirtyDaysCount: function() {
|
||||||
|
return this.sumDays(1,30);
|
||||||
|
}.property('data'),
|
||||||
|
|
||||||
|
sevenDaysAgoCount: function() {
|
||||||
|
return this.valueAt(7);
|
||||||
|
}.property('data'),
|
||||||
|
|
||||||
|
thirtyDaysAgoCount: function() {
|
||||||
|
return this.valueAt(30);
|
||||||
|
}.property('data'),
|
||||||
|
|
||||||
yesterdayTrend: function() {
|
yesterdayTrend: function() {
|
||||||
var yesterdayVal = this.valueAt(1);
|
var yesterdayVal = this.valueAt(1);
|
||||||
var twoDaysAgoVal = this.valueAt(2);
|
var twoDaysAgoVal = this.valueAt(2);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="title"><a {{bindAttr href="reportUrl"}}>{{title}}</a></td>
|
<td class="title"><a {{bindAttr href="reportUrl"}}>{{title}}</a></td>
|
||||||
<td class="value">{{valueAtDaysAgo data 0}}</td>
|
<td class="value">{{todayCount}}</td>
|
||||||
<td class="value">{{valueAtDaysAgo data 1}}</td>
|
<td class="value">{{yesterdayCount}}</td>
|
||||||
<td class="value">{{valueAtDaysAgo data 7}}</td>
|
<td class="value">{{sevenDaysAgoCount}}</td>
|
||||||
<td class="value">{{valueAtDaysAgo data 30}}</td>
|
<td class="value">{{thirtyDaysAgoCount}}</td>
|
||||||
</tr>
|
</tr>
|
@ -1,8 +1,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="title"><a {{bindAttr href="reportUrl"}}>{{title}}</a></td>
|
<td class="title"><a {{bindAttr href="reportUrl"}}>{{title}}</a></td>
|
||||||
<td class="value">{{valueAtDaysAgo data 0}}</td>
|
<td class="value">{{todayCount}}</td>
|
||||||
<td {{bindAttr class=":value yesterdayTrend"}}>{{valueAtDaysAgo data 1}} <i class="icon up icon-caret-up"></i><i class="icon down icon-caret-down"></i></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"}}>{{sumLast data 7}} <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"}}>{{sumLast data 30}} <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 class="value">{{total}}</td>
|
<td class="value">{{total}}</td>
|
||||||
</tr>
|
</tr>
|
Loading…
Reference in New Issue
Block a user