2021-01-28 18:25:21 +03:00
|
|
|
import Component from '@ember/component';
|
2022-03-14 13:52:04 +03:00
|
|
|
import SearchModal from '../modals/search';
|
2021-01-28 18:25:21 +03:00
|
|
|
import ShortcutsMixin from 'ghost-admin/mixins/shortcuts';
|
2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
2021-01-28 18:25:21 +03:00
|
|
|
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd';
|
2022-02-01 12:34:03 +03:00
|
|
|
import {action} from '@ember/object';
|
2022-01-21 22:25:47 +03:00
|
|
|
import {and, equal, match, or, reads} from '@ember/object/computed';
|
2021-01-28 18:25:21 +03:00
|
|
|
import {getOwner} from '@ember/application';
|
2021-05-12 14:33:36 +03:00
|
|
|
import {htmlSafe} from '@ember/template';
|
2021-01-28 18:25:21 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-02-01 12:34:03 +03:00
|
|
|
import {tagName} from '@ember-decorators/component';
|
2021-03-04 20:34:59 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2021-01-28 18:25:21 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
@tagName('')
|
|
|
|
export default class Main extends Component.extend(ShortcutsMixin) {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service billing;
|
|
|
|
@service config;
|
|
|
|
@service customViews;
|
|
|
|
@service feature;
|
|
|
|
@service ghostPaths;
|
|
|
|
@service modals;
|
|
|
|
@service navigation;
|
|
|
|
@service router;
|
|
|
|
@service session;
|
|
|
|
@service ui;
|
|
|
|
@service whatsNew;
|
|
|
|
@service membersStats;
|
|
|
|
@service settings;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
iconStyle = '';
|
|
|
|
iconClass = '';
|
|
|
|
memberCountLoading = true;
|
|
|
|
memberCount = 0;
|
|
|
|
shortcuts = null;
|
|
|
|
|
|
|
|
@match('router.currentRouteName', /^settings\.integration/)
|
2022-02-10 13:41:36 +03:00
|
|
|
isIntegrationRoute;
|
2021-01-28 18:25:21 +03:00
|
|
|
|
|
|
|
// HACK: {{link-to}} should be doing this automatically but there appears to
|
|
|
|
// be a bug in Ember that's preventing it from working immediately after login
|
2022-02-01 12:34:03 +03:00
|
|
|
@equal('router.currentRouteName', 'site')
|
2022-02-10 13:41:36 +03:00
|
|
|
isOnSite;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
@or('session.user.isAdmin', 'session.user.isEditor')
|
2022-02-10 13:41:36 +03:00
|
|
|
showTagsNavigation;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
@and('config.clientExtensions.menu', 'session.user.isOwnerOnly')
|
2022-02-10 13:41:36 +03:00
|
|
|
showMenuExtension;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
@and('config.clientExtensions.script', 'session.user.isOwnerOnly')
|
2022-02-10 13:41:36 +03:00
|
|
|
showScriptExtension;
|
2021-01-28 18:25:21 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@reads('config.hostSettings.billing.enabled')
|
2022-02-10 13:41:36 +03:00
|
|
|
showBilling;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
2021-01-28 18:25:21 +03:00
|
|
|
init() {
|
2022-02-01 12:34:03 +03:00
|
|
|
super.init(...arguments);
|
2021-01-28 18:25:21 +03:00
|
|
|
|
|
|
|
let shortcuts = {};
|
|
|
|
|
2022-01-11 20:59:48 +03:00
|
|
|
shortcuts[`${ctrlOrCmd}+k`] = {action: 'openSearchModal'};
|
2021-01-28 18:25:21 +03:00
|
|
|
this.shortcuts = shortcuts;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-01-28 18:25:21 +03:00
|
|
|
|
|
|
|
// the menu has a rendering issue (#8307) when the the world is reloaded
|
|
|
|
// during an import which we have worked around by not binding the icon
|
|
|
|
// style directly. However we still need to keep track of changing icons
|
|
|
|
// so that we can refresh when a new icon is uploaded
|
|
|
|
didReceiveAttrs() {
|
2022-02-01 12:34:03 +03:00
|
|
|
super.didReceiveAttrs(...arguments);
|
2021-01-28 18:25:21 +03:00
|
|
|
this._setIconStyle();
|
2021-03-04 20:34:59 +03:00
|
|
|
this._loadMemberCountsTask.perform();
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-01-28 18:25:21 +03:00
|
|
|
|
|
|
|
didInsertElement() {
|
2022-02-01 12:34:03 +03:00
|
|
|
super.didInsertElement(...arguments);
|
2021-01-28 18:25:21 +03:00
|
|
|
this.registerShortcuts();
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-01-28 18:25:21 +03:00
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
this.removeShortcuts();
|
2022-02-01 12:34:03 +03:00
|
|
|
super.willDestroyElement(...arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
transitionToOrRefreshSite() {
|
|
|
|
let {currentRouteName} = this.router;
|
|
|
|
if (currentRouteName === 'site') {
|
|
|
|
getOwner(this).lookup(`route:${currentRouteName}`).refresh();
|
|
|
|
} else {
|
2022-02-02 12:12:16 +03:00
|
|
|
if (this.session.user.isContributor) {
|
|
|
|
this.router.transitionTo('posts');
|
|
|
|
} else {
|
|
|
|
this.router.transitionTo('site');
|
|
|
|
}
|
2021-01-28 18:25:21 +03:00
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
openSearchModal() {
|
2022-03-14 13:52:04 +03:00
|
|
|
return this.modals.open(SearchModal);
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-01-28 18:25:21 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
toggleBillingModal() {
|
|
|
|
this.billing.openBillingWindow(this.router.currentURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
@task(function* () {
|
2021-03-04 20:34:59 +03:00
|
|
|
try {
|
|
|
|
this.set('memberCountLoading', true);
|
|
|
|
const stats = yield this.membersStats.fetchCounts();
|
2021-03-04 16:51:19 +03:00
|
|
|
this.set('memberCountLoading', false);
|
|
|
|
if (stats) {
|
|
|
|
const statsDateObj = this.membersStats.fillCountDates(stats.data) || {};
|
|
|
|
const dateValues = Object.values(statsDateObj);
|
|
|
|
this.set('memberCount', dateValues.length ? dateValues[dateValues.length - 1].total : 0);
|
|
|
|
}
|
2021-03-04 20:34:59 +03:00
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
})
|
2022-02-10 13:41:36 +03:00
|
|
|
_loadMemberCountsTask;
|
2021-03-04 16:51:19 +03:00
|
|
|
|
2021-01-28 18:25:21 +03:00
|
|
|
_setIconStyle() {
|
|
|
|
let icon = this.icon;
|
|
|
|
|
|
|
|
if (icon === this._icon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._icon = icon;
|
|
|
|
|
|
|
|
if (icon && icon.match(/^https?:\/\//i)) {
|
2021-07-21 13:40:55 +03:00
|
|
|
this.set('iconClass', '');
|
2021-01-28 18:25:21 +03:00
|
|
|
this.set('iconStyle', htmlSafe(`background-image: url(${icon})`));
|
|
|
|
return;
|
|
|
|
}
|
2021-03-04 20:34:59 +03:00
|
|
|
|
2021-03-18 20:26:35 +03:00
|
|
|
let iconUrl = 'https://static.ghost.org/v4.0.0/images/ghost-orb-1.png';
|
2021-01-28 18:25:21 +03:00
|
|
|
|
|
|
|
this.set('iconStyle', htmlSafe(`background-image: url(${iconUrl})`));
|
2021-03-18 20:26:35 +03:00
|
|
|
this.set('iconClass', 'gh-nav-logo-default');
|
2021-01-28 18:25:21 +03:00
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|