mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-13 14:39:52 +03:00
9fbb63cf41
refs https://github.com/TryGhost/Team/issues/1376 - adjusted tests so they are in sync with expected dashboard behaviour - removed `dashboardHideGettingStarted` feature and it's usage in the `showMembersGraphs` property as there's no longer a resource box to dismiss
104 lines
2.9 KiB
JavaScript
104 lines
2.9 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;
|
|
|
|
return this.showMembersData
|
|
&& this.checkMemberCountTask.performCount > 0
|
|
&& hasMembers;
|
|
}
|
|
|
|
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});
|
|
}
|
|
}
|
|
}
|