mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 18:05:37 +08:00
correct it so when we have no dates we still return graphs
This commit is contained in:
parent
9d9332d8c9
commit
9d97e1244e
|
@ -83,7 +83,6 @@ export default Ember.Component.extend(AsyncReport, {
|
|||
ajax(this.get("dataSource"), payload)
|
||||
.then((response) => {
|
||||
this.set('reportKey', response.report.report_key);
|
||||
|
||||
this.loadReport(response.report);
|
||||
})
|
||||
.finally(() => {
|
||||
|
@ -100,7 +99,7 @@ export default Ember.Component.extend(AsyncReport, {
|
|||
},
|
||||
|
||||
loadReport(report) {
|
||||
if (report.data) {
|
||||
if (_.isArray(report.data)) {
|
||||
Report.fillMissingDates(report);
|
||||
|
||||
if (report.data && report.data.length > 40) {
|
||||
|
|
|
@ -14,7 +14,6 @@ export default Ember.Mixin.create({
|
|||
Em.run.next(() => {
|
||||
if (report.report_key = this.get("reportKey")) {
|
||||
this.loadReport(report);
|
||||
console.log(report);
|
||||
this.set("isLoading", false);
|
||||
this.renderReport();
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ const Report = Discourse.Model.extend({
|
|||
|
||||
@computed('data', 'currentTotal')
|
||||
currentAverage(data, total) {
|
||||
return parseFloat((total / parseFloat(data.length)).toFixed(1));
|
||||
return data.length === 0 ? 0 : parseFloat((total / parseFloat(data.length)).toFixed(1));
|
||||
},
|
||||
|
||||
@computed('prev_period', 'currentTotal', 'currentAverage')
|
||||
|
@ -172,7 +172,7 @@ const Report = Discourse.Model.extend({
|
|||
let percent = this.percentChangeString(current, prev);
|
||||
|
||||
if (this.get('average')) {
|
||||
prev = prev.toFixed(1);
|
||||
prev = prev ? prev.toFixed(1) : "0";
|
||||
current += '%';
|
||||
prev += '%';
|
||||
}
|
||||
|
@ -219,7 +219,8 @@ const Report = Discourse.Model.extend({
|
|||
Report.reopenClass({
|
||||
|
||||
fillMissingDates(report) {
|
||||
if (report.data.length > 0) {
|
||||
if (_.isArray(report.data)) {
|
||||
|
||||
const startDateFormatted = moment.utc(report.start_date).format('YYYY-MM-DD');
|
||||
const endDateFormatted = moment.utc(report.end_date).format('YYYY-MM-DD');
|
||||
report.data = fillMissingDates(report.data, startDateFormatted, endDateFormatted);
|
||||
|
|
|
@ -494,7 +494,7 @@ export function fillMissingDates(data, startDate, endDate) {
|
|||
|
||||
for (let i = 0; i <= countDays; i++) {
|
||||
let date = (data[i]) ? moment(data[i].x, "YYYY-MM-DD") : null;
|
||||
if (i === 0 && date.isAfter(startMoment)) {
|
||||
if (i === 0 && (!date || date.isAfter(startMoment))) {
|
||||
data.splice(i, 0, { "x" : startMoment.format("YYYY-MM-DD"), 'y': 0 });
|
||||
} else {
|
||||
if (!date || date.isAfter(moment(currentMoment))) {
|
||||
|
|
|
@ -16,8 +16,8 @@ module Jobs
|
|||
report.facets = args['facets'].map(&:to_sym) if args['facets']
|
||||
|
||||
Report.send("report_#{type}", report)
|
||||
|
||||
json = report.as_json
|
||||
|
||||
Discourse.cache.write(Report.cache_key(report), json, force: true, expires_in: 30.minutes)
|
||||
|
||||
MessageBus.publish("/admin/reports/#{type}", json, user_ids: User.staff.pluck(:id))
|
||||
|
|
|
@ -42,8 +42,8 @@ class Report
|
|||
yaxis: I18n.t("reports.#{type}.yaxis"),
|
||||
description: I18n.t("reports.#{type}.description"),
|
||||
data: data,
|
||||
start_date: start_date,
|
||||
end_date: end_date,
|
||||
start_date: start_date&.iso8601,
|
||||
end_date: end_date&.iso8601,
|
||||
category_id: category_id,
|
||||
group_id: group_id,
|
||||
prev30Days: self.prev30Days,
|
||||
|
|
Loading…
Reference in New Issue
Block a user