FEATURE: category dropdown in admin reports

This commit is contained in:
Régis Hanol
2015-06-24 15:19:39 +02:00
parent 80f258e51c
commit f18098fd9b
8 changed files with 108 additions and 77 deletions

View File

@ -142,23 +142,24 @@ const Report = Discourse.Model.extend({
});
Report.reopenClass({
find: function(type, startDate, endDate) {
return Discourse.ajax("/admin/reports/" + type, {data: {
start_date: startDate,
end_date: endDate
}}).then(function (json) {
find(type, startDate, endDate, categoryId) {
return Discourse.ajax("/admin/reports/" + type, {
data: {
start_date: startDate,
end_date: endDate,
category_id: categoryId
}
}).then(json => {
// Add a percent field to each tuple
var maxY = 0;
json.report.data.forEach(function (row) {
let maxY = 0;
json.report.data.forEach(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);
});
json.report.data.forEach(row => row.percentage = Math.round((row.y / maxY) * 100));
}
var model = Discourse.Report.create({type: type});
const model = Discourse.Report.create({ type: type });
model.setProperties(json.report);
return model;
});