discourse/app/assets/javascripts/admin/components/dashboard-mini-table.js.es6
Joffrey JAFFEUX cfe88a67e1
dashboard next: minor quality improvements
* locale for title
* minimum chart/table while loading
* sort users by type
* more spacing in the UI
* minor refactoring
2018-04-16 16:01:29 +02:00

48 lines
1.0 KiB
JavaScript

import { ajax } from 'discourse/lib/ajax';
import computed from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({
classNames: ["dashboard-mini-table"],
classNameBindings: ["isLoading"],
total: null,
labels: null,
title: null,
chartData: null,
isLoading: false,
help: null,
helpPage: null,
didInsertElement() {
this._super();
this.fetchReport.apply(this);
},
@computed("dataSourceName")
dataSource(dataSourceName) {
return `/admin/reports/${dataSourceName}`;
},
fetchReport() {
this.set("isLoading", true);
ajax(this.get("dataSource"))
.then((response) => {
const report = response.report;
const data = report.data.sort((a, b) => a.x >= b.x);
this.setProperties({
labels: data.map(r => r.x),
dataset: data.map(r => r.y),
total: report.total,
title: report.title,
chartData: data
});
}).finally(() => {
this.set("isLoading", false);
});
}
});