2016-11-14 16:16:51 +03:00
|
|
|
/* eslint-disable camelcase */
|
2016-05-24 15:06:59 +03:00
|
|
|
import SlackObject from 'ghost-admin/models/slack-integration';
|
2017-05-29 21:50:03 +03:00
|
|
|
import Transform from 'ember-data/transform';
|
2018-07-02 16:57:33 +03:00
|
|
|
import {isArray as isEmberArray} from '@ember/array';
|
|
|
|
import {isEmpty} from '@ember/utils';
|
2016-03-29 11:40:44 +03:00
|
|
|
|
|
|
|
export default Transform.extend({
|
|
|
|
deserialize(serialized) {
|
2018-07-02 16:57:33 +03:00
|
|
|
let settingsArray;
|
2016-03-29 11:40:44 +03:00
|
|
|
try {
|
|
|
|
settingsArray = JSON.parse(serialized) || [];
|
|
|
|
} catch (e) {
|
|
|
|
settingsArray = [];
|
|
|
|
}
|
|
|
|
|
2018-07-02 16:57:33 +03:00
|
|
|
if (isEmpty(settingsArray)) {
|
|
|
|
settingsArray.push({url: ''});
|
|
|
|
}
|
|
|
|
|
|
|
|
let slackObjs = settingsArray.map(itemDetails => SlackObject.create(itemDetails));
|
|
|
|
|
|
|
|
return slackObjs;
|
2016-03-29 11:40:44 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
serialize(deserialized) {
|
|
|
|
let settingsArray;
|
2016-06-30 13:21:47 +03:00
|
|
|
if (isEmberArray(deserialized)) {
|
2016-03-29 11:40:44 +03:00
|
|
|
settingsArray = deserialized.map((item) => {
|
|
|
|
let url = (item.get('url') || '').trim();
|
2018-07-02 16:57:33 +03:00
|
|
|
if (url) {
|
|
|
|
return {url};
|
|
|
|
}
|
2016-03-29 11:40:44 +03:00
|
|
|
}).compact();
|
|
|
|
} else {
|
|
|
|
settingsArray = [];
|
|
|
|
}
|
|
|
|
return JSON.stringify(settingsArray);
|
|
|
|
}
|
|
|
|
});
|