From 87d443f070582351c211efff989adee39449c30c Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 22 Aug 2018 12:37:05 +0200 Subject: [PATCH] FIX: counters were showing future instead of past (#6299) --- .../admin-dashboard-next-general.js.es6 | 8 ++ .../admin/mixins/period-computation.js.es6 | 17 ++++ .../templates/dashboard_next_general.hbs | 1 + .../acceptance/dashboard-next-test.js.es6 | 29 +++++++ .../fixtures/page_view_total_reqs.js.es6 | 85 ++++++++++++++++++- 5 files changed, 139 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard-next-general.js.es6 b/app/assets/javascripts/admin/controllers/admin-dashboard-next-general.js.es6 index 7f81972a16b..84ad3623274 100644 --- a/app/assets/javascripts/admin/controllers/admin-dashboard-next-general.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-dashboard-next-general.js.es6 @@ -40,6 +40,14 @@ export default Ember.Controller.extend(PeriodComputationMixin, { ]; }, + @computed + activityMetricsFilters() { + return { + startDate: this.get("lastMonth"), + endDate: this.get("today") + }; + }, + @computed trendingSearchOptions() { return { table: { total: false, limit: 8 } }; diff --git a/app/assets/javascripts/admin/mixins/period-computation.js.es6 b/app/assets/javascripts/admin/mixins/period-computation.js.es6 index 8ed2346cd53..6cad0c6dee0 100644 --- a/app/assets/javascripts/admin/mixins/period-computation.js.es6 +++ b/app/assets/javascripts/admin/mixins/period-computation.js.es6 @@ -42,6 +42,15 @@ export default Ember.Mixin.create({ .subtract(1, "week"); }, + @computed() + lastMonth() { + return moment() + .locale("en") + .utc() + .startOf("day") + .subtract(1, "month"); + }, + @computed() endDate() { return moment() @@ -51,6 +60,14 @@ export default Ember.Mixin.create({ .endOf("day"); }, + @computed() + today() { + return moment() + .locale("en") + .utc() + .endOf("day"); + }, + actions: { changePeriod(period) { DiscourseURL.routeTo(this._reportsForPeriodURL(period)); diff --git a/app/assets/javascripts/admin/templates/dashboard_next_general.hbs b/app/assets/javascripts/admin/templates/dashboard_next_general.hbs index 593914f44dc..c0ce8d74a1f 100644 --- a/app/assets/javascripts/admin/templates/dashboard_next_general.hbs +++ b/app/assets/javascripts/admin/templates/dashboard_next_general.hbs @@ -79,6 +79,7 @@ {{#each activityMetrics as |metric|}} {{admin-report showHeader=false + filters=activityMetricsFilters forcedModes="counters" dataSourceName=metric}} {{/each}} diff --git a/test/javascripts/acceptance/dashboard-next-test.js.es6 b/test/javascripts/acceptance/dashboard-next-test.js.es6 index fa8fef4bfb5..d142e32d720 100644 --- a/test/javascripts/acceptance/dashboard-next-test.js.es6 +++ b/test/javascripts/acceptance/dashboard-next-test.js.es6 @@ -29,3 +29,32 @@ QUnit.test("Visit dashboard next page", async assert => { "displays problems" ); }); + +QUnit.test("it has counters", async assert => { + await visit("/admin"); + + assert.equal( + $(".admin-report.page-view-total-reqs .today-count") + .text() + .trim(), + "1.1k" + ); + assert.equal( + $(".admin-report.page-view-total-reqs .yesterday-count") + .text() + .trim(), + "2.5k" + ); + assert.equal( + $(".admin-report.page-view-total-reqs .sevendays-count") + .text() + .trim(), + "18.6k" + ); + assert.equal( + $(".admin-report.page-view-total-reqs .thirty-days-count") + .text() + .trim(), + "80.8k" + ); +}); diff --git a/test/javascripts/fixtures/page_view_total_reqs.js.es6 b/test/javascripts/fixtures/page_view_total_reqs.js.es6 index 9ad51ed7864..4b66b1b5f89 100644 --- a/test/javascripts/fixtures/page_view_total_reqs.js.es6 +++ b/test/javascripts/fixtures/page_view_total_reqs.js.es6 @@ -1,7 +1,90 @@ +const startDate = moment() + .locale("en") + .utc() + .startOf("day") + .subtract(1, "month"); + +const endDate = moment() + .locale("en") + .utc() + .endOf("day"); + +const data = [ + 851, + 3805, + 2437, + 3768, + 4476, + 3021, + 1285, + 1120, + 3932, + 2777, + 3298, + 3198, + 3601, + 1249, + 1046, + 3212, + 3358, + 3306, + 2618, + 2679, + 910, + 875, + 3877, + 2342, + 2305, + 3534, + 3713, + 1133, + 1350, + 4048, + 2523, + 1062 +]; + export default { "/admin/reports/page_view_total_reqs": { report: { - report_key: "page_view_total_reqs" + type: "page_view_total_reqs", + title: "Pageviews", + xaxis: "Day", + yaxis: "Total Pageviews", + description: null, + data: [...data].map((d, i) => { + return { + x: moment(startDate) + .add(i, "days") + .format("YYYY-MM-DD"), + y: d + }; + }), + start_date: startDate.toISOString(), + end_date: endDate.toISOString(), + prev_data: null, + prev_start_date: "2018-06-20T00:00:00Z", + prev_end_date: "2018-07-23T00:00:00Z", + category_id: null, + group_id: null, + prev30Days: 58110, + dates_filtering: true, + report_key: `reports:page_view_total_reqs:${startDate.format( + "YYYYMMDD" + )}:${endDate.format("YYYYMMDD")}:[:prev_period]:2`, + labels: [ + { type: "date", property: "x", title: "Day" }, + { type: "number", property: "y", title: "Count" } + ], + processing: false, + average: false, + percent: false, + higher_is_better: true, + category_filtering: false, + group_filtering: false, + modes: ["table", "chart"], + icon: "file", + total: 921672 } } };