2016-05-24 15:06:59 +03:00
|
|
|
import NavigationItem from 'ghost-admin/models/navigation-item';
|
2020-01-16 20:01:12 +03:00
|
|
|
import Transform from '@ember-data/serializer/transform';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {A as emberA, isArray as isEmberArray} from '@ember/array';
|
2016-04-26 12:45:59 +03:00
|
|
|
|
2022-02-02 13:40:43 +03:00
|
|
|
export default class NavigationSettings extends Transform {
|
2019-12-04 07:14:45 +03:00
|
|
|
deserialize(serialized, options) {
|
2016-04-26 12:45:59 +03:00
|
|
|
let navItems, settingsArray;
|
|
|
|
|
|
|
|
try {
|
|
|
|
settingsArray = JSON.parse(serialized) || [];
|
|
|
|
} catch (e) {
|
|
|
|
settingsArray = [];
|
|
|
|
}
|
|
|
|
|
2019-12-04 07:14:45 +03:00
|
|
|
navItems = settingsArray.map((itemDetails) => {
|
|
|
|
itemDetails.isSecondary = options && options.isSecondary || false;
|
|
|
|
return NavigationItem.create(itemDetails);
|
|
|
|
});
|
2016-04-26 12:45:59 +03:00
|
|
|
|
|
|
|
return emberA(navItems);
|
2022-02-02 13:40:43 +03:00
|
|
|
}
|
2016-04-26 12:45:59 +03:00
|
|
|
|
|
|
|
serialize(deserialized) {
|
|
|
|
let settingsArray;
|
|
|
|
|
2016-06-30 13:21:47 +03:00
|
|
|
if (isEmberArray(deserialized)) {
|
2016-04-26 12:45:59 +03:00
|
|
|
settingsArray = deserialized.map((item) => {
|
2022-02-02 21:48:59 +03:00
|
|
|
let label = item.label.trim();
|
|
|
|
let url = item.url.trim();
|
2016-04-26 12:45:59 +03:00
|
|
|
|
|
|
|
return {label, url};
|
|
|
|
}).compact();
|
|
|
|
} else {
|
|
|
|
settingsArray = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return JSON.stringify(settingsArray);
|
|
|
|
}
|
2022-02-02 13:40:43 +03:00
|
|
|
}
|