2013-03-19 12:04:40 -04:00
|
|
|
Discourse.Report = Discourse.Model.extend({
|
|
|
|
reportUrl: function() {
|
|
|
|
return("/admin/reports/" + this.get('type'));
|
|
|
|
}.property('type')
|
|
|
|
});
|
2013-02-27 22:39:42 -05:00
|
|
|
|
|
|
|
Discourse.Report.reopenClass({
|
|
|
|
find: function(type) {
|
2013-03-07 11:07:59 -05:00
|
|
|
var model = Discourse.Report.create({type: type});
|
2013-03-14 08:01:52 -04:00
|
|
|
$.ajax(Discourse.getURL("/admin/reports/") + type, {
|
2013-02-27 22:39:42 -05:00
|
|
|
type: 'GET',
|
|
|
|
success: function(json) {
|
2013-03-17 15:02:36 -04:00
|
|
|
|
|
|
|
// Add a percent field to each tuple
|
|
|
|
var maxY = 0;
|
|
|
|
json.report.data.forEach(function (row) {
|
|
|
|
if (row.y > maxY) maxY = row.y;
|
|
|
|
});
|
|
|
|
if (maxY > 0) {
|
|
|
|
json.report.data.forEach(function (row) {
|
|
|
|
row.percentage = Math.round((row.y / maxY) * 100);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-02-27 22:39:42 -05:00
|
|
|
model.mergeAttributes(json.report);
|
|
|
|
model.set('loaded', true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return(model);
|
|
|
|
}
|
2013-03-14 08:01:52 -04:00
|
|
|
});
|