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 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({
|
||||
topologies: attr(),
|
||||
|
@ -8,6 +8,6 @@ export default Model.extend({
|
|||
version: attr('string'),
|
||||
controllerRequired: attr('boolean'),
|
||||
|
||||
// controllers: fragmentArray('storage-controller', { defaultValue: () => [] }),
|
||||
// nodes: fragmentArray('storage-node', { defaultValue: () => [] }),
|
||||
controllers: fragmentArray('storage-controller', { defaultValue: () => [] }),
|
||||
nodes: fragmentArray('storage-node', { defaultValue: () => [] }),
|
||||
});
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
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({
|
||||
normalize(typeHash, hash) {
|
||||
hash.PlainID = hash.ID;
|
||||
|
@ -10,8 +22,11 @@ export default ApplicationSerializer.extend({
|
|||
// this identifier.
|
||||
hash.ID = `csi/${hash.ID}`;
|
||||
|
||||
hash.Nodes = hash.Nodes || [];
|
||||
hash.Controllers = hash.Controllers || [];
|
||||
const nodes = hash.Nodes || {};
|
||||
const controllers = hash.Controllers || {};
|
||||
|
||||
hash.Nodes = unmap(nodes, 'NodeID');
|
||||
hash.Controllers = unmap(controllers, 'NodeID');
|
||||
|
||||
return this._super(typeHash, hash);
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue