2018-04-16 04:42:06 -04:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
|
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
2018-04-16 06:00:49 -04:00
|
|
|
classNames: ["dashboard-mini-table"],
|
2018-04-16 04:42:06 -04:00
|
|
|
|
2018-04-16 10:01:29 -04:00
|
|
|
classNameBindings: ["isLoading"],
|
|
|
|
|
2018-04-16 04:42:06 -04:00
|
|
|
total: null,
|
|
|
|
labels: null,
|
|
|
|
title: null,
|
|
|
|
chartData: null,
|
|
|
|
isLoading: false,
|
|
|
|
help: null,
|
|
|
|
helpPage: null,
|
2018-04-18 15:30:41 -04:00
|
|
|
model: null,
|
2018-04-16 04:42:06 -04:00
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this._super();
|
|
|
|
|
2018-04-18 15:30:41 -04:00
|
|
|
if (this.get("dataSourceName")){
|
|
|
|
this._fetchReport();
|
|
|
|
} else if (this.get("model")) {
|
|
|
|
this._setPropertiesFromModel(this.get("model"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
didUpdateAttrs() {
|
|
|
|
this._super();
|
|
|
|
|
|
|
|
if (this.get("model")) {
|
|
|
|
this._setPropertiesFromModel(this.get("model"));
|
|
|
|
}
|
2018-04-16 04:42:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
@computed("dataSourceName")
|
|
|
|
dataSource(dataSourceName) {
|
|
|
|
return `/admin/reports/${dataSourceName}`;
|
|
|
|
},
|
|
|
|
|
2018-04-18 15:30:41 -04:00
|
|
|
_fetchReport() {
|
2018-04-17 05:01:06 -04:00
|
|
|
if (this.get("isLoading")) return;
|
|
|
|
|
2018-04-16 04:42:06 -04:00
|
|
|
this.set("isLoading", true);
|
|
|
|
|
2018-04-16 10:01:29 -04:00
|
|
|
ajax(this.get("dataSource"))
|
|
|
|
.then((response) => {
|
2018-04-18 15:30:41 -04:00
|
|
|
this._setPropertiesFromModel(response.report);
|
2018-04-16 10:01:29 -04:00
|
|
|
}).finally(() => {
|
|
|
|
this.set("isLoading", false);
|
2018-04-16 04:42:06 -04:00
|
|
|
});
|
2018-04-18 15:30:41 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_setPropertiesFromModel(model) {
|
|
|
|
const data = model.data.sort((a, b) => a.x >= b.x);
|
|
|
|
|
|
|
|
this.setProperties({
|
|
|
|
labels: data.map(r => r.x),
|
|
|
|
dataset: data.map(r => r.y),
|
|
|
|
total: model.total,
|
|
|
|
title: model.title,
|
|
|
|
chartData: data
|
|
|
|
});
|
2018-04-16 04:42:06 -04:00
|
|
|
}
|
|
|
|
});
|