mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
d51f2bcf23
closes https://github.com/TryGhost/Admin/pull/2107 - updated related babel dependencies - bumped eslint - ran `yarn lint:js --fix` - added eslint ignore comments for some required non-camel-case properties
80 lines
2.1 KiB
JavaScript
80 lines
2.1 KiB
JavaScript
import Component from '@ember/component';
|
|
import classic from 'ember-classic-decorator';
|
|
import {action, computed} from '@ember/object';
|
|
import {isEmpty} from '@ember/utils';
|
|
import {inject as service} from '@ember/service';
|
|
import {tagName} from '@ember-decorators/component';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
@classic
|
|
@tagName('')
|
|
export default class GhPsmTemplateSelect extends Component {
|
|
@service store;
|
|
|
|
post = null;
|
|
|
|
// internal properties
|
|
activeTheme = null;
|
|
|
|
// closure actions
|
|
onTemplateSelect() {}
|
|
|
|
// computed properties
|
|
@computed('activeTheme.customTemplates.[]')
|
|
get customTemplates() {
|
|
let templates = this.get('activeTheme.customTemplates') || [];
|
|
let defaultTemplate = {
|
|
filename: '',
|
|
name: 'Default'
|
|
};
|
|
|
|
return isEmpty(templates) ? templates : [defaultTemplate, ...templates.sortBy('name')];
|
|
}
|
|
|
|
@computed('post.{page,slug}', 'activeTheme.slugTemplates.[]')
|
|
get matchedSlugTemplate() {
|
|
let slug = this.get('post.slug');
|
|
let type = this.post.constructor.modelName;
|
|
|
|
let [matchedTemplate] = this.get('activeTheme.slugTemplates').filter(function (template) {
|
|
return template.for.includes(type) && template.slug === slug;
|
|
});
|
|
|
|
return matchedTemplate;
|
|
}
|
|
|
|
@computed('post.customTemplate', 'customTemplates.[]')
|
|
get selectedTemplate() {
|
|
let templates = this.customTemplates;
|
|
let filename = this.get('post.customTemplate');
|
|
|
|
return templates.findBy('filename', filename);
|
|
}
|
|
|
|
// hooks
|
|
didInsertElement() {
|
|
super.didInsertElement(...arguments);
|
|
this.loadActiveTheme.perform();
|
|
}
|
|
|
|
@action
|
|
selectTemplate(template) {
|
|
this.onTemplateSelect(template.filename);
|
|
}
|
|
|
|
// tasks
|
|
@task(function* () {
|
|
let store = this.store;
|
|
let themes = yield store.peekAll('theme');
|
|
|
|
if (isEmpty(themes)) {
|
|
themes = yield store.findAll('theme');
|
|
}
|
|
|
|
let activeTheme = themes.filterBy('active', true).get('firstObject');
|
|
|
|
this.set('activeTheme', activeTheme);
|
|
})
|
|
loadActiveTheme;
|
|
}
|