2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00

dashboard next: trending search report

This commit also improves how data is loaded sync and async
This commit is contained in:
Joffrey JAFFEUX 2018-04-19 18:19:21 +02:00 committed by GitHub
parent 108e622a61
commit 0e414d0890
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 310 additions and 113 deletions

View file

@ -0,0 +1,65 @@
import { ajax } from 'discourse/lib/ajax';
import computed from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({
classNames: ["dashboard-table", "dashboard-inline-table"],
classNameBindings: ["isLoading"],
total: null,
labels: null,
title: null,
chartData: null,
isLoading: false,
help: null,
helpPage: null,
model: null,
didInsertElement() {
this._super();
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"));
}
},
@computed("dataSourceName")
dataSource(dataSourceName) {
return `/admin/reports/${dataSourceName}`;
},
_fetchReport() {
if (this.get("isLoading")) return;
this.set("isLoading", true);
ajax(this.get("dataSource"))
.then((response) => {
this._setPropertiesFromModel(response.report);
}).finally(() => {
this.set("isLoading", false);
});
},
_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
});
}
});