2025-01-29 10:33:43 +10:00
|
|
|
import { tracked } from "@glimmer/tracking";
|
2024-01-18 13:06:42 +01:00
|
|
|
import Controller from "@ember/controller";
|
2025-01-29 10:33:43 +10:00
|
|
|
import { action } from "@ember/object";
|
2024-03-06 18:05:11 +01:00
|
|
|
import { service } from "@ember/service";
|
2025-01-29 10:33:43 +10:00
|
|
|
import { TrackedObject } from "@ember-compat/tracked-built-ins";
|
2024-01-18 13:06:42 +01:00
|
|
|
import CustomDateRangeModal from "../components/modal/custom-date-range";
|
|
|
|
|
|
|
|
export default class AdminDashboardTabController extends Controller {
|
|
|
|
@service modal;
|
|
|
|
|
2025-01-29 10:33:43 +10:00
|
|
|
@tracked endDate = moment().locale("en").utc().endOf("day");
|
|
|
|
@tracked startDate = this.calculateStartDate();
|
|
|
|
@tracked
|
|
|
|
filters = new TrackedObject({
|
|
|
|
startDate: this.startDate,
|
|
|
|
endDate: this.endDate,
|
|
|
|
});
|
|
|
|
|
2024-01-18 13:06:42 +01:00
|
|
|
queryParams = ["period"];
|
|
|
|
period = "monthly";
|
|
|
|
|
2025-01-29 10:33:43 +10:00
|
|
|
calculateStartDate() {
|
2024-01-18 13:06:42 +01:00
|
|
|
const fullDay = moment().locale("en").utc().endOf("day");
|
|
|
|
|
|
|
|
switch (this.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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2025-01-29 10:33:43 +10:00
|
|
|
setCustomDateRange(startDate, endDate) {
|
|
|
|
this.startDate = startDate;
|
|
|
|
this.endDate = endDate;
|
|
|
|
this.filters.startDate = this.startDate;
|
|
|
|
this.filters.endDate = this.endDate;
|
2024-01-18 13:06:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setPeriod(period) {
|
2025-01-29 10:33:43 +10:00
|
|
|
this.set("period", period);
|
|
|
|
this.startDate = this.calculateStartDate();
|
|
|
|
this.filters.startDate = this.startDate;
|
|
|
|
this.filters.endDate = this.endDate;
|
2024-01-18 13:06:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
openCustomDateRangeModal() {
|
|
|
|
this.modal.show(CustomDateRangeModal, {
|
|
|
|
model: {
|
|
|
|
startDate: this.startDate,
|
|
|
|
endDate: this.endDate,
|
|
|
|
setCustomDateRange: this.setCustomDateRange,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|