Ghost/ghost/admin/app/services/dashboard-stats.js
Simon Backx 98c93b66c8 Added dashboard 5.0 stats service and days dropdown
refs https://github.com/TryGhost/Team/issues/1432

- Added very basic state selection at the bottom of dashboard 5.0
- Added a dashboard stats service, who is responsible for fetching and returning stats data
- Added POC for days dropdown with communication and reload between ember components
- Added proper automatic number and plural formatting for member counts
2022-03-23 10:05:47 +01:00

97 lines
1.9 KiB
JavaScript

import Service from '@ember/service';
import {tracked} from '@glimmer/tracking';
export default class DashboardStatsService extends Service {
@tracked
useMocks = true;
@tracked
memberCounts = null;
@tracked
memberCountStats = [];
@tracked
mrrStats = [];
@tracked
membersLastSeen30d = null;
@tracked
membersLastSeen7d = null;
@tracked
newsletterSubscribers = null;
@tracked
emailsSent30d = null;
@tracked
emailOpenRateStats = null;
loadMembersCounts() {
if (this.useMocks) {
this.memberCounts = this.mockedMemberCounts;
return;
}
// Normal implementation
// @todo
}
/**
* Loads the members graphs
* - total paid
* - total members
* for each day in the last {{days}} days
* @param {number} days The number of days to fetch data for
*/
loadMemberCountStats(days) {
if (this.useMocks) {
this.memberCountStats = this.mockedMemberCountStats.slice(-days);
return;
}
// Normal implementation
// @todo
}
/**
* Loads the mrr graphs
* @param {number} days The number of days to fetch data for
*/
loadMrrStats(days) {
if (this.useMocks) {
this.mmrStats = this.mockedMrrStats.slice(-days);
return;
}
// Normal implementation
// @todo
}
loadLastSeen() {
if (this.useMocks) {
this.membersLastSeen30d = 620;
this.membersLastSeen7d = 320;
return;
}
// Normal implementation
// @todo
}
// Mocked data (move this to a mocking service?)
@tracked
mockedMemberCountStats = [];
@tracked
mockedMrrStats = [];
@tracked
mockedMemberCounts = {
total: 0,
paid: 0,
free: 0
};
}