2019-11-07 16:38:28 -05:00
|
|
|
import EmberObject, { action, computed } from "@ember/object";
|
2021-06-17 03:15:20 -04:00
|
|
|
import Report, { DAILY_LIMIT_DAYS, SCHEMA_VERSION } from "admin/models/report";
|
2020-09-11 14:53:44 -04:00
|
|
|
import { alias, and, equal, notEmpty, or } from "@ember/object/computed";
|
2019-10-23 12:30:52 -04:00
|
|
|
import Component from "@ember/component";
|
2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2018-08-24 09:28:01 -04:00
|
|
|
import ReportLoader from "discourse/lib/reports-loader";
|
2019-11-07 16:38:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2018-07-19 14:33:11 -04:00
|
|
|
import { exportEntity } from "discourse/lib/export-csv";
|
2020-04-22 16:17:53 -04:00
|
|
|
import { isPresent } from "@ember/utils";
|
2020-06-01 16:33:43 -04:00
|
|
|
import { isTesting } from "discourse-common/config/environment";
|
|
|
|
import { makeArray } from "discourse-common/lib/helpers";
|
2019-10-30 09:48:24 -04:00
|
|
|
import { next } from "@ember/runloop";
|
2018-07-19 14:33:11 -04:00
|
|
|
import { outputExportResult } from "discourse/lib/export-result";
|
|
|
|
|
|
|
|
const TABLE_OPTIONS = {
|
|
|
|
perPage: 8,
|
|
|
|
total: true,
|
2018-08-01 18:40:59 -04:00
|
|
|
limit: 20,
|
|
|
|
formatNumbers: true,
|
2018-07-19 14:33:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const CHART_OPTIONS = {};
|
|
|
|
|
2019-10-23 12:30:52 -04:00
|
|
|
export default Component.extend({
|
2020-04-30 11:31:04 -04:00
|
|
|
classNameBindings: [
|
2020-09-11 14:53:44 -04:00
|
|
|
"isHidden:hidden",
|
|
|
|
"isHidden::is-visible",
|
2020-04-30 11:31:04 -04:00
|
|
|
"isEnabled",
|
|
|
|
"isLoading",
|
|
|
|
"dasherizedDataSourceName",
|
|
|
|
],
|
2018-07-19 14:33:11 -04:00
|
|
|
classNames: ["admin-report"],
|
|
|
|
isEnabled: true,
|
2018-11-07 11:59:42 -05:00
|
|
|
disabledLabel: I18n.t("admin.dashboard.disabled"),
|
2018-07-19 14:33:11 -04:00
|
|
|
isLoading: false,
|
2018-08-22 05:25:12 -04:00
|
|
|
rateLimitationString: null,
|
2018-07-19 14:33:11 -04:00
|
|
|
dataSourceName: null,
|
|
|
|
report: null,
|
|
|
|
model: null,
|
|
|
|
reportOptions: null,
|
|
|
|
forcedModes: null,
|
|
|
|
showAllReportsLink: false,
|
2018-07-27 01:22:00 -04:00
|
|
|
filters: null,
|
2018-07-19 14:33:11 -04:00
|
|
|
showTrend: false,
|
|
|
|
showHeader: true,
|
|
|
|
showTitle: true,
|
|
|
|
showFilteringUI: false,
|
2019-10-30 16:28:29 -04:00
|
|
|
showDatesOptions: alias("model.dates_filtering"),
|
2019-10-30 19:18:29 -04:00
|
|
|
showRefresh: or("showDatesOptions", "model.available_filters.length"),
|
2019-10-30 16:28:29 -04:00
|
|
|
shouldDisplayTrend: and("showTrend", "model.prev_period"),
|
2021-04-22 04:34:23 -04:00
|
|
|
endDate: null,
|
|
|
|
startDate: null,
|
2018-07-19 14:33:11 -04:00
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
this._reports = [];
|
|
|
|
},
|
|
|
|
|
2020-04-30 11:31:04 -04:00
|
|
|
isHidden: computed("siteSettings.dashboard_hidden_reports", function () {
|
|
|
|
return (this.siteSettings.dashboard_hidden_reports || "")
|
|
|
|
.split("|")
|
|
|
|
.filter(Boolean)
|
|
|
|
.includes(this.dataSourceName);
|
|
|
|
}),
|
|
|
|
|
2021-04-22 04:34:23 -04:00
|
|
|
didReceiveAttrs() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
let startDate = moment();
|
2020-04-22 16:17:53 -04:00
|
|
|
if (this.filters && isPresent(this.filters.startDate)) {
|
2021-04-22 04:34:23 -04:00
|
|
|
startDate = moment(this.filters.startDate, "YYYY-MM-DD");
|
2020-04-22 16:17:53 -04:00
|
|
|
}
|
2021-04-22 04:34:23 -04:00
|
|
|
this.set("startDate", startDate);
|
2020-04-22 16:17:53 -04:00
|
|
|
|
2021-04-22 04:34:23 -04:00
|
|
|
let endDate = moment();
|
2020-04-22 16:17:53 -04:00
|
|
|
if (this.filters && isPresent(this.filters.endDate)) {
|
2021-04-22 04:34:23 -04:00
|
|
|
endDate = moment(this.filters.endDate, "YYYY-MM-DD");
|
2020-04-22 16:17:53 -04:00
|
|
|
}
|
2021-04-22 04:34:23 -04:00
|
|
|
this.set("endDate", endDate);
|
2018-07-19 14:33:11 -04:00
|
|
|
|
2021-06-17 03:15:20 -04:00
|
|
|
if (this.filters) {
|
|
|
|
this.set("currentMode", this.filters.mode);
|
|
|
|
}
|
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.report) {
|
2019-05-27 04:42:53 -04:00
|
|
|
this._renderReport(this.report, this.forcedModes, this.currentMode);
|
2019-05-27 04:15:39 -04:00
|
|
|
} else if (this.dataSourceName) {
|
2018-08-24 09:28:01 -04:00
|
|
|
this._fetchReport();
|
2018-07-19 14:33:11 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-10-30 19:18:29 -04:00
|
|
|
showError: or("showTimeoutError", "showExceptionError", "showNotFoundError"),
|
2019-10-30 16:28:29 -04:00
|
|
|
showNotFoundError: equal("model.error", "not_found"),
|
|
|
|
showTimeoutError: equal("model.error", "timeout"),
|
|
|
|
showExceptionError: equal("model.error", "exception"),
|
2018-07-19 14:33:11 -04:00
|
|
|
|
2019-10-30 16:28:29 -04:00
|
|
|
hasData: notEmpty("model.data"),
|
2018-07-25 14:28:41 -04:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("dataSourceName", "model.type")
|
2018-07-19 14:33:11 -04:00
|
|
|
dasherizedDataSourceName(dataSourceName, type) {
|
|
|
|
return (dataSourceName || type || "undefined").replace(/_/g, "-");
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("dataSourceName", "model.type")
|
2018-07-19 14:33:11 -04:00
|
|
|
dataSource(dataSourceName, type) {
|
|
|
|
dataSourceName = dataSourceName || type;
|
|
|
|
return `/admin/reports/${dataSourceName}`;
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("displayedModes.length")
|
2018-07-19 14:33:11 -04:00
|
|
|
showModes(displayedModesLength) {
|
|
|
|
return displayedModesLength > 1;
|
|
|
|
},
|
|
|
|
|
2020-07-28 10:14:41 -04:00
|
|
|
@discourseComputed("currentMode")
|
|
|
|
isChartMode(currentMode) {
|
|
|
|
return currentMode === "chart";
|
|
|
|
},
|
|
|
|
|
|
|
|
@action
|
|
|
|
changeGrouping(grouping) {
|
|
|
|
this.send("refreshReport", {
|
|
|
|
chartGrouping: grouping,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("currentMode", "model.modes", "forcedModes")
|
2018-07-19 14:33:11 -04:00
|
|
|
displayedModes(currentMode, reportModes, forcedModes) {
|
|
|
|
const modes = forcedModes ? forcedModes.split(",") : reportModes;
|
|
|
|
|
2019-10-31 13:55:01 -04:00
|
|
|
return makeArray(modes).map((mode) => {
|
2018-10-24 16:09:36 -04:00
|
|
|
const base = `btn-default mode-btn ${mode}`;
|
2021-06-17 03:15:20 -04:00
|
|
|
const cssClass = currentMode === mode ? `${base} btn-primary` : base;
|
2018-07-19 14:33:11 -04:00
|
|
|
|
|
|
|
return {
|
|
|
|
mode,
|
|
|
|
cssClass,
|
|
|
|
icon: mode === "table" ? "table" : "signal",
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("currentMode")
|
2018-07-19 14:33:11 -04:00
|
|
|
modeComponent(currentMode) {
|
2020-02-06 05:30:38 -05:00
|
|
|
return `admin-report-${currentMode.replace(/_/g, "-")}`;
|
2018-07-19 14:33:11 -04:00
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed(
|
2018-07-19 19:30:13 -04:00
|
|
|
"dataSourceName",
|
2020-04-22 16:17:53 -04:00
|
|
|
"startDate",
|
|
|
|
"endDate",
|
2019-04-26 06:17:10 -04:00
|
|
|
"filters.customFilters"
|
2018-07-19 19:30:13 -04:00
|
|
|
)
|
2019-04-26 06:17:10 -04:00
|
|
|
reportKey(dataSourceName, startDate, endDate, customFilters) {
|
2020-09-22 10:28:28 -04:00
|
|
|
if (!dataSourceName || !startDate || !endDate) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-07-19 19:30:13 -04:00
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
startDate = startDate.toISOString(true).split("T")[0];
|
|
|
|
endDate = endDate.toISOString(true).split("T")[0];
|
|
|
|
|
2018-07-31 17:35:13 -04:00
|
|
|
let reportKey = "reports:";
|
|
|
|
reportKey += [
|
|
|
|
dataSourceName,
|
2020-06-01 16:33:43 -04:00
|
|
|
isTesting() ? "start" : startDate.replace(/-/g, ""),
|
|
|
|
isTesting() ? "end" : endDate.replace(/-/g, ""),
|
2018-07-31 17:35:13 -04:00
|
|
|
"[:prev_period]",
|
|
|
|
this.get("reportOptions.table.limit"),
|
2020-04-22 04:52:50 -04:00
|
|
|
// Convert all filter values to strings to ensure unique serialization
|
2019-04-26 06:17:10 -04:00
|
|
|
customFilters
|
2020-04-22 04:52:50 -04:00
|
|
|
? JSON.stringify(customFilters, (k, v) => (k ? `${v}` : v))
|
2019-04-26 06:17:10 -04:00
|
|
|
: null,
|
2018-07-31 17:35:13 -04:00
|
|
|
SCHEMA_VERSION,
|
|
|
|
]
|
|
|
|
.filter((x) => x)
|
|
|
|
.map((x) => x.toString())
|
|
|
|
.join(":");
|
2018-07-19 19:30:13 -04:00
|
|
|
|
|
|
|
return reportKey;
|
|
|
|
},
|
|
|
|
|
2021-06-17 03:15:20 -04:00
|
|
|
@discourseComputed("options.chartGrouping", "model.chartData.length")
|
|
|
|
chartGroupings(grouping, count) {
|
|
|
|
const options = ["daily", "weekly", "monthly"];
|
2020-07-28 10:14:41 -04:00
|
|
|
|
2021-06-17 03:15:20 -04:00
|
|
|
return options.map((id) => {
|
2020-07-28 10:14:41 -04:00
|
|
|
return {
|
|
|
|
id,
|
2021-06-17 03:15:20 -04:00
|
|
|
disabled: id === "daily" && count >= DAILY_LIMIT_DAYS,
|
2020-07-28 10:14:41 -04:00
|
|
|
label: `admin.dashboard.reports.${id}`,
|
2021-06-17 03:15:20 -04:00
|
|
|
class: `chart-grouping ${grouping === id ? "active" : "inactive"}`,
|
2020-07-28 10:14:41 -04:00
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
@action
|
|
|
|
onChangeDateRange(range) {
|
2021-04-22 04:34:23 -04:00
|
|
|
this.setProperties({
|
2020-04-22 16:17:53 -04:00
|
|
|
startDate: range.from,
|
|
|
|
endDate: range.to,
|
|
|
|
});
|
|
|
|
},
|
2019-08-06 02:41:21 -04:00
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
@action
|
|
|
|
applyFilter(id, value) {
|
|
|
|
let customFilters = this.get("filters.customFilters") || {};
|
2019-08-06 02:41:21 -04:00
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
if (typeof value === "undefined") {
|
|
|
|
delete customFilters[id];
|
|
|
|
} else {
|
|
|
|
customFilters[id] = value;
|
|
|
|
}
|
2019-08-06 02:41:21 -04:00
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
this.send("refreshReport", {
|
|
|
|
filters: customFilters,
|
|
|
|
});
|
|
|
|
},
|
2019-08-06 02:41:21 -04:00
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
@action
|
|
|
|
refreshReport(options = {}) {
|
2020-07-31 14:06:40 -04:00
|
|
|
if (!this.attrs.onRefresh) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
this.attrs.onRefresh({
|
|
|
|
type: this.get("model.type"),
|
2021-06-17 03:15:20 -04:00
|
|
|
mode: this.currentMode,
|
2020-07-28 10:14:41 -04:00
|
|
|
chartGrouping: options.chartGrouping,
|
2020-04-22 16:17:53 -04:00
|
|
|
startDate:
|
|
|
|
typeof options.startDate === "undefined"
|
|
|
|
? this.startDate
|
|
|
|
: options.startDate,
|
|
|
|
endDate:
|
|
|
|
typeof options.endDate === "undefined" ? this.endDate : options.endDate,
|
|
|
|
filters:
|
|
|
|
typeof options.filters === "undefined"
|
|
|
|
? this.get("filters.customFilters")
|
|
|
|
: options.filters,
|
|
|
|
});
|
|
|
|
},
|
2019-04-26 06:17:10 -04:00
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
@action
|
|
|
|
exportCsv() {
|
2020-06-10 11:57:39 -04:00
|
|
|
const args = {
|
2020-04-22 16:17:53 -04:00
|
|
|
name: this.get("model.type"),
|
|
|
|
start_date: this.startDate.toISOString(true).split("T")[0],
|
2020-06-10 11:57:39 -04:00
|
|
|
end_date: this.endDate.toISOString(true).split("T")[0],
|
|
|
|
};
|
|
|
|
|
|
|
|
const customFilters = this.get("filters.customFilters");
|
|
|
|
if (customFilters) {
|
|
|
|
Object.assign(args, customFilters);
|
|
|
|
}
|
|
|
|
|
|
|
|
exportEntity("report", args).then(outputExportResult);
|
2020-04-22 16:17:53 -04:00
|
|
|
},
|
FEATURE: Exposing a way to add a generic report filter (#6816)
* FEATURE: Exposing a way to add a generic report filter
## Why do we need this change?
Part of the work discussed [here](https://meta.discourse.org/t/gain-understanding-of-file-uploads-usage/104994), and implemented a first spike [here](https://github.com/discourse/discourse/pull/6809), I am trying to expose a single generic filter selector per report.
## How does this work?
We basically expose a simple, single generic filter that is computed and displayed based on backend values passed into the report.
This would be a simple contract between the frontend and the backend.
**Backend changes:** we simply need to return a list of dropdown / select options, and enable the report's newly introduced `custom_filtering` property.
For example, for our [Top Uploads](https://github.com/discourse/discourse/pull/6809/files#diff-3f97cbb8726f3310e0b0c386dbe89e22R1423) report, it can look like this on the backend:
```ruby
report.custom_filtering = true
report.custom_filter_options = [{ id: "any", name: "Any" }, { id: "jpg", name: "JPEG" } ]
```
In our javascript report HTTP call, it will look like:
```js
{
"custom_filtering": true,
"custom_filter_options": [
{
"id": "any",
"name": "Any"
},
{
"id": "jpg",
"name": "JPG"
}
]
}
```
**Frontend changes:** We introduced a generic `filter` param and a `combo-box` which hooks up into the existing framework for fetching a report.
This works alright, with the limitation of being a single custom filter per report. If we wanted to add, for an instance a `filesize filter`, this will not work for us. _I went through with this approach because it is hard to predict and build abstractions for requirements or problems we don't have yet, or might not have._
## How does it look like?
![a1ktg1odde](https://user-images.githubusercontent.com/45508821/50485875-f17edb80-09ee-11e9-92dd-1454ab041fbb.gif)
## More on the bigger picture
The major concern here I have is the solution I introduced might serve the `think small` version of the reporting work, but I don't think it serves the `think big`, I will try to shed some light into why.
Within the current design, It is hard to maintain QueryParams for dynamically generated params (based on the idea of introducing more than one custom filter per report).
To allow ourselves to have more than one generic filter, we will need to:
a. Use the Route's model to retrieve the report's payload (we are now dependent on changes of the QueryParams via computed properties)
b. After retrieving the payload, we can use the `setupController` to define our dynamic QueryParams based on the custom filters definitions we received from the backend
c. Load a custom filter specific Ember component based on the definitions we received from the backend
2019-03-15 08:15:38 -04:00
|
|
|
|
2020-04-22 16:17:53 -04:00
|
|
|
@action
|
2021-06-17 03:15:20 -04:00
|
|
|
onChangeMode(mode) {
|
2020-04-22 16:17:53 -04:00
|
|
|
this.set("currentMode", mode);
|
2020-07-28 10:14:41 -04:00
|
|
|
|
|
|
|
this.send("refreshReport", {
|
|
|
|
chartGrouping: null,
|
|
|
|
});
|
2018-07-19 14:33:11 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_computeReport() {
|
|
|
|
if (!this.element || this.isDestroying || this.isDestroyed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._reports || !this._reports.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
let filteredReports = this._reports.uniqBy("report_key");
|
|
|
|
let report;
|
|
|
|
|
|
|
|
const sort = (r) => {
|
|
|
|
if (r.length > 1) {
|
2019-05-27 04:15:39 -04:00
|
|
|
return r.findBy("type", this.dataSourceName);
|
2018-07-19 14:33:11 -04:00
|
|
|
} else {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
if (!this.startDate || !this.endDate) {
|
2018-07-19 14:33:11 -04:00
|
|
|
report = sort(filteredReports)[0];
|
|
|
|
} else {
|
|
|
|
report = sort(
|
2020-04-22 16:17:53 -04:00
|
|
|
filteredReports.filter((r) => r.report_key.includes(this.reportKey))
|
2018-07-19 14:33:11 -04:00
|
|
|
)[0];
|
|
|
|
|
2020-09-22 10:28:28 -04:00
|
|
|
if (!report) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-19 14:33:11 -04:00
|
|
|
}
|
2021-06-29 15:58:35 -04:00
|
|
|
|
2018-11-12 07:47:24 -05:00
|
|
|
if (report.error === "not_found") {
|
|
|
|
this.set("showFilteringUI", false);
|
|
|
|
}
|
|
|
|
|
2019-05-27 04:42:53 -04:00
|
|
|
this._renderReport(report, this.forcedModes, this.currentMode);
|
2018-07-19 14:33:11 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_renderReport(report, forcedModes, currentMode) {
|
|
|
|
const modes = forcedModes ? forcedModes.split(",") : report.modes;
|
2018-07-25 14:02:21 -04:00
|
|
|
currentMode = currentMode || (modes ? modes[0] : null);
|
2018-07-19 14:33:11 -04:00
|
|
|
|
|
|
|
this.setProperties({
|
|
|
|
model: report,
|
|
|
|
currentMode,
|
2021-06-17 03:15:20 -04:00
|
|
|
options: this._buildOptions(currentMode, report),
|
2018-07-19 14:33:11 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_fetchReport() {
|
2019-01-19 04:05:51 -05:00
|
|
|
this._super(...arguments);
|
2018-07-19 14:33:11 -04:00
|
|
|
|
2018-08-22 05:25:12 -04:00
|
|
|
this.setProperties({ isLoading: true, rateLimitationString: null });
|
2018-07-19 14:33:11 -04:00
|
|
|
|
2019-10-30 09:48:24 -04:00
|
|
|
next(() => {
|
2018-08-24 09:28:01 -04:00
|
|
|
let payload = this._buildPayload(["prev_period"]);
|
2018-07-19 14:33:11 -04:00
|
|
|
|
2018-08-24 09:28:01 -04:00
|
|
|
const callback = (response) => {
|
|
|
|
if (!this.element || this.isDestroying || this.isDestroyed) {
|
|
|
|
return;
|
2018-07-19 14:33:11 -04:00
|
|
|
}
|
2018-08-24 09:28:01 -04:00
|
|
|
|
|
|
|
this.set("isLoading", false);
|
|
|
|
|
|
|
|
if (response === 429) {
|
2018-08-22 12:13:29 -04:00
|
|
|
this.set(
|
|
|
|
"rateLimitationString",
|
|
|
|
I18n.t("admin.dashboard.too_many_requests")
|
|
|
|
);
|
2018-08-24 09:28:01 -04:00
|
|
|
} else if (response === 500) {
|
|
|
|
this.set("model.error", "exception");
|
|
|
|
} else if (response) {
|
|
|
|
this._reports.push(this._loadReport(response));
|
|
|
|
this._computeReport();
|
2018-08-22 05:25:12 -04:00
|
|
|
}
|
2018-08-24 09:28:01 -04:00
|
|
|
};
|
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
ReportLoader.enqueue(this.dataSourceName, payload.data, callback);
|
2018-08-24 09:28:01 -04:00
|
|
|
});
|
2018-07-19 14:33:11 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildPayload(facets) {
|
2021-05-31 08:41:35 -04:00
|
|
|
let payload = { data: { facets } };
|
2018-07-19 14:33:11 -04:00
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.startDate) {
|
2020-04-22 16:17:53 -04:00
|
|
|
payload.data.start_date = moment(this.startDate)
|
|
|
|
.toISOString(true)
|
|
|
|
.split("T")[0];
|
2018-07-19 14:33:11 -04:00
|
|
|
}
|
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.endDate) {
|
2020-04-22 16:17:53 -04:00
|
|
|
payload.data.end_date = moment(this.endDate)
|
|
|
|
.toISOString(true)
|
|
|
|
.split("T")[0];
|
2018-07-19 14:33:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.get("reportOptions.table.limit")) {
|
|
|
|
payload.data.limit = this.get("reportOptions.table.limit");
|
|
|
|
}
|
|
|
|
|
2019-04-26 06:17:10 -04:00
|
|
|
if (this.get("filters.customFilters")) {
|
|
|
|
payload.data.filters = this.get("filters.customFilters");
|
|
|
|
}
|
|
|
|
|
2018-07-19 14:33:11 -04:00
|
|
|
return payload;
|
|
|
|
},
|
|
|
|
|
2021-06-17 03:15:20 -04:00
|
|
|
_buildOptions(mode, report) {
|
2018-07-19 14:33:11 -04:00
|
|
|
if (mode === "table") {
|
|
|
|
const tableOptions = JSON.parse(JSON.stringify(TABLE_OPTIONS));
|
2019-10-29 15:23:50 -04:00
|
|
|
return EmberObject.create(
|
2018-08-01 18:40:59 -04:00
|
|
|
Object.assign(tableOptions, this.get("reportOptions.table") || {})
|
2018-07-19 14:33:11 -04:00
|
|
|
);
|
2021-06-29 15:58:35 -04:00
|
|
|
} else if (mode === "chart") {
|
2018-07-19 14:33:11 -04:00
|
|
|
const chartOptions = JSON.parse(JSON.stringify(CHART_OPTIONS));
|
2019-10-29 15:23:50 -04:00
|
|
|
return EmberObject.create(
|
2020-07-28 10:14:41 -04:00
|
|
|
Object.assign(chartOptions, this.get("reportOptions.chart") || {}, {
|
2021-06-29 15:58:35 -04:00
|
|
|
chartGrouping:
|
|
|
|
this.get("reportOptions.chartGrouping") ||
|
|
|
|
Report.groupingForDatapoints(report.chartData.length),
|
2020-07-28 10:14:41 -04:00
|
|
|
})
|
2018-07-19 14:33:11 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_loadReport(jsonReport) {
|
|
|
|
Report.fillMissingDates(jsonReport, { filledField: "chartData" });
|
|
|
|
|
2019-01-21 09:17:04 -05:00
|
|
|
if (jsonReport.chartData && jsonReport.modes[0] === "stacked_chart") {
|
|
|
|
jsonReport.chartData = jsonReport.chartData.map((chartData) => {
|
|
|
|
if (chartData.length > 40) {
|
|
|
|
return {
|
2021-06-17 03:15:20 -04:00
|
|
|
data: chartData.data,
|
2019-01-21 09:17:04 -05:00
|
|
|
req: chartData.req,
|
2019-01-21 11:10:10 -05:00
|
|
|
label: chartData.label,
|
2019-01-21 09:17:04 -05:00
|
|
|
color: chartData.color,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return chartData;
|
|
|
|
}
|
|
|
|
});
|
2018-07-19 14:33:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (jsonReport.prev_data) {
|
|
|
|
Report.fillMissingDates(jsonReport, {
|
|
|
|
filledField: "prevChartData",
|
|
|
|
dataField: "prev_data",
|
2019-04-26 06:17:10 -04:00
|
|
|
starDate: jsonReport.prev_startDate,
|
|
|
|
endDate: jsonReport.prev_endDate,
|
2018-07-19 14:33:11 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Report.create(jsonReport);
|
|
|
|
},
|
|
|
|
});
|