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)
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
/* eslint-disable camelcase */
|
|
import SlackObject from 'ghost-admin/models/slack-integration';
|
|
import Transform from '@ember-data/serializer/transform';
|
|
import {isArray as isEmberArray} from '@ember/array';
|
|
import {isEmpty} from '@ember/utils';
|
|
|
|
export default Transform.extend({
|
|
deserialize(serialized) {
|
|
let settingsArray;
|
|
try {
|
|
settingsArray = JSON.parse(serialized) || [];
|
|
} catch (e) {
|
|
settingsArray = [];
|
|
}
|
|
|
|
if (isEmpty(settingsArray)) {
|
|
settingsArray.push({url: '', username: ''});
|
|
}
|
|
|
|
let slackObjs = settingsArray.map(itemDetails => SlackObject.create(itemDetails));
|
|
|
|
return slackObjs;
|
|
},
|
|
|
|
serialize(deserialized) {
|
|
let settingsArray;
|
|
if (isEmberArray(deserialized)) {
|
|
settingsArray = deserialized.map((item) => {
|
|
let url = (item.get('url') || '').trim();
|
|
let username = (item.get('username') || '').trim();
|
|
if (url) {
|
|
return {url, username};
|
|
}
|
|
}).compact();
|
|
} else {
|
|
settingsArray = [];
|
|
}
|
|
return JSON.stringify(settingsArray);
|
|
}
|
|
});
|