2024-08-01 00:37:15 +08:00
|
|
|
import { computed } from "@ember/object";
|
2019-10-31 04:13:48 +08:00
|
|
|
import Mixin from "@ember/object/mixin";
|
2023-10-11 02:38:59 +08:00
|
|
|
import DiscourseURL from "discourse/lib/url";
|
2024-01-18 20:06:42 +08:00
|
|
|
import deprecated from "discourse-common/lib/deprecated";
|
2018-07-20 02:33:11 +08:00
|
|
|
|
2019-10-31 03:03:08 +08:00
|
|
|
export default Mixin.create({
|
2018-07-20 02:33:11 +08:00
|
|
|
queryParams: ["period"],
|
|
|
|
period: "monthly",
|
|
|
|
|
2019-05-28 18:15:12 +08:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
2024-01-18 20:06:42 +08:00
|
|
|
deprecated(
|
|
|
|
"PeriodComputation mixin is deprecated. Use AdminDashboardTabController instead.",
|
|
|
|
{
|
|
|
|
id: "discourse.period-mixin",
|
|
|
|
since: "3.2.0.beta5-dev",
|
|
|
|
}
|
|
|
|
);
|
2019-05-28 18:15:12 +08:00
|
|
|
this.availablePeriods = ["yearly", "quarterly", "monthly", "weekly"];
|
|
|
|
},
|
2018-07-20 02:33:11 +08:00
|
|
|
|
2024-08-01 00:37:15 +08:00
|
|
|
startDate: computed("period", {
|
|
|
|
get() {
|
|
|
|
const period = this.period;
|
2024-01-15 17:34:28 +08:00
|
|
|
const fullDay = moment().locale("en").utc().endOf("day");
|
|
|
|
|
|
|
|
switch (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");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
set(period) {
|
|
|
|
return period;
|
|
|
|
},
|
2024-08-01 00:37:15 +08:00
|
|
|
}),
|
2018-07-20 02:33:11 +08:00
|
|
|
|
2024-08-01 00:37:15 +08:00
|
|
|
get lastWeek() {
|
2018-07-20 02:33:11 +08:00
|
|
|
return moment().locale("en").utc().endOf("day").subtract(1, "week");
|
|
|
|
},
|
|
|
|
|
2024-08-01 00:37:15 +08:00
|
|
|
get lastMonth() {
|
2018-08-22 18:37:05 +08:00
|
|
|
return moment().locale("en").utc().startOf("day").subtract(1, "month");
|
|
|
|
},
|
|
|
|
|
2024-08-01 00:37:15 +08:00
|
|
|
get endDate() {
|
|
|
|
return moment().locale("en").utc().endOf("day");
|
|
|
|
},
|
|
|
|
set endDate(value) {
|
|
|
|
/* noop */
|
2018-07-20 02:33:11 +08:00
|
|
|
},
|
|
|
|
|
2024-08-01 00:37:15 +08:00
|
|
|
get today() {
|
2018-08-22 18:37:05 +08:00
|
|
|
return moment().locale("en").utc().endOf("day");
|
|
|
|
},
|
|
|
|
|
2018-07-20 02:33:11 +08:00
|
|
|
actions: {
|
|
|
|
changePeriod(period) {
|
|
|
|
DiscourseURL.routeTo(this._reportsForPeriodURL(period));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|