FEATURE: category dropdown in admin reports
This commit is contained in:
@@ -4,24 +4,26 @@ export default Ember.ObjectController.extend({
|
||||
viewingBarChart: Em.computed.equal('viewMode', 'barChart'),
|
||||
startDate: null,
|
||||
endDate: null,
|
||||
categoryId: null,
|
||||
refreshing: false,
|
||||
|
||||
actions: {
|
||||
refreshReport: function() {
|
||||
var self = this;
|
||||
this.set('refreshing', true);
|
||||
Discourse.Report.find(this.get('type'), this.get('startDate'), this.get('endDate')).then(function(r) {
|
||||
self.set('model', r);
|
||||
}).finally(function() {
|
||||
self.set('refreshing', false);
|
||||
});
|
||||
refreshReport() {
|
||||
this.set("refreshing", true);
|
||||
Discourse.Report.find(
|
||||
this.get("type"),
|
||||
this.get("startDate"),
|
||||
this.get("endDate"),
|
||||
this.get("categoryId")
|
||||
).then(m => this.set("model", m)
|
||||
).finally(() => this.set("refreshing", false));
|
||||
},
|
||||
|
||||
viewAsTable: function() {
|
||||
viewAsTable() {
|
||||
this.set('viewMode', 'table');
|
||||
},
|
||||
|
||||
viewAsBarChart: function() {
|
||||
viewAsBarChart() {
|
||||
this.set('viewMode', 'barChart');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<div>
|
||||
{{i18n 'admin.dashboard.reports.start_date'}} {{input type="date" value=startDate}}
|
||||
{{i18n 'admin.dashboard.reports.end_date'}} {{input type="date" value=endDate}}
|
||||
{{category-chooser valueAttribute="id" value=categoryId source=categoryId}}
|
||||
{{d-button action="refreshReport" class="btn-primary" label="admin.dashboard.reports.refresh_report" icon="refresh"}}
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user