mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 04:43:12 +03:00
983110d931
no issue - add eslint-plugin-ember, configure no-old-shims rule - run `eslint --fix` on `app`, `lib`, `mirage`, and `tests` to move imports to the new module imports - further cleanup of Ember globals usage - remove event-dispatcher initializer now that `canDispatchToEventManager` is deprecated
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
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) => {
|
|
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);
|
|
}
|
|
});
|