mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
7fdf3c7433
refs https://github.com/TryGhost/Team/issues/1444 - Moved control panel to separate component - Moved storage of amount of graph days to load to dashboard stats service - Moved storage of engagement filtered status to dashboard stats service - Dropdown state selector - Save state in localstorage - SiteStatus object and loadStatus methods in dashboard stats service and mock service
82 lines
2.1 KiB
JavaScript
82 lines
2.1 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
const STATUS_OPTIONS = [{
|
|
name: 'All members',
|
|
value: 'total'
|
|
}, {
|
|
name: 'Paid members',
|
|
value: 'paid'
|
|
}, {
|
|
name: 'Free members',
|
|
value: 'free'
|
|
}];
|
|
|
|
export default class ChartEngagement extends Component {
|
|
@service dashboardStats;
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.loadCharts();
|
|
}
|
|
|
|
loadCharts() {
|
|
this.dashboardStats.lastSeenFilterStatus = this.status;
|
|
this.dashboardStats.loadLastSeen();
|
|
this.dashboardStats.loadMembersCounts();
|
|
}
|
|
|
|
@tracked status = 'total';
|
|
statusOptions = STATUS_OPTIONS;
|
|
|
|
get selectedStatusOption() {
|
|
return this.statusOptions.find(option => option.value === this.status);
|
|
}
|
|
|
|
@action
|
|
onSwitchStatus(selected) {
|
|
this.status = selected.value;
|
|
this.dashboardStats.lastSeenFilterStatus = this.status;
|
|
this.dashboardStats.loadLastSeen();
|
|
}
|
|
|
|
get loading() {
|
|
return this.dashboardStats.memberCounts === null
|
|
|| !this.dashboardStats.memberCounts[this.status]
|
|
|| this.dashboardStats.membersLastSeen30d === null
|
|
|| this.dashboardStats.membersLastSeen7d === null;
|
|
}
|
|
|
|
get data30Days() {
|
|
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}%`;
|
|
}
|
|
|
|
get data7Days() {
|
|
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}%`;
|
|
}
|
|
}
|