2017-12-15 21:39:18 +00:00
|
|
|
import { get } from '@ember/object';
|
|
|
|
import { assign } from '@ember/polyfills';
|
2017-09-19 14:47:10 +00:00
|
|
|
import ApplicationSerializer from './application';
|
2017-10-18 17:39:36 +00:00
|
|
|
import queryString from 'npm:query-string';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export default ApplicationSerializer.extend({
|
|
|
|
attrs: {
|
|
|
|
parameterized: 'ParameterizedJob',
|
|
|
|
},
|
|
|
|
|
|
|
|
normalize(typeHash, hash) {
|
2017-10-18 17:39:36 +00:00
|
|
|
hash.NamespaceID = hash.Namespace;
|
|
|
|
|
2017-10-23 17:22:58 +00:00
|
|
|
// ID is a composite of both the job ID and the namespace the job is in
|
|
|
|
hash.PlainId = hash.ID;
|
|
|
|
hash.ID = JSON.stringify([hash.ID, hash.NamespaceID || 'default']);
|
|
|
|
|
2018-01-23 21:23:16 +00:00
|
|
|
// ParentID comes in as "" instead of null
|
|
|
|
if (!hash.ParentID) {
|
|
|
|
hash.ParentID = null;
|
|
|
|
} else {
|
|
|
|
hash.ParentID = JSON.stringify([hash.ParentID, hash.NamespaceID || 'default']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Periodic is a boolean on list and an object on single
|
|
|
|
if (hash.Periodic instanceof Object) {
|
|
|
|
hash.PeriodicDetails = hash.Periodic;
|
|
|
|
hash.Periodic = true;
|
|
|
|
}
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
// Transform the map-based JobSummary object into an array-based
|
|
|
|
// JobSummary fragment list
|
2017-10-23 17:22:58 +00:00
|
|
|
hash.TaskGroupSummaries = Object.keys(get(hash, 'JobSummary.Summary') || {}).map(key => {
|
2017-11-29 01:23:30 +00:00
|
|
|
const allocStats = get(hash, `JobSummary.Summary.${key}`) || {};
|
2017-09-19 14:47:10 +00:00
|
|
|
const summary = { Name: key };
|
|
|
|
|
|
|
|
Object.keys(allocStats).forEach(
|
|
|
|
allocKey => (summary[`${allocKey}Allocs`] = allocStats[allocKey])
|
|
|
|
);
|
|
|
|
|
|
|
|
return summary;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Lift the children stats out of the JobSummary object
|
|
|
|
const childrenStats = get(hash, 'JobSummary.Children');
|
|
|
|
if (childrenStats) {
|
|
|
|
Object.keys(childrenStats).forEach(
|
|
|
|
childrenKey => (hash[`${childrenKey}Children`] = childrenStats[childrenKey])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._super(typeHash, hash);
|
|
|
|
},
|
|
|
|
|
|
|
|
extractRelationships(modelClass, hash) {
|
2017-10-18 17:39:36 +00:00
|
|
|
const namespace =
|
|
|
|
!hash.NamespaceID || hash.NamespaceID === 'default' ? undefined : hash.NamespaceID;
|
2017-09-19 14:47:10 +00:00
|
|
|
const { modelName } = modelClass;
|
2017-10-23 17:22:58 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
const jobURL = this.store
|
|
|
|
.adapterFor(modelName)
|
2017-10-23 17:22:58 +00:00
|
|
|
.buildURL(modelName, hash.PlainId, hash, 'findRecord');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-10-10 16:36:15 +00:00
|
|
|
return assign(this._super(...arguments), {
|
2017-09-19 14:47:10 +00:00
|
|
|
allocations: {
|
|
|
|
links: {
|
2017-10-18 17:39:36 +00:00
|
|
|
related: buildURL(`${jobURL}/allocations`, { namespace: namespace }),
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
versions: {
|
|
|
|
links: {
|
2017-10-18 17:39:36 +00:00
|
|
|
related: buildURL(`${jobURL}/versions`, { namespace: namespace, diffs: true }),
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
deployments: {
|
|
|
|
links: {
|
2017-10-18 17:39:36 +00:00
|
|
|
related: buildURL(`${jobURL}/deployments`, { namespace: namespace }),
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
},
|
2017-11-29 01:23:30 +00:00
|
|
|
evaluations: {
|
|
|
|
links: {
|
|
|
|
related: buildURL(`${jobURL}/evaluations`, { namespace: namespace }),
|
|
|
|
},
|
|
|
|
},
|
2017-10-10 16:36:15 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
});
|
2017-10-18 17:39:36 +00:00
|
|
|
|
|
|
|
function buildURL(path, queryParams) {
|
|
|
|
const qpString = queryString.stringify(queryParams);
|
|
|
|
if (qpString) {
|
|
|
|
return `${path}?${qpString}`;
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|