diff --git a/app/assets/javascripts/admin/addon/components/dashboard-period-selector.gjs b/app/assets/javascripts/admin/addon/components/dashboard-period-selector.gjs new file mode 100644 index 00000000000..d6519749b24 --- /dev/null +++ b/app/assets/javascripts/admin/addon/components/dashboard-period-selector.gjs @@ -0,0 +1,40 @@ +import Component from "@glimmer/component"; +import { action } from "@ember/object"; +import { inject as service } from "@ember/service"; +import DButton from "discourse/components/d-button"; +import PeriodChooser from "select-kit/components/period-chooser"; +import CustomDateRangeModal from "../components/modal/custom-date-range"; + +export default class DashboardPeriodSelector extends Component { + @service modal; + + availablePeriods = ["yearly", "quarterly", "monthly", "weekly"]; + + @action + openCustomDateRangeModal() { + this.modal.show(CustomDateRangeModal, { + model: { + startDate: this.args.startDate, + endDate: this.args.endDate, + setCustomDateRange: this.args.setCustomDateRange, + }, + }); + } + + +} diff --git a/app/assets/javascripts/admin/addon/controllers/admin-dashboard-general.js b/app/assets/javascripts/admin/addon/controllers/admin-dashboard-general.js index dcc8deca526..80cacc2cd14 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-dashboard-general.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-dashboard-general.js @@ -1,15 +1,14 @@ -import Controller, { inject as controller } from "@ember/controller"; -import { action, computed } from "@ember/object"; +import { inject as controller } from "@ember/controller"; +import { computed } from "@ember/object"; import { inject as service } from "@ember/service"; import { setting } from "discourse/lib/computed"; import getURL from "discourse-common/lib/get-url"; import { makeArray } from "discourse-common/lib/helpers"; import discourseComputed from "discourse-common/utils/decorators"; import I18n from "discourse-i18n"; -import PeriodComputationMixin from "admin/mixins/period-computation"; import AdminDashboard from "admin/models/admin-dashboard"; import Report from "admin/models/report"; -import CustomDateRangeModal from "../components/modal/custom-date-range"; +import AdminDashboardTabController from "./admin-dashboard-tab"; function staticReport(reportType) { return computed("reports.[]", function () { @@ -17,10 +16,7 @@ function staticReport(reportType) { }); } -export default class AdminDashboardGeneralController extends Controller.extend( - PeriodComputationMixin -) { - @service modal; +export default class AdminDashboardGeneralController extends AdminDashboardTabController { @service router; @service siteSettings; @controller("exception") exceptionController; @@ -74,10 +70,26 @@ export default class AdminDashboardGeneralController extends Controller.extend( ].some((x) => !this.hiddenReports.includes(x)); } + @discourseComputed + today() { + return moment().locale("en").utc().endOf("day"); + } + + @computed("startDate", "endDate") + get filters() { + return { startDate: this.startDate, endDate: this.endDate }; + } + @discourseComputed activityMetricsFilters() { + const lastMonth = moment() + .locale("en") + .utc() + .startOf("day") + .subtract(1, "month"); + return { - startDate: this.lastMonth, + startDate: lastMonth, endDate: this.today, }; } @@ -147,29 +159,4 @@ export default class AdminDashboardGeneralController extends Controller.extend( .finally(() => this.set("isLoading", false)); } } - - @discourseComputed("startDate", "endDate") - filters(startDate, endDate) { - return { startDate, endDate }; - } - - _reportsForPeriodURL(period) { - return getURL(`/admin?period=${period}`); - } - - @action - setCustomDateRange(startDate, endDate) { - this.setProperties({ startDate, endDate }); - } - - @action - openCustomDateRangeModal() { - this.modal.show(CustomDateRangeModal, { - model: { - startDate: this.startDate, - endDate: this.endDate, - setCustomDateRange: this.setCustomDateRange, - }, - }); - } } diff --git a/app/assets/javascripts/admin/addon/controllers/admin-dashboard-moderation.js b/app/assets/javascripts/admin/addon/controllers/admin-dashboard-moderation.js index b4e79e41b07..a5fe8a27446 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-dashboard-moderation.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-dashboard-moderation.js @@ -1,16 +1,8 @@ -import Controller from "@ember/controller"; -import { action, computed } from "@ember/object"; -import { inject as service } from "@ember/service"; -import getURL from "discourse-common/lib/get-url"; +import { computed } from "@ember/object"; import discourseComputed from "discourse-common/utils/decorators"; -import PeriodComputationMixin from "admin/mixins/period-computation"; -import CustomDateRangeModal from "../components/modal/custom-date-range"; - -export default class AdminDashboardModerationController extends Controller.extend( - PeriodComputationMixin -) { - @service modal; +import AdminDashboardTabController from "./admin-dashboard-tab"; +export default class AdminDashboardModerationController extends AdminDashboardTabController { @discourseComputed flagsStatusOptions() { return { @@ -39,33 +31,19 @@ export default class AdminDashboardModerationController extends Controller.exten }; } - @discourseComputed("startDate", "endDate") - filters(startDate, endDate) { - return { startDate, endDate }; + @computed("startDate", "endDate") + get filters() { + return { startDate: this.startDate, endDate: this.endDate }; } - @discourseComputed("lastWeek", "endDate") - lastWeekfilters(startDate, endDate) { - return { startDate, endDate }; - } + @discourseComputed("endDate") + lastWeekFilters(endDate) { + const lastWeek = moment() + .locale("en") + .utc() + .endOf("day") + .subtract(1, "week"); - _reportsForPeriodURL(period) { - return getURL(`/admin/dashboard/moderation?period=${period}`); - } - - @action - setCustomDateRange(startDate, endDate) { - this.setProperties({ startDate, endDate }); - } - - @action - openCustomDateRangeModal() { - this.modal.show(CustomDateRangeModal, { - model: { - startDate: this.startDate, - endDate: this.endDate, - setCustomDateRange: this.setCustomDateRange, - }, - }); + return { lastWeek, endDate }; } } diff --git a/app/assets/javascripts/admin/addon/controllers/admin-dashboard-tab.js b/app/assets/javascripts/admin/addon/controllers/admin-dashboard-tab.js new file mode 100644 index 00000000000..1432adbd270 --- /dev/null +++ b/app/assets/javascripts/admin/addon/controllers/admin-dashboard-tab.js @@ -0,0 +1,57 @@ +import Controller from "@ember/controller"; +import { action, computed } from "@ember/object"; +import { inject as service } from "@ember/service"; +import CustomDateRangeModal from "../components/modal/custom-date-range"; + +export default class AdminDashboardTabController extends Controller { + @service modal; + + queryParams = ["period"]; + period = "monthly"; + + endDate = moment().locale("en").utc().endOf("day"); + _startDate; + + @computed("_startDate", "period") + get startDate() { + if (this._startDate) { + return this._startDate; + } + + const fullDay = moment().locale("en").utc().endOf("day"); + + switch (this.period) { + case "yearly": + return fullDay.subtract(1, "year").startOf("day"); + case "quarterly": + return fullDay.subtract(3, "month").startOf("day"); + case "weekly": + return fullDay.subtract(6, "days").startOf("day"); + case "monthly": + return fullDay.subtract(1, "month").startOf("day"); + default: + return fullDay.subtract(1, "month").startOf("day"); + } + } + + @action + setCustomDateRange(_startDate, endDate) { + this.setProperties({ _startDate, endDate }); + } + + @action + setPeriod(period) { + this.setProperties({ period, _startDate: null }); + } + + @action + openCustomDateRangeModal() { + this.modal.show(CustomDateRangeModal, { + model: { + startDate: this.startDate, + endDate: this.endDate, + setCustomDateRange: this.setCustomDateRange, + }, + }); + } +} diff --git a/app/assets/javascripts/admin/addon/mixins/period-computation.js b/app/assets/javascripts/admin/addon/mixins/period-computation.js index 1968df7c2c3..5a97d298272 100644 --- a/app/assets/javascripts/admin/addon/mixins/period-computation.js +++ b/app/assets/javascripts/admin/addon/mixins/period-computation.js @@ -1,5 +1,6 @@ import Mixin from "@ember/object/mixin"; import DiscourseURL from "discourse/lib/url"; +import deprecated from "discourse-common/lib/deprecated"; import discourseComputed from "discourse-common/utils/decorators"; export default Mixin.create({ @@ -9,6 +10,13 @@ export default Mixin.create({ init() { this._super(...arguments); + deprecated( + "PeriodComputation mixin is deprecated. Use AdminDashboardTabController instead.", + { + id: "discourse.period-mixin", + since: "3.2.0.beta5-dev", + } + ); this.availablePeriods = ["yearly", "quarterly", "monthly", "weekly"]; }, diff --git a/app/assets/javascripts/admin/addon/templates/dashboard_general.hbs b/app/assets/javascripts/admin/addon/templates/dashboard_general.hbs index 6215319581d..702bed7c1c0 100644 --- a/app/assets/javascripts/admin/addon/templates/dashboard_general.hbs +++ b/app/assets/javascripts/admin/addon/templates/dashboard_general.hbs @@ -1,7 +1,5 @@ - - - + {{#if this.isCommunityHealthVisible}}
@@ -12,20 +10,14 @@ {{i18n "admin.dashboard.community_health"}} - - - - + +
@@ -203,11 +195,9 @@ {{/if}}
- - - +
\ No newline at end of file diff --git a/app/assets/javascripts/admin/addon/templates/dashboard_moderation.hbs b/app/assets/javascripts/admin/addon/templates/dashboard_moderation.hbs index 3a1ef805dd3..bb3d1f2c9f3 100644 --- a/app/assets/javascripts/admin/addon/templates/dashboard_moderation.hbs +++ b/app/assets/javascripts/admin/addon/templates/dashboard_moderation.hbs @@ -1,10 +1,8 @@
- - - + {{#if this.isModeratorsActivityVisible}}
@@ -14,20 +12,14 @@ {{i18n "admin.dashboard.moderators_activity"}} - - - - + +
@@ -44,26 +36,24 @@ - - - +
\ No newline at end of file diff --git a/app/assets/javascripts/admin/addon/templates/dashboard_security.hbs b/app/assets/javascripts/admin/addon/templates/dashboard_security.hbs index 887cdb3c0fb..d91ce4dcbfc 100644 --- a/app/assets/javascripts/admin/addon/templates/dashboard_security.hbs +++ b/app/assets/javascripts/admin/addon/templates/dashboard_security.hbs @@ -1,27 +1,20 @@
- - - +
- - - +
\ No newline at end of file