2021-02-04 20:36:29 +03:00
|
|
|
import Controller from '@ember/controller';
|
2021-02-25 12:57:46 +03:00
|
|
|
import {action} from '@ember/object';
|
2021-02-04 20:36:29 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-03-07 16:26:52 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2022-05-17 10:34:34 +03:00
|
|
|
|
|
|
|
// Options 30 and 90 need an extra day to be able to distribute ticks/gridlines evenly
|
|
|
|
const DAYS_OPTIONS = [{
|
|
|
|
name: '7 Days',
|
|
|
|
value: 7
|
|
|
|
}, {
|
|
|
|
name: '30 Days',
|
|
|
|
value: 30 + 1
|
|
|
|
}, {
|
|
|
|
name: '90 Days',
|
|
|
|
value: 90 + 1
|
|
|
|
}];
|
2021-02-04 20:36:29 +03:00
|
|
|
|
|
|
|
export default class DashboardController extends Controller {
|
2022-05-17 10:34:34 +03:00
|
|
|
@service dashboardStats;
|
2022-09-28 14:56:38 +03:00
|
|
|
@service membersUtils;
|
2021-02-18 17:17:10 +03:00
|
|
|
|
2022-05-17 10:34:34 +03:00
|
|
|
daysOptions = DAYS_OPTIONS;
|
2021-02-24 18:59:01 +03:00
|
|
|
|
2022-05-17 10:34:34 +03:00
|
|
|
@task
|
|
|
|
*loadSiteStatusTask() {
|
|
|
|
yield this.dashboardStats.loadSiteStatus();
|
|
|
|
return {};
|
2021-04-20 11:08:15 +03:00
|
|
|
}
|
|
|
|
|
2022-09-28 14:56:38 +03:00
|
|
|
@action
|
2022-05-17 10:34:34 +03:00
|
|
|
onDaysChange(selected) {
|
|
|
|
this.days = selected.value;
|
|
|
|
}
|
2022-03-07 16:26:52 +03:00
|
|
|
|
2022-05-17 10:34:34 +03:00
|
|
|
get days() {
|
|
|
|
return this.dashboardStats.chartDays;
|
|
|
|
}
|
2022-03-07 16:26:52 +03:00
|
|
|
|
2022-05-17 10:34:34 +03:00
|
|
|
set days(days) {
|
|
|
|
this.dashboardStats.chartDays = days;
|
2022-03-07 16:26:52 +03:00
|
|
|
}
|
|
|
|
|
2022-05-17 10:34:34 +03:00
|
|
|
get selectedDaysOption() {
|
|
|
|
return this.daysOptions.find(d => d.value === this.days);
|
2021-02-18 20:13:51 +03:00
|
|
|
}
|
|
|
|
|
2022-05-17 10:34:34 +03:00
|
|
|
get isLoading() {
|
|
|
|
return this.dashboardStats.siteStatus === null;
|
2021-02-24 18:59:01 +03:00
|
|
|
}
|
2021-02-25 12:57:46 +03:00
|
|
|
|
2022-05-17 10:34:34 +03:00
|
|
|
get totalMembers() {
|
|
|
|
return this.dashboardStats.memberCounts?.total ?? 0;
|
2021-02-25 12:57:46 +03:00
|
|
|
}
|
2022-03-07 16:26:52 +03:00
|
|
|
|
2022-05-17 10:34:34 +03:00
|
|
|
get isTotalMembersZero() {
|
|
|
|
return this.dashboardStats.memberCounts && this.totalMembers === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasPaidTiers() {
|
|
|
|
return this.dashboardStats.siteStatus?.hasPaidTiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
get areNewslettersEnabled() {
|
|
|
|
return this.dashboardStats.siteStatus?.newslettersEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
get areMembersEnabled() {
|
|
|
|
return this.dashboardStats.siteStatus?.membersEnabled;
|
2022-03-07 16:26:52 +03:00
|
|
|
}
|
2021-02-18 17:17:10 +03:00
|
|
|
}
|