discourse/app/assets/javascripts/admin/mixins/async-report.js.es6
Joffrey JAFFEUX 9554d9c56a
UX: tooltips and improvements to new dashboard
- tooltips
- revert chart title UI
- reduce period chooser font-size
- localize dates of data points
- fix a bug where multiple reports were loaded at the same time
- fix a bug where % was not showing anymore
- remove spacing at the top
- remove loadingTitle feature (Loading...%report name%) incompatible with new hijack design
2018-05-16 16:45:21 +02:00

69 lines
1.7 KiB
JavaScript

import computed from "ember-addons/ember-computed-decorators";
export default Ember.Mixin.create({
classNameBindings: ["isLoading"],
reports: null,
isLoading: false,
dataSourceNames: "",
title: null,
init() {
this._super();
this.set("reports", []);
},
@computed("dataSourceNames")
dataSources(dataSourceNames) {
return dataSourceNames.split(",").map(source => `/admin/reports/${source}`);
},
@computed("reports.[]", "startDate", "endDate")
reportsForPeriod(reports, startDate, endDate) {
// on a slow network fetchReport could be called multiple times between
// T and T+x, and all the ajax responses would occur after T+(x+y)
// to avoid any inconsistencies we filter by period and make sure
// the array contains only unique values
reports = reports.uniqBy("report_key");
if (!startDate || !endDate) {
return reports;
}
return reports.filter(report => {
return report.report_key.includes(startDate.format("YYYYMMDD")) &&
report.report_key.includes(endDate.format("YYYYMMDD"));
});
},
didInsertElement() {
this._super();
this.fetchReport()
.finally(() => {
this.renderReport();
});
},
didUpdateAttrs() {
this._super();
this.fetchReport()
.finally(() => {
this.renderReport();
});
},
renderReport() {
if (!this.element || this.isDestroying || this.isDestroyed) return;
this.set("title", this.get("reportsForPeriod").map(r => r.title).join(", "));
this.set("isLoading", false);
},
loadReport() {},
fetchReport() {
this.set("reports", []);
this.set("isLoading", true);
},
});