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";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
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
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("period")
|
2024-01-15 17:34:28 +08:00
|
|
|
startDate: {
|
|
|
|
get(period) {
|
|
|
|
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;
|
|
|
|
},
|
2018-07-20 02:33:11 +08:00
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed()
|
2018-07-20 02:33:11 +08:00
|
|
|
lastWeek() {
|
|
|
|
return moment().locale("en").utc().endOf("day").subtract(1, "week");
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed()
|
2018-08-22 18:37:05 +08:00
|
|
|
lastMonth() {
|
|
|
|
return moment().locale("en").utc().startOf("day").subtract(1, "month");
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed()
|
2024-01-15 17:34:28 +08:00
|
|
|
endDate: {
|
|
|
|
get() {
|
|
|
|
return moment().locale("en").utc().endOf("day");
|
|
|
|
},
|
|
|
|
|
|
|
|
set(endDate) {
|
|
|
|
return endDate;
|
|
|
|
},
|
2018-07-20 02:33:11 +08:00
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed()
|
2018-08-22 18:37:05 +08:00
|
|
|
today() {
|
|
|
|
return moment().locale("en").utc().endOf("day");
|
|
|
|
},
|
|
|
|
|
2018-07-20 02:33:11 +08:00
|
|
|
actions: {
|
|
|
|
changePeriod(period) {
|
|
|
|
DiscourseURL.routeTo(this._reportsForPeriodURL(period));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|