mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-13 14:39:52 +03:00
696fca0f9e
refs https://github.com/TryGhost/Team/issues/1406 - added fetch of a single member to the dashboard initialisation if we don't already have some members loaded in memory - added `showMembersGraphs` getter used in the conditional for rendering the members graphs block component - if `improvedOnboarding` flag is disabled, return `showMemberData` so existing functionality is retained - will return `false` if until the single-member fetch has completed if we don't already have any members in memory - returns `true` if any members exist or the "get started" dashboard resources block has been dismissed
105 lines
3.0 KiB
JavaScript
105 lines
3.0 KiB
JavaScript
import Controller from '@ember/controller';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class DashboardController extends Controller {
|
|
@service feature;
|
|
@service session;
|
|
@service membersStats;
|
|
@service store;
|
|
@service settings;
|
|
@service whatsNew;
|
|
|
|
@tracked topMembersData = null;
|
|
@tracked topMembersError = null;
|
|
@tracked topMembersLoading = false;
|
|
|
|
@tracked whatsNewEntries = null;
|
|
@tracked whatsNewEntriesLoading = null;
|
|
@tracked whatsNewEntriesError = null;
|
|
|
|
get topMembersDataHasOpenRates() {
|
|
return this.topMembersData && this.topMembersData.find((member) => {
|
|
return member.emailOpenRate !== null;
|
|
});
|
|
}
|
|
|
|
get showMembersData() {
|
|
return this.settings.get('membersSignupAccess') !== 'none';
|
|
}
|
|
|
|
get showMembersGraphs() {
|
|
if (!this.feature.improvedOnboarding) {
|
|
return this.showMembersData;
|
|
}
|
|
|
|
const hasMembers = this.store.peekAll('member').length > 0;
|
|
const gettingStartedBannerDismissed = this.feature.dashboardHideGettingStarted === true;
|
|
|
|
return this.showMembersData
|
|
&& this.checkMemberCountTask.performCount > 0
|
|
&& (hasMembers || gettingStartedBannerDismissed);
|
|
}
|
|
|
|
initialise() {
|
|
this.loadTopMembers();
|
|
this.loadWhatsNew();
|
|
this.checkMemberCountTask.perform();
|
|
}
|
|
|
|
loadTopMembers() {
|
|
if (this.feature.membersActivityFeed) {
|
|
return;
|
|
}
|
|
|
|
this.topMembersLoading = true;
|
|
let query = {
|
|
filter: 'email_open_rate:-null',
|
|
order: 'email_open_rate desc',
|
|
limit: 5
|
|
};
|
|
this.store.query('member', query).then((result) => {
|
|
if (!result.length) {
|
|
return this.store.query('member', {
|
|
filter: 'status:paid',
|
|
order: 'created_at asc',
|
|
limit: 5
|
|
});
|
|
}
|
|
return result;
|
|
}).then((result) => {
|
|
this.topMembersData = result;
|
|
this.topMembersLoading = false;
|
|
}).catch((error) => {
|
|
this.topMembersError = error;
|
|
this.topMembersLoading = false;
|
|
});
|
|
}
|
|
|
|
loadWhatsNew() {
|
|
this.whatsNewEntriesLoading = true;
|
|
this.whatsNew.fetchLatest.perform().then(() => {
|
|
this.whatsNewEntriesLoading = false;
|
|
this.whatsNewEntries = this.whatsNew.entries.slice(0, 3);
|
|
}, (error) => {
|
|
this.whatsNewEntriesError = error;
|
|
this.whatsNewEntriesLoading = false;
|
|
});
|
|
}
|
|
|
|
@action
|
|
dismissLaunchBanner() {
|
|
this.settings.set('editorIsLaunchComplete', true);
|
|
this.settings.save();
|
|
}
|
|
|
|
@task
|
|
*checkMemberCountTask() {
|
|
if (this.store.peekAll('member').length === 0) {
|
|
yield this.store.query('member', {limit: 1});
|
|
}
|
|
}
|
|
}
|