mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 17:32:15 +03:00
24df9781cc
refs https://github.com/TryGhost/Ghost/issues/9060 - add `{{gh-psm-template-select}}` component - allows selection of a custom template for a post if the active theme has custom templates - loads themes on render, only hitting the server if not already in the store - disables select if post slug matches a `post-*.hbs` or `page-*.hbs` template - adds `customTemplate` attr to `Post` model - adds `templates` attr to `Theme` model with CPs to pull out custom vs post/page override templates - add `.gh-select.disabled` styles to make disabled selects look visually disabled
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import Model from 'ember-data/model';
|
|
import attr from 'ember-data/attr';
|
|
import {computed} from '@ember/object';
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
export default Model.extend({
|
|
active: attr('boolean'),
|
|
errors: attr('raw'),
|
|
name: attr('string'),
|
|
package: attr('raw'),
|
|
templates: attr('raw', {defaultValue: () => []}),
|
|
warnings: attr('raw'),
|
|
|
|
customTemplates: computed('templates.[]', function () {
|
|
let templates = this.get('templates') || [];
|
|
|
|
return templates.filter(function (template) {
|
|
return isBlank(template.slug);
|
|
});
|
|
}),
|
|
|
|
slugTemplates: computed('templates.[]', function () {
|
|
let templates = this.get('templates') || [];
|
|
|
|
return templates.filter(function (template) {
|
|
return !isBlank(template.slug);
|
|
});
|
|
}),
|
|
|
|
activate() {
|
|
let adapter = this.store.adapterFor(this.constructor.modelName);
|
|
|
|
return adapter.activate(this).then(() => {
|
|
// the server only gives us the newly active theme back so we need
|
|
// to manually mark other themes as inactive in the store
|
|
let activeThemes = this.store.peekAll('theme').filterBy('active', true);
|
|
|
|
activeThemes.forEach((theme) => {
|
|
if (theme !== this) {
|
|
// store.push is necessary to avoid dirty records that cause
|
|
// problems when we get new data back in subsequent requests
|
|
this.store.push({data: {
|
|
id: theme.id,
|
|
type: 'theme',
|
|
attributes: {active: false}
|
|
}});
|
|
}
|
|
});
|
|
|
|
return this;
|
|
});
|
|
}
|
|
});
|