2022-03-22 18:37:17 +03:00
|
|
|
import Component from '@glimmer/component';
|
2022-03-23 18:38:16 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-03-22 18:37:17 +03:00
|
|
|
|
|
|
|
export default class ChartEngagement extends Component {
|
2022-03-23 18:38:16 +03:00
|
|
|
@service dashboardStats;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
this.loadCharts();
|
|
|
|
}
|
|
|
|
|
|
|
|
loadCharts() {
|
|
|
|
this.dashboardStats.loadLastSeen(this.status);
|
|
|
|
this.dashboardStats.loadMembersCounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
get status() {
|
|
|
|
// todo: this should come from a dropdown
|
|
|
|
// + reload stats after changing this value
|
|
|
|
return 'total';
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|