2022-03-22 18:37:17 +03:00
|
|
|
import Component from '@glimmer/component';
|
2022-03-23 18:38:16 +03:00
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
2022-03-22 18:37:17 +03:00
|
|
|
|
|
|
|
export default class ChartEmailOpenRate extends Component {
|
2022-03-23 18:38:16 +03:00
|
|
|
@service dashboardStats;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this method when you need to fetch new data from the server. In this component, it will get called
|
|
|
|
* when the days parameter changes and on initialisation.
|
|
|
|
*/
|
|
|
|
@action
|
|
|
|
loadCharts() {
|
|
|
|
// The dashboard stats service will take care or reusing and limiting API-requests between charts
|
|
|
|
this.dashboardStats.loadNewsletterSubscribers();
|
|
|
|
this.dashboardStats.loadEmailsSent();
|
|
|
|
this.dashboardStats.loadEmailOpenRateStats();
|
|
|
|
}
|
|
|
|
|
2022-03-22 18:37:17 +03:00
|
|
|
get dataSubscribers() {
|
2022-03-23 18:38:16 +03:00
|
|
|
// @todo: show paid, free, total together
|
2022-03-28 14:19:56 +03:00
|
|
|
return this.dashboardStats.newsletterSubscribers ?? {
|
|
|
|
total: 0,
|
|
|
|
free: 0,
|
|
|
|
paid: 0
|
|
|
|
};
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get dataEmailsSent() {
|
2022-03-23 18:38:16 +03:00
|
|
|
return this.dashboardStats.emailsSent30d ?? 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get loading() {
|
|
|
|
return this.dashboardStats.emailOpenRateStats === null;
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get chartType() {
|
|
|
|
return 'bar';
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartData() {
|
2022-03-28 14:49:44 +03:00
|
|
|
const stats = this.dashboardStats.emailOpenRateStats;
|
2022-03-23 18:38:16 +03:00
|
|
|
const labels = stats.map(stat => stat.title);
|
2022-03-28 14:49:44 +03:00
|
|
|
const data = stats.map(stat => stat.email.openRate);
|
2022-03-23 18:38:16 +03:00
|
|
|
|
2022-03-22 18:37:17 +03:00
|
|
|
return {
|
2022-03-23 18:38:16 +03:00
|
|
|
labels,
|
2022-03-22 18:37:17 +03:00
|
|
|
datasets: [{
|
2022-03-23 18:38:16 +03:00
|
|
|
data,
|
2022-03-22 18:37:17 +03:00
|
|
|
fill: false,
|
|
|
|
backgroundColor: '#14b8ff',
|
|
|
|
tension: 0.1
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartOptions() {
|
|
|
|
return {
|
|
|
|
legend: {
|
|
|
|
display: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get chartHeight() {
|
2022-03-24 17:02:13 +03:00
|
|
|
return 100;
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|
|
|
|
}
|