mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 04:43:12 +03:00
ba4c53134f
no issue - update imports for `@ember-data` package (https://github.com/emberjs/rfcs/blob/master/text/0395-ember-data-packages.md) - use `computed.reads` where applicable (https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/require-computed-macros.md) - fix usage of `scheduleOnce` so that functions are only scheduled once (https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-incorrect-calls-with-inline-anonymous-functions.md)
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import NavigationItem from 'ghost-admin/models/navigation-item';
|
|
import Transform from '@ember-data/serializer/transform';
|
|
import {A as emberA, isArray as isEmberArray} from '@ember/array';
|
|
|
|
export default Transform.extend({
|
|
deserialize(serialized, options) {
|
|
let navItems, settingsArray;
|
|
|
|
try {
|
|
settingsArray = JSON.parse(serialized) || [];
|
|
} catch (e) {
|
|
settingsArray = [];
|
|
}
|
|
|
|
navItems = settingsArray.map((itemDetails) => {
|
|
itemDetails.isSecondary = options && options.isSecondary || false;
|
|
return NavigationItem.create(itemDetails);
|
|
});
|
|
|
|
return emberA(navItems);
|
|
},
|
|
|
|
serialize(deserialized) {
|
|
let settingsArray;
|
|
|
|
if (isEmberArray(deserialized)) {
|
|
settingsArray = deserialized.map((item) => {
|
|
let label = item.get('label').trim();
|
|
let url = item.get('url').trim();
|
|
|
|
return {label, url};
|
|
}).compact();
|
|
} else {
|
|
settingsArray = [];
|
|
}
|
|
|
|
return JSON.stringify(settingsArray);
|
|
}
|
|
});
|