2019-11-07 16:38:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2018-07-19 14:33:11 -04:00
|
|
|
import DiscourseURL from "discourse/lib/url";
|
2019-10-30 16:13:48 -04:00
|
|
|
import Mixin from "@ember/object/mixin";
|
2018-07-19 14:33:11 -04:00
|
|
|
|
2019-10-30 15:03:08 -04:00
|
|
|
export default Mixin.create({
|
2018-07-19 14:33:11 -04:00
|
|
|
queryParams: ["period"],
|
|
|
|
period: "monthly",
|
|
|
|
|
2019-05-28 06:15:12 -04:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
this.availablePeriods = ["yearly", "quarterly", "monthly", "weekly"];
|
|
|
|
},
|
2018-07-19 14:33:11 -04:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("period")
|
2018-07-19 14:33:11 -04:00
|
|
|
startDate(period) {
|
2020-10-05 04:32:12 -04:00
|
|
|
let fullDay = moment().locale("en").utc().endOf("day");
|
2018-07-19 14:33:11 -04:00
|
|
|
|
|
|
|
switch (period) {
|
|
|
|
case "yearly":
|
|
|
|
return fullDay.subtract(1, "year").startOf("day");
|
|
|
|
break;
|
|
|
|
case "quarterly":
|
|
|
|
return fullDay.subtract(3, "month").startOf("day");
|
|
|
|
break;
|
|
|
|
case "weekly":
|
2020-10-05 04:32:12 -04:00
|
|
|
return fullDay.subtract(6, "days").startOf("day");
|
2018-07-19 14:33:11 -04:00
|
|
|
break;
|
|
|
|
case "monthly":
|
|
|
|
return fullDay.subtract(1, "month").startOf("day");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return fullDay.subtract(1, "month").startOf("day");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed()
|
2018-07-19 14:33:11 -04:00
|
|
|
lastWeek() {
|
|
|
|
return moment().locale("en").utc().endOf("day").subtract(1, "week");
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed()
|
2018-08-22 06:37:05 -04:00
|
|
|
lastMonth() {
|
|
|
|
return moment().locale("en").utc().startOf("day").subtract(1, "month");
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed()
|
2018-07-19 14:33:11 -04:00
|
|
|
endDate() {
|
2020-10-05 04:32:12 -04:00
|
|
|
return moment().locale("en").utc().endOf("day");
|
2018-07-19 14:33:11 -04:00
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed()
|
2018-08-22 06:37:05 -04:00
|
|
|
today() {
|
|
|
|
return moment().locale("en").utc().endOf("day");
|
|
|
|
},
|
|
|
|
|
2018-07-19 14:33:11 -04:00
|
|
|
actions: {
|
|
|
|
changePeriod(period) {
|
|
|
|
DiscourseURL.routeTo(this._reportsForPeriodURL(period));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|