mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
cf36851265
replaces #41, #60 - update ember-suave and grunt-jscs to 3.0 - standardize Ember global de-structuring rules across app & tests
40 lines
1023 B
JavaScript
40 lines
1023 B
JavaScript
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
|
|
import Ember from 'ember';
|
|
import Transform from 'ember-data/transform';
|
|
import SlackObject from 'ghost-admin/models/slack-integration';
|
|
|
|
const {
|
|
isArray,
|
|
A: emberA
|
|
} = Ember;
|
|
|
|
export default Transform.extend({
|
|
deserialize(serialized) {
|
|
let slackObj, settingsArray;
|
|
try {
|
|
settingsArray = JSON.parse(serialized) || [];
|
|
} catch (e) {
|
|
settingsArray = [];
|
|
}
|
|
|
|
slackObj = settingsArray.map((itemDetails) => {
|
|
return SlackObject.create(itemDetails);
|
|
});
|
|
return emberA(slackObj);
|
|
},
|
|
|
|
serialize(deserialized) {
|
|
let settingsArray;
|
|
if (isArray(deserialized)) {
|
|
settingsArray = deserialized.map((item) => {
|
|
let url = (item.get('url') || '').trim();
|
|
|
|
return {url};
|
|
}).compact();
|
|
} else {
|
|
settingsArray = [];
|
|
}
|
|
return JSON.stringify(settingsArray);
|
|
}
|
|
});
|