mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 08:53:40 +08:00
702f7a5a67
Prior to this fix, weekly could be 8 days and we could have differences between period chooser text and actual results in the chart. A good followup to this PR would be to add custom date ranges in period-chooser component.
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
import discourseComputed from "discourse-common/utils/decorators";
|
|
import DiscourseURL from "discourse/lib/url";
|
|
import Mixin from "@ember/object/mixin";
|
|
|
|
export default Mixin.create({
|
|
queryParams: ["period"],
|
|
period: "monthly",
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
|
|
this.availablePeriods = ["yearly", "quarterly", "monthly", "weekly"];
|
|
},
|
|
|
|
@discourseComputed("period")
|
|
startDate(period) {
|
|
let fullDay = moment().locale("en").utc().endOf("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(6, "days").startOf("day");
|
|
break;
|
|
case "monthly":
|
|
return fullDay.subtract(1, "month").startOf("day");
|
|
break;
|
|
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));
|
|
},
|
|
},
|
|
});
|