open-nomad/ui/app/serializers/node.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

import { assign } from '@ember/polyfills';
import { inject as service } from '@ember/service';
2017-09-19 14:47:10 +00:00
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
config: service(),
2017-09-19 14:47:10 +00:00
attrs: {
isDraining: 'Drain',
2017-09-19 14:47:10 +00:00
httpAddr: 'HTTPAddr',
},
normalize(modelClass, hash) {
2020-02-15 00:44:28 +00:00
// Transform map-based objects into array-based fragment lists
const drivers = hash.Drivers || {};
hash.Drivers = Object.keys(drivers).map(key => {
return assign({}, drivers[key], { Name: key });
});
const hostVolumes = hash.HostVolumes || {};
hash.HostVolumes = Object.keys(hostVolumes).map(key => hostVolumes[key]);
2020-02-11 00:19:28 +00:00
return this._super(modelClass, hash);
},
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`,
},
},
};
},
});