mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
DEV: Replace period mixin with a component (#25292)
This commit is contained in:
parent
6fa836d781
commit
b2b32d6af8
@ -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,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<PeriodChooser
|
||||||
|
@period={{@period}}
|
||||||
|
@action={{@setPeriod}}
|
||||||
|
@content={{this.availablePeriods}}
|
||||||
|
@fullDay={{false}}
|
||||||
|
/>
|
||||||
|
<DButton
|
||||||
|
@icon="cog"
|
||||||
|
@action={{this.openCustomDateRangeModal}}
|
||||||
|
@title="admin.dashboard.custom_date_range"
|
||||||
|
class="custom-date-range-button"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
}
|
@ -1,15 +1,14 @@
|
|||||||
import Controller, { inject as controller } from "@ember/controller";
|
import { inject as controller } from "@ember/controller";
|
||||||
import { action, computed } from "@ember/object";
|
import { computed } from "@ember/object";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import { setting } from "discourse/lib/computed";
|
import { setting } from "discourse/lib/computed";
|
||||||
import getURL from "discourse-common/lib/get-url";
|
import getURL from "discourse-common/lib/get-url";
|
||||||
import { makeArray } from "discourse-common/lib/helpers";
|
import { makeArray } from "discourse-common/lib/helpers";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import I18n from "discourse-i18n";
|
import I18n from "discourse-i18n";
|
||||||
import PeriodComputationMixin from "admin/mixins/period-computation";
|
|
||||||
import AdminDashboard from "admin/models/admin-dashboard";
|
import AdminDashboard from "admin/models/admin-dashboard";
|
||||||
import Report from "admin/models/report";
|
import Report from "admin/models/report";
|
||||||
import CustomDateRangeModal from "../components/modal/custom-date-range";
|
import AdminDashboardTabController from "./admin-dashboard-tab";
|
||||||
|
|
||||||
function staticReport(reportType) {
|
function staticReport(reportType) {
|
||||||
return computed("reports.[]", function () {
|
return computed("reports.[]", function () {
|
||||||
@ -17,10 +16,7 @@ function staticReport(reportType) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class AdminDashboardGeneralController extends Controller.extend(
|
export default class AdminDashboardGeneralController extends AdminDashboardTabController {
|
||||||
PeriodComputationMixin
|
|
||||||
) {
|
|
||||||
@service modal;
|
|
||||||
@service router;
|
@service router;
|
||||||
@service siteSettings;
|
@service siteSettings;
|
||||||
@controller("exception") exceptionController;
|
@controller("exception") exceptionController;
|
||||||
@ -74,10 +70,26 @@ export default class AdminDashboardGeneralController extends Controller.extend(
|
|||||||
].some((x) => !this.hiddenReports.includes(x));
|
].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
|
@discourseComputed
|
||||||
activityMetricsFilters() {
|
activityMetricsFilters() {
|
||||||
|
const lastMonth = moment()
|
||||||
|
.locale("en")
|
||||||
|
.utc()
|
||||||
|
.startOf("day")
|
||||||
|
.subtract(1, "month");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
startDate: this.lastMonth,
|
startDate: lastMonth,
|
||||||
endDate: this.today,
|
endDate: this.today,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -147,29 +159,4 @@ export default class AdminDashboardGeneralController extends Controller.extend(
|
|||||||
.finally(() => this.set("isLoading", false));
|
.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,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,8 @@
|
|||||||
import Controller from "@ember/controller";
|
import { computed } from "@ember/object";
|
||||||
import { action, computed } from "@ember/object";
|
|
||||||
import { inject as service } from "@ember/service";
|
|
||||||
import getURL from "discourse-common/lib/get-url";
|
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import PeriodComputationMixin from "admin/mixins/period-computation";
|
import AdminDashboardTabController from "./admin-dashboard-tab";
|
||||||
import CustomDateRangeModal from "../components/modal/custom-date-range";
|
|
||||||
|
|
||||||
export default class AdminDashboardModerationController extends Controller.extend(
|
|
||||||
PeriodComputationMixin
|
|
||||||
) {
|
|
||||||
@service modal;
|
|
||||||
|
|
||||||
|
export default class AdminDashboardModerationController extends AdminDashboardTabController {
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
flagsStatusOptions() {
|
flagsStatusOptions() {
|
||||||
return {
|
return {
|
||||||
@ -39,33 +31,19 @@ export default class AdminDashboardModerationController extends Controller.exten
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@discourseComputed("startDate", "endDate")
|
@computed("startDate", "endDate")
|
||||||
filters(startDate, endDate) {
|
get filters() {
|
||||||
return { startDate, endDate };
|
return { startDate: this.startDate, endDate: this.endDate };
|
||||||
}
|
}
|
||||||
|
|
||||||
@discourseComputed("lastWeek", "endDate")
|
@discourseComputed("endDate")
|
||||||
lastWeekfilters(startDate, endDate) {
|
lastWeekFilters(endDate) {
|
||||||
return { startDate, endDate };
|
const lastWeek = moment()
|
||||||
}
|
.locale("en")
|
||||||
|
.utc()
|
||||||
|
.endOf("day")
|
||||||
|
.subtract(1, "week");
|
||||||
|
|
||||||
_reportsForPeriodURL(period) {
|
return { lastWeek, endDate };
|
||||||
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,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import Mixin from "@ember/object/mixin";
|
import Mixin from "@ember/object/mixin";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
|
import deprecated from "discourse-common/lib/deprecated";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
export default Mixin.create({
|
export default Mixin.create({
|
||||||
@ -9,6 +10,13 @@ export default Mixin.create({
|
|||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
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"];
|
this.availablePeriods = ["yearly", "quarterly", "monthly", "weekly"];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
<ConditionalLoadingSpinner @condition={{this.isLoading}}>
|
<ConditionalLoadingSpinner @condition={{this.isLoading}}>
|
||||||
<span>
|
<PluginOutlet @name="admin-dashboard-general-top" @connectorTagName="div" />
|
||||||
<PluginOutlet @name="admin-dashboard-general-top" @connectorTagName="div" />
|
|
||||||
</span>
|
|
||||||
|
|
||||||
{{#if this.isCommunityHealthVisible}}
|
{{#if this.isCommunityHealthVisible}}
|
||||||
<div class="community-health section">
|
<div class="community-health section">
|
||||||
@ -12,20 +10,14 @@
|
|||||||
{{i18n "admin.dashboard.community_health"}}
|
{{i18n "admin.dashboard.community_health"}}
|
||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
<span>
|
|
||||||
<PeriodChooser
|
<DashboardPeriodSelector
|
||||||
@period={{this.period}}
|
@period={{this.period}}
|
||||||
@action={{action "changePeriod"}}
|
@setPeriod={{this.setPeriod}}
|
||||||
@content={{this.availablePeriods}}
|
@startDate={{this.startDate}}
|
||||||
@fullDay={{false}}
|
@endDate={{this.endDate}}
|
||||||
/>
|
@setCustomDateRange={{this.setCustomDateRange}}
|
||||||
<DButton
|
/>
|
||||||
@icon="cog"
|
|
||||||
class="custom-date-range-button"
|
|
||||||
@action={{this.openCustomDateRangeModal}}
|
|
||||||
@title="admin.dashboard.custom_date_range"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section-body">
|
<div class="section-body">
|
||||||
@ -203,11 +195,9 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span>
|
<PluginOutlet
|
||||||
<PluginOutlet
|
@name="admin-dashboard-general-bottom"
|
||||||
@name="admin-dashboard-general-bottom"
|
@connectorTagName="div"
|
||||||
@connectorTagName="div"
|
@outletArgs={{hash filters=this.filters}}
|
||||||
@outletArgs={{hash filters=this.filters}}
|
/>
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</ConditionalLoadingSpinner>
|
</ConditionalLoadingSpinner>
|
@ -1,10 +1,8 @@
|
|||||||
<div class="sections">
|
<div class="sections">
|
||||||
<span>
|
<PluginOutlet
|
||||||
<PluginOutlet
|
@name="admin-dashboard-moderation-top"
|
||||||
@name="admin-dashboard-moderation-top"
|
@connectorTagName="div"
|
||||||
@connectorTagName="div"
|
/>
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
{{#if this.isModeratorsActivityVisible}}
|
{{#if this.isModeratorsActivityVisible}}
|
||||||
<div class="moderators-activity section">
|
<div class="moderators-activity section">
|
||||||
@ -14,20 +12,14 @@
|
|||||||
{{i18n "admin.dashboard.moderators_activity"}}
|
{{i18n "admin.dashboard.moderators_activity"}}
|
||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
<span>
|
|
||||||
<PeriodChooser
|
<DashboardPeriodSelector
|
||||||
@period={{this.period}}
|
@period={{this.period}}
|
||||||
@action={{action "changePeriod"}}
|
@setPeriod={{this.setPeriod}}
|
||||||
@content={{this.availablePeriods}}
|
@startDate={{this.startDate}}
|
||||||
@fullDay={{false}}
|
@endDate={{this.endDate}}
|
||||||
/>
|
@setCustomDateRange={{this.setCustomDateRange}}
|
||||||
<DButton
|
/>
|
||||||
@icon="cog"
|
|
||||||
class="custom-date-range-button"
|
|
||||||
@action={{this.openCustomDateRangeModal}}
|
|
||||||
@title="admin.dashboard.custom_date_range"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section-body">
|
<div class="section-body">
|
||||||
@ -44,26 +36,24 @@
|
|||||||
<AdminReport
|
<AdminReport
|
||||||
@dataSourceName="flags_status"
|
@dataSourceName="flags_status"
|
||||||
@reportOptions={{this.flagsStatusOptions}}
|
@reportOptions={{this.flagsStatusOptions}}
|
||||||
@filters={{this.lastWeekfilters}}
|
@filters={{this.lastWeekFilters}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<AdminReport
|
<AdminReport
|
||||||
@dataSourceName="post_edits"
|
@dataSourceName="post_edits"
|
||||||
@filters={{this.lastWeekfilters}}
|
@filters={{this.lastWeekFilters}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<AdminReport
|
<AdminReport
|
||||||
@dataSourceName="user_flagging_ratio"
|
@dataSourceName="user_flagging_ratio"
|
||||||
@filters={{this.lastWeekfilters}}
|
@filters={{this.lastWeekFilters}}
|
||||||
@reportOptions={{this.userFlaggingRatioOptions}}
|
@reportOptions={{this.userFlaggingRatioOptions}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<span>
|
<PluginOutlet
|
||||||
<PluginOutlet
|
@name="admin-dashboard-moderation-bottom"
|
||||||
@name="admin-dashboard-moderation-bottom"
|
@connectorTagName="div"
|
||||||
@connectorTagName="div"
|
@outletArgs={{hash filters=this.lastWeekFilters}}
|
||||||
@outletArgs={{hash filters=this.lastWeekfilters}}
|
/>
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
@ -1,27 +1,20 @@
|
|||||||
<div class="sections">
|
<div class="sections">
|
||||||
<span>
|
<PluginOutlet @name="admin-dashboard-security-top" @connectorTagName="div" />
|
||||||
<PluginOutlet
|
|
||||||
@name="admin-dashboard-security-top"
|
|
||||||
@connectorTagName="div"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<div class="main-section">
|
<div class="main-section">
|
||||||
<AdminReport
|
<AdminReport
|
||||||
@dataSourceName="suspicious_logins"
|
@dataSourceName="suspicious_logins"
|
||||||
@filters={{this.lastWeekfilters}}
|
@filters={{this.lastWeekFilters}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<AdminReport
|
<AdminReport
|
||||||
@dataSourceName="staff_logins"
|
@dataSourceName="staff_logins"
|
||||||
@filters={{this.lastWeekfilters}}
|
@filters={{this.lastWeekFilters}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<span>
|
<PluginOutlet
|
||||||
<PluginOutlet
|
@name="admin-dashboard-security-bottom"
|
||||||
@name="admin-dashboard-security-bottom"
|
@connectorTagName="div"
|
||||||
@connectorTagName="div"
|
/>
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
Loading…
Reference in New Issue
Block a user