discourse/app/assets/javascripts/admin/addon/mixins/period-computation.js
Jarek Radosz 8cf13977a1
DEV: Fix or disable various lint rules (#24630)
A grab bag of smaller issues (constructor-super, no-fallthrough, ember/no-private-routing-service, no-unreachable, no-async-promise-executor)
2023-11-29 15:14:53 +01:00

59 lines
1.4 KiB
JavaScript

import Mixin from "@ember/object/mixin";
import DiscourseURL from "discourse/lib/url";
import discourseComputed from "discourse-common/utils/decorators";
export default Mixin.create({
queryParams: ["period"],
period: "monthly",
init() {
this._super(...arguments);
this.availablePeriods = ["yearly", "quarterly", "monthly", "weekly"];
},
@discourseComputed("period")
startDate(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");
}
},
@discourseComputed()
lastWeek() {
return moment().locale("en").utc().endOf("day").subtract(1, "week");
},
@discourseComputed()
lastMonth() {
return moment().locale("en").utc().startOf("day").subtract(1, "month");
},
@discourseComputed()
endDate() {
return moment().locale("en").utc().endOf("day");
},
@discourseComputed()
today() {
return moment().locale("en").utc().endOf("day");
},
actions: {
changePeriod(period) {
DiscourseURL.routeTo(this._reportsForPeriodURL(period));
},
},
});