discourse/app/assets/javascripts/admin/addon/mixins/period-computation.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.4 KiB
JavaScript
Raw Normal View History

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));
},
},
});