2020-01-16 20:01:12 +03:00
|
|
|
import Model, {attr} from '@ember-data/model';
|
2017-10-10 15:26:19 +03:00
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {isBlank} from '@ember/utils';
|
2017-02-21 21:28:44 +03:00
|
|
|
|
|
|
|
export default Model.extend({
|
2017-10-10 15:26:19 +03:00
|
|
|
active: attr('boolean'),
|
2023-02-28 16:28:32 +03:00
|
|
|
gscanErrors: attr('raw', {defaultValue: () => []}), // renamed from 'errors' to avoid clash with Ember Data Model's `errors` property
|
2017-02-21 21:28:44 +03:00
|
|
|
name: attr('string'),
|
2017-03-03 18:31:42 +03:00
|
|
|
package: attr('raw'),
|
2017-10-10 15:26:19 +03:00
|
|
|
templates: attr('raw', {defaultValue: () => []}),
|
2023-01-06 15:44:27 +03:00
|
|
|
warnings: attr('raw', {defaultValue: () => []}),
|
2017-10-10 15:26:19 +03:00
|
|
|
|
|
|
|
customTemplates: computed('templates.[]', function () {
|
2019-03-06 16:53:54 +03:00
|
|
|
let templates = this.templates || [];
|
2017-10-10 15:26:19 +03:00
|
|
|
|
|
|
|
return templates.filter(function (template) {
|
|
|
|
return isBlank(template.slug);
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
slugTemplates: computed('templates.[]', function () {
|
2019-03-06 16:53:54 +03:00
|
|
|
let templates = this.templates || [];
|
2017-10-10 15:26:19 +03:00
|
|
|
|
|
|
|
return templates.filter(function (template) {
|
|
|
|
return !isBlank(template.slug);
|
|
|
|
});
|
|
|
|
}),
|
2017-03-03 18:31:42 +03:00
|
|
|
|
2023-07-21 19:03:38 +03:00
|
|
|
codedWarnings: computed('warnings.[]', function () {
|
|
|
|
const codedWarnings = {};
|
|
|
|
|
|
|
|
this.warnings.forEach((warning) => {
|
|
|
|
if (!codedWarnings[warning.code]) {
|
|
|
|
codedWarnings[warning.code] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
codedWarnings[warning.code].push(warning);
|
|
|
|
});
|
|
|
|
|
|
|
|
return codedWarnings;
|
|
|
|
}),
|
|
|
|
|
2023-07-21 19:39:13 +03:00
|
|
|
codedErrors: computed('gscanErrors.[]', function () {
|
2023-07-21 19:03:38 +03:00
|
|
|
const codedErrors = {};
|
|
|
|
|
2023-07-21 19:39:13 +03:00
|
|
|
this.gscanErrors.forEach((error) => {
|
2023-07-21 19:03:38 +03:00
|
|
|
if (!codedErrors[error.code]) {
|
|
|
|
codedErrors[error.code] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
codedErrors[error.code].push(error);
|
|
|
|
});
|
|
|
|
|
|
|
|
return codedErrors;
|
|
|
|
}),
|
|
|
|
|
|
|
|
codedErrorsAndWarnings: computed('codedErrors.[]', 'codedWarnings.[]', function () {
|
|
|
|
const codedErrorsAndWarnings = {};
|
|
|
|
|
|
|
|
Object.keys(this.codedErrors).forEach((code) => {
|
|
|
|
if (!codedErrorsAndWarnings[code]) {
|
|
|
|
codedErrorsAndWarnings[code] = [];
|
|
|
|
}
|
|
|
|
codedErrorsAndWarnings[code] = [...codedErrorsAndWarnings[code], ...this.codedErrors[code]];
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.keys(this.codedWarnings).forEach((code) => {
|
|
|
|
if (!codedErrorsAndWarnings[code]) {
|
|
|
|
codedErrorsAndWarnings[code] = [];
|
|
|
|
}
|
|
|
|
codedErrorsAndWarnings[code] = [...codedErrorsAndWarnings[code], ...this.codedWarnings[code]];
|
|
|
|
});
|
|
|
|
|
|
|
|
return codedErrorsAndWarnings;
|
|
|
|
}),
|
|
|
|
|
|
|
|
hasPageBuilderFeature(feature) {
|
|
|
|
const failures = this.codedErrorsAndWarnings;
|
2023-07-31 22:22:19 +03:00
|
|
|
|
2023-07-21 19:03:38 +03:00
|
|
|
if (!failures['GS110-NO-MISSING-PAGE-BUILDER-USAGE']) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !failures['GS110-NO-MISSING-PAGE-BUILDER-USAGE'].some((failure) => {
|
2023-07-31 22:22:19 +03:00
|
|
|
return failure.failures.some(({message}) => message.includes(`@page.${feature}`));
|
2023-07-21 19:03:38 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-03-03 18:31:42 +03:00
|
|
|
activate() {
|
|
|
|
let adapter = this.store.adapterFor(this.constructor.modelName);
|
2017-03-14 16:54:58 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
});
|
2017-03-03 18:31:42 +03:00
|
|
|
}
|
2017-02-21 21:28:44 +03:00
|
|
|
});
|