1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/models/theme.js
Kevin Ansfield 68442c5676 Custom Post Templates UI (#878)
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
2017-10-10 14:26:19 +02:00

53 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;
});
}
});