mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
26d05aecd8
no issue - the Ember Data `Model` class has an `errors` property by default that is set to a `DS.Errors` instance but the Theme model was overriding that with an `errors` attr - it hasn't been an issue so far but causes problems in Ember/Ember Data 3.28.x because that tries to use the `DS.Errors` interface on the overridden attr property which then throws errors because the `errors` attr doesn't have the right methods
53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
import Model, {attr} from '@ember-data/model';
|
|
import {computed} from '@ember/object';
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
export default Model.extend({
|
|
active: attr('boolean'),
|
|
gscanErrors: attr('raw', {defaultValue: () => []}), // renamed from 'errors' to avoid clash with Ember Data Model's `errors` property
|
|
name: attr('string'),
|
|
package: attr('raw'),
|
|
templates: attr('raw', {defaultValue: () => []}),
|
|
warnings: attr('raw', {defaultValue: () => []}),
|
|
|
|
customTemplates: computed('templates.[]', function () {
|
|
let templates = this.templates || [];
|
|
|
|
return templates.filter(function (template) {
|
|
return isBlank(template.slug);
|
|
});
|
|
}),
|
|
|
|
slugTemplates: computed('templates.[]', function () {
|
|
let templates = this.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;
|
|
});
|
|
}
|
|
});
|