2022-03-22 18:37:17 +03:00
|
|
|
import Component from '@glimmer/component';
|
2022-03-24 12:05:08 +03:00
|
|
|
import {action} from '@ember/object';
|
2022-03-23 18:38:16 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-03-24 12:05:08 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
|
|
|
|
const STATUS_OPTIONS = [{
|
2022-04-06 20:11:46 +03:00
|
|
|
name: 'All',
|
2022-03-24 12:05:08 +03:00
|
|
|
value: 'total'
|
|
|
|
}, {
|
2022-04-06 20:11:46 +03:00
|
|
|
name: 'Paid',
|
2022-03-24 12:05:08 +03:00
|
|
|
value: 'paid'
|
|
|
|
}, {
|
2022-04-06 20:11:46 +03:00
|
|
|
name: 'Free',
|
2022-03-24 12:05:08 +03:00
|
|
|
value: 'free'
|
|
|
|
}];
|
2022-03-22 18:37:17 +03:00
|
|
|
|
2022-04-12 15:09:00 +03:00
|
|
|
export default class Engagement extends Component {
|
2022-03-23 18:38:16 +03:00
|
|
|
@service dashboardStats;
|
|
|
|
|
2022-03-24 17:32:34 +03:00
|
|
|
@action
|
2022-03-23 18:38:16 +03:00
|
|
|
loadCharts() {
|
2022-03-24 14:04:18 +03:00
|
|
|
this.dashboardStats.lastSeenFilterStatus = this.status;
|
|
|
|
this.dashboardStats.loadLastSeen();
|
2022-04-01 11:48:01 +03:00
|
|
|
this.dashboardStats.loadMemberCountStats();
|
2022-03-23 18:38:16 +03:00
|
|
|
}
|
|
|
|
|
2022-03-24 12:05:08 +03:00
|
|
|
@tracked status = 'total';
|
|
|
|
statusOptions = STATUS_OPTIONS;
|
|
|
|
|
|
|
|
get selectedStatusOption() {
|
|
|
|
return this.statusOptions.find(option => option.value === this.status);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
onSwitchStatus(selected) {
|
|
|
|
this.status = selected.value;
|
2022-03-24 14:04:18 +03:00
|
|
|
this.dashboardStats.lastSeenFilterStatus = this.status;
|
|
|
|
this.dashboardStats.loadLastSeen();
|
2022-03-23 18:38:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get loading() {
|
|
|
|
return this.dashboardStats.memberCounts === null
|
|
|
|
|| !this.dashboardStats.memberCounts[this.status]
|
|
|
|
|| this.dashboardStats.membersLastSeen30d === null
|
|
|
|
|| this.dashboardStats.membersLastSeen7d === null;
|
|
|
|
}
|
|
|
|
|
2022-03-22 18:37:17 +03:00
|
|
|
get data30Days() {
|
2022-03-23 18:38:16 +03:00
|
|
|
if (this.loading) {
|
|
|
|
return '- %';
|
|
|
|
}
|
|
|
|
const total = this.dashboardStats.memberCounts[this.status];
|
|
|
|
const part = this.dashboardStats.membersLastSeen30d;
|
|
|
|
|
|
|
|
if (total <= 0) {
|
|
|
|
return '- %';
|
|
|
|
}
|
|
|
|
|
|
|
|
const percentage = Math.round(part / total * 100);
|
|
|
|
return `${percentage}%`;
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get data7Days() {
|
2022-03-23 18:38:16 +03:00
|
|
|
if (this.loading) {
|
|
|
|
return '- %';
|
|
|
|
}
|
|
|
|
const total = this.dashboardStats.memberCounts[this.status];
|
|
|
|
const part = this.dashboardStats.membersLastSeen7d;
|
|
|
|
|
|
|
|
if (total <= 0) {
|
|
|
|
return '- %';
|
|
|
|
}
|
|
|
|
|
|
|
|
const percentage = Math.round(part / total * 100);
|
|
|
|
return `${percentage}%`;
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|
|
|
|
}
|