Update plugin model and serializer to match final API
This commit is contained in:
parent
343d4e0b81
commit
1b47885bdb
|
@ -1,6 +1,6 @@
|
||||||
import Model from 'ember-data/model';
|
import Model from 'ember-data/model';
|
||||||
import attr from 'ember-data/attr';
|
import attr from 'ember-data/attr';
|
||||||
// import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
||||||
|
|
||||||
export default Model.extend({
|
export default Model.extend({
|
||||||
topologies: attr(),
|
topologies: attr(),
|
||||||
|
@ -8,6 +8,6 @@ export default Model.extend({
|
||||||
version: attr('string'),
|
version: attr('string'),
|
||||||
controllerRequired: attr('boolean'),
|
controllerRequired: attr('boolean'),
|
||||||
|
|
||||||
// controllers: fragmentArray('storage-controller', { defaultValue: () => [] }),
|
controllers: fragmentArray('storage-controller', { defaultValue: () => [] }),
|
||||||
// nodes: fragmentArray('storage-node', { defaultValue: () => [] }),
|
nodes: fragmentArray('storage-node', { defaultValue: () => [] }),
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,17 @@
|
||||||
import ApplicationSerializer from './application';
|
import ApplicationSerializer from './application';
|
||||||
|
|
||||||
|
// Convert a map[string]interface{} into an array of objects
|
||||||
|
// where the key becomes a property at propKey.
|
||||||
|
// This is destructive. The original object is mutated to avoid
|
||||||
|
// excessive copies of the originals which would otherwise just
|
||||||
|
// be garbage collected.
|
||||||
|
const unmap = (hash, propKey) =>
|
||||||
|
Object.keys(hash).map(key => {
|
||||||
|
const record = hash[key];
|
||||||
|
record[propKey] = key;
|
||||||
|
return record;
|
||||||
|
});
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default ApplicationSerializer.extend({
|
||||||
normalize(typeHash, hash) {
|
normalize(typeHash, hash) {
|
||||||
hash.PlainID = hash.ID;
|
hash.PlainID = hash.ID;
|
||||||
|
@ -10,8 +22,11 @@ export default ApplicationSerializer.extend({
|
||||||
// this identifier.
|
// this identifier.
|
||||||
hash.ID = `csi/${hash.ID}`;
|
hash.ID = `csi/${hash.ID}`;
|
||||||
|
|
||||||
hash.Nodes = hash.Nodes || [];
|
const nodes = hash.Nodes || {};
|
||||||
hash.Controllers = hash.Controllers || [];
|
const controllers = hash.Controllers || {};
|
||||||
|
|
||||||
|
hash.Nodes = unmap(nodes, 'NodeID');
|
||||||
|
hash.Controllers = unmap(controllers, 'NodeID');
|
||||||
|
|
||||||
return this._super(typeHash, hash);
|
return this._super(typeHash, hash);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue