Ghost/ghost/admin/app/transforms/navigation-settings.js
Kevin Ansfield a85f5fae35 Switch to eslint-plugin-ghost extending plugin:ghost/ember
no issue
- fix lint errors in lib/gh-koenig
- fix ghost:base eslint errors
- update ember plugin refs, remove ember-suave plugin refs
- remove old jshint refs
- add `lint:js` script
- switch to `eslint-plugin-ghost` extending `plugin:ghost/ember`
2018-01-12 12:17:56 +00:00

37 lines
990 B
JavaScript

import NavigationItem from 'ghost-admin/models/navigation-item';
import Transform from 'ember-data/transform';
import {A as emberA, isArray as isEmberArray} from '@ember/array';
export default Transform.extend({
deserialize(serialized) {
let navItems, settingsArray;
try {
settingsArray = JSON.parse(serialized) || [];
} catch (e) {
settingsArray = [];
}
navItems = settingsArray.map(itemDetails => 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);
}
});