2018-05-08 16:39:27 +00:00
|
|
|
import { assign } from '@ember/polyfills';
|
2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2017-09-19 14:47:10 +00:00
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
export default class NodeSerializer extends ApplicationSerializer {
|
|
|
|
@service config;
|
2017-10-17 01:39:32 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
attrs = {
|
2018-05-29 17:05:16 +00:00
|
|
|
isDraining: 'Drain',
|
2017-09-19 14:47:10 +00:00
|
|
|
httpAddr: 'HTTPAddr',
|
2020-06-11 21:23:00 +00:00
|
|
|
};
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-10-17 01:39:32 +00:00
|
|
|
normalize(modelClass, hash) {
|
2020-02-15 00:44:28 +00:00
|
|
|
// Transform map-based objects into array-based fragment lists
|
2018-12-13 01:23:09 +00:00
|
|
|
const drivers = hash.Drivers || {};
|
|
|
|
hash.Drivers = Object.keys(drivers).map(key => {
|
|
|
|
return assign({}, drivers[key], { Name: key });
|
2018-05-08 16:39:27 +00:00
|
|
|
});
|
|
|
|
|
2020-03-26 16:54:52 +00:00
|
|
|
const hostVolumes = hash.HostVolumes || {};
|
|
|
|
hash.HostVolumes = Object.keys(hostVolumes).map(key => hostVolumes[key]);
|
2020-02-11 00:19:28 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
return super.normalize(modelClass, hash);
|
|
|
|
}
|
2017-10-17 01:39:32 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
extractRelationships(modelClass, hash) {
|
|
|
|
const { modelName } = modelClass;
|
|
|
|
const nodeURL = this.store
|
|
|
|
.adapterFor(modelName)
|
|
|
|
.buildURL(modelName, this.extractId(modelClass, hash), hash, 'findRecord');
|
|
|
|
|
|
|
|
return {
|
|
|
|
allocations: {
|
|
|
|
links: {
|
|
|
|
related: `${nodeURL}/allocations`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
|
|
|
}
|