2020-03-25 12:51:26 +00:00
|
|
|
import ApplicationSerializer from './application';
|
2022-03-08 17:28:36 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-05-02 06:38:05 +00:00
|
|
|
// 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) =>
|
2020-09-05 02:44:21 +00:00
|
|
|
Object.keys(hash)
|
|
|
|
.sort()
|
2021-12-28 14:45:20 +00:00
|
|
|
.map((key) => {
|
2020-09-05 02:44:21 +00:00
|
|
|
const record = hash[key];
|
|
|
|
record[propKey] = key;
|
|
|
|
return record;
|
|
|
|
});
|
2020-05-02 06:38:05 +00:00
|
|
|
|
2022-03-08 17:28:36 +00:00
|
|
|
@classic
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class Plugin extends ApplicationSerializer {
|
2020-03-25 12:51:26 +00:00
|
|
|
normalize(typeHash, hash) {
|
2020-05-03 04:31:17 +00:00
|
|
|
hash.PlainId = hash.ID;
|
2020-03-25 12:51:26 +00:00
|
|
|
|
|
|
|
// TODO This shouldn't hardcode `csi/` as part of the ID,
|
|
|
|
// but it is necessary to make the correct find request and the
|
|
|
|
// payload does not contain the required information to derive
|
|
|
|
// this identifier.
|
|
|
|
hash.ID = `csi/${hash.ID}`;
|
|
|
|
|
2020-05-02 06:38:05 +00:00
|
|
|
const nodes = hash.Nodes || {};
|
|
|
|
const controllers = hash.Controllers || {};
|
|
|
|
|
|
|
|
hash.Nodes = unmap(nodes, 'NodeID');
|
|
|
|
hash.Controllers = unmap(controllers, 'NodeID');
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
return super.normalize(typeHash, hash);
|
|
|
|
}
|
|
|
|
}
|