2013-02-27 22:39:42 -05:00
|
|
|
Discourse.Report = Discourse.Model.extend({});
|
|
|
|
|
|
|
|
Discourse.Report.reopenClass({
|
|
|
|
find: function(type) {
|
2013-03-07 11:07:59 -05:00
|
|
|
var model = Discourse.Report.create({type: type});
|
2013-03-05 15:39:21 -05:00
|
|
|
$.ajax("/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);
|
|
|
|
}
|
|
|
|
});
|