2022-03-21 19:58:39 +03:00
|
|
|
import Component from '@glimmer/component';
|
2022-03-23 11:51:53 +03:00
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
2022-03-21 21:02:57 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2022-03-21 19:58:39 +03:00
|
|
|
|
2022-03-23 11:51:53 +03:00
|
|
|
const DAYS_OPTIONS = [{
|
|
|
|
name: '7 days',
|
|
|
|
value: 7
|
|
|
|
}, {
|
|
|
|
name: '30 days',
|
|
|
|
value: 30
|
|
|
|
}, {
|
|
|
|
name: '90 days',
|
|
|
|
value: 90
|
|
|
|
}, {
|
|
|
|
name: 'All time',
|
|
|
|
value: 365 // todo: add support for all time (not important for prototype)
|
|
|
|
}];
|
|
|
|
|
2022-03-21 19:58:39 +03:00
|
|
|
export default class DashboardDashboardV5Component extends Component {
|
2022-03-23 11:51:53 +03:00
|
|
|
@service dashboardStats;
|
|
|
|
|
2022-03-21 21:02:57 +03:00
|
|
|
@tracked mockPaidTiers = true;
|
|
|
|
@tracked mockStripeEnabled = true;
|
|
|
|
@tracked mockNewslettersEnabled = true;
|
|
|
|
@tracked mockMembersEnabled = true;
|
2022-03-23 11:51:53 +03:00
|
|
|
|
|
|
|
@tracked days = 30;
|
|
|
|
|
|
|
|
daysOptions = DAYS_OPTIONS;
|
|
|
|
|
|
|
|
get selectedDaysOption() {
|
|
|
|
return this.daysOptions.find(d => d.value === this.days);
|
|
|
|
}
|
2022-03-21 21:02:57 +03:00
|
|
|
|
|
|
|
get hasPaidTiers() {
|
|
|
|
return this.mockPaidTiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
get isStripeEnabled() {
|
|
|
|
return this.mockStripeEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
get areNewslettersEnabled() {
|
|
|
|
return this.mockNewslettersEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
get areMembersEnabled() {
|
|
|
|
return this.mockMembersEnabled;
|
|
|
|
}
|
2022-03-23 11:51:53 +03:00
|
|
|
|
|
|
|
@action
|
|
|
|
onDaysChange(selected) {
|
|
|
|
this.days = selected.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method generates new data and forces a reload for all the charts
|
|
|
|
* Might be better to move this code to a temporary mocking service
|
|
|
|
*/
|
|
|
|
@action
|
|
|
|
updateMockedData(days) {
|
|
|
|
const generateDays = days;
|
|
|
|
const startDate = new Date();
|
|
|
|
startDate.setDate(startDate.getDate() - generateDays + 1);
|
|
|
|
|
|
|
|
const stats = [];
|
|
|
|
let growPeriod = true;
|
|
|
|
let growCount = 0;
|
|
|
|
let growLength = Math.floor(Math.random() * 14);
|
|
|
|
for (let index = 0; index < generateDays; index++) {
|
|
|
|
const date = new Date(startDate.getTime());
|
|
|
|
date.setDate(date.getDate() + index);
|
|
|
|
|
|
|
|
const previous = stats.length ? stats[stats.length - 1] : {free: 0, paid: 0, comped: 0};
|
|
|
|
|
|
|
|
stats.push({
|
|
|
|
date: date.toISOString().split('T')[0],
|
|
|
|
free: previous.free + (growPeriod ? (index + Math.floor(Math.random() * (previous.free) * 0.01)) : 0),
|
|
|
|
paid: previous.paid + Math.floor(Math.random() * (previous.free) * 0.005),
|
|
|
|
comped: previous.comped + Math.floor(Math.random() * 1)
|
|
|
|
});
|
|
|
|
|
|
|
|
if (growPeriod) {
|
|
|
|
growCount += 1;
|
|
|
|
if (growCount > growLength) {
|
|
|
|
growPeriod = false;
|
|
|
|
growCount = 0;
|
|
|
|
growLength = Math.floor(Math.random() * 14);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
growCount += 1;
|
|
|
|
if (growCount > growLength) {
|
|
|
|
growPeriod = true;
|
|
|
|
growCount = 0;
|
|
|
|
growLength = Math.floor(Math.random() * 14);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dashboardStats.mockedMemberCountStats = stats;
|
|
|
|
|
|
|
|
this.dashboardStats.mockedMemberCounts = {
|
|
|
|
total: stats[stats.length - 1].paid + stats[stats.length - 1].free + stats[stats.length - 1].comped,
|
|
|
|
paid: stats[stats.length - 1].paid,
|
|
|
|
free: stats[stats.length - 1].free + stats[stats.length - 1].comped
|
|
|
|
};
|
|
|
|
|
|
|
|
// Force update all data
|
|
|
|
this.dashboardStats.loadMembersCounts();
|
|
|
|
this.dashboardStats.loadMrrStats(this.days);
|
|
|
|
this.dashboardStats.loadMemberCountStats(this.days);
|
|
|
|
this.dashboardStats.loadLastSeen();
|
|
|
|
}
|
2022-03-21 19:58:39 +03:00
|
|
|
}
|