add legacy support
This commit is contained in:
parent
6275fb54ec
commit
1fd7f27f03
3 changed files with 55 additions and 0 deletions
|
@ -46,6 +46,11 @@ export default DS.RESTSerializer.extend({
|
|||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
// run legacy support transformation specified in model serializer
|
||||
if (typeof this.legacySupport === 'function') {
|
||||
resourceHash = this.legacySupport(resourceHash);
|
||||
}
|
||||
|
||||
return this._super(modelClass, resourceHash, prop);
|
||||
},
|
||||
|
|
|
@ -1,10 +1,27 @@
|
|||
import DS from "ember-data";
|
||||
import ApplicationAdapter from './application';
|
||||
import Ember from "ember";
|
||||
|
||||
export default ApplicationAdapter.extend(DS.EmbeddedRecordsMixin, {
|
||||
attrs: {
|
||||
users: {
|
||||
deserialize: 'records'
|
||||
}
|
||||
},
|
||||
|
||||
legacySupport(resourceHash) {
|
||||
// croodle <= 0.3.0
|
||||
// property "type" of answers was named "id"
|
||||
if (
|
||||
resourceHash.answers.length > 0 &&
|
||||
!Ember.isEmpty(resourceHash.answers[0].id)
|
||||
) {
|
||||
resourceHash.answers.forEach((answer, index) => {
|
||||
resourceHash.answers[index].type = answer.id;
|
||||
delete resourceHash.answers[index].id;
|
||||
});
|
||||
}
|
||||
|
||||
return resourceHash;
|
||||
}
|
||||
});
|
||||
|
|
33
app/serializers/user.js
Normal file
33
app/serializers/user.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
import ApplicationAdapter from './application';
|
||||
import Ember from 'ember';
|
||||
|
||||
export default ApplicationAdapter.extend({
|
||||
legacySupport: function(resourceHash) {
|
||||
/*
|
||||
* Croodle <= 0.3.0:
|
||||
* * for answer type "freetext":
|
||||
* selections where a string containing label
|
||||
* * all other answer types ("YesNo", "YesNoMaybe"):
|
||||
* selections where stored as child object of "value" property
|
||||
* and selection property "type" where named "id"
|
||||
*/
|
||||
if (!Ember.isEmpty(resourceHash.selections[0].value)) {
|
||||
resourceHash.selections.forEach(function(selection, index) {
|
||||
if (typeof selection.value === 'string') {
|
||||
resourceHash.selections[index] = {
|
||||
label: selection.value
|
||||
};
|
||||
} else {
|
||||
resourceHash.selections[index] = {
|
||||
icon: selection.value.icon,
|
||||
label: selection.value.label,
|
||||
labelTranslation: selection.value.labelTranslation,
|
||||
type: selection.value.id
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return resourceHash;
|
||||
}
|
||||
});
|
Loading…
Reference in a new issue