2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2018-07-20 02:33:11 +08:00
|
|
|
import DiscourseURL from "discourse/lib/url";
|
2019-10-31 04:13:48 +08:00
|
|
|
import Mixin from "@ember/object/mixin";
|
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);
|
|
|
|
|
|
|
|
this.availablePeriods = ["yearly", "quarterly", "monthly", "weekly"];
|
|
|
|
},
|
2018-07-20 02:33:11 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("period")
|
2018-07-20 02:33:11 +08:00
|
|
|
startDate(period) {
|
|
|
|
let fullDay = moment()
|
|
|
|
.locale("en")
|
|
|
|
.utc()
|
|
|
|
.subtract(1, "day");
|
|
|
|
|
|
|
|
switch (period) {
|
|
|
|
case "yearly":
|
|
|
|
return fullDay.subtract(1, "year").startOf("day");
|
|
|
|
break;
|
|
|
|
case "quarterly":
|
|
|
|
return fullDay.subtract(3, "month").startOf("day");
|
|
|
|
break;
|
|
|
|
case "weekly":
|
|
|
|
return fullDay.subtract(1, "week").startOf("day");
|
|
|
|
break;
|
|
|
|
case "monthly":
|
|
|
|
return fullDay.subtract(1, "month").startOf("day");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return fullDay.subtract(1, "month").startOf("day");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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()
|
2018-07-20 02:33:11 +08:00
|
|
|
endDate() {
|
|
|
|
return moment()
|
|
|
|
.locale("en")
|
|
|
|
.utc()
|
|
|
|
.subtract(1, "day")
|
|
|
|
.endOf("day");
|
|
|
|
},
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|