f747cc79e4
This reverts commits 141ecd8d9170f56c8302b5c776532e6d287a40e3 d2d838c2de08aac716a9431d9720b5c12bb19ba1 8099db433641429816e8479c6d23116269f744c0 86262b3ceff607627a9c9e0e25eb81b9b5ee739c eb4104ec528982e0ee6ae9a05fb0460e53139f3f 0e0e23e238017815bdb6dcfbc056275b3deaacca 6d45658d77fb4c40760a63cced71b74757356e48 b52a8176e85b9c6f13ec012f7fce2ec3df1c8751
79 lines
2.2 KiB
JavaScript
79 lines
2.2 KiB
JavaScript
import Ember from 'ember';
|
|
import ApplicationSerializer from './application';
|
|
import queryString from 'npm:query-string';
|
|
|
|
const { get, assign } = Ember;
|
|
|
|
export default ApplicationSerializer.extend({
|
|
attrs: {
|
|
parameterized: 'ParameterizedJob',
|
|
},
|
|
|
|
normalize(typeHash, hash) {
|
|
hash.NamespaceID = hash.Namespace;
|
|
|
|
// 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']);
|
|
|
|
// Transform the map-based JobSummary object into an array-based
|
|
// JobSummary fragment list
|
|
hash.TaskGroupSummaries = Object.keys(get(hash, 'JobSummary.Summary') || {}).map(key => {
|
|
const allocStats = get(hash, `JobSummary.Summary.${key}`);
|
|
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) {
|
|
const namespace =
|
|
!hash.NamespaceID || hash.NamespaceID === 'default' ? undefined : hash.NamespaceID;
|
|
const { modelName } = modelClass;
|
|
|
|
const jobURL = this.store
|
|
.adapterFor(modelName)
|
|
.buildURL(modelName, hash.PlainId, hash, 'findRecord');
|
|
|
|
return assign(this._super(...arguments), {
|
|
allocations: {
|
|
links: {
|
|
related: buildURL(`${jobURL}/allocations`, { namespace: namespace }),
|
|
},
|
|
},
|
|
versions: {
|
|
links: {
|
|
related: buildURL(`${jobURL}/versions`, { namespace: namespace, diffs: true }),
|
|
},
|
|
},
|
|
deployments: {
|
|
links: {
|
|
related: buildURL(`${jobURL}/deployments`, { namespace: namespace }),
|
|
},
|
|
},
|
|
});
|
|
},
|
|
});
|
|
|
|
function buildURL(path, queryParams) {
|
|
const qpString = queryString.stringify(queryParams);
|
|
if (qpString) {
|
|
return `${path}?${qpString}`;
|
|
}
|
|
return path;
|
|
}
|