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';
|
2020-06-11 21:23:00 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@classic
|
|
|
|
export default class DeploymentSerializer extends ApplicationSerializer {
|
|
|
|
attrs = {
|
2017-09-19 14:47:10 +00:00
|
|
|
versionNumber: 'JobVersion',
|
2020-06-11 21:23:00 +00:00
|
|
|
};
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
normalize(typeHash, hash) {
|
2018-07-30 22:20:58 +00:00
|
|
|
if (hash) {
|
2018-12-13 00:49:52 +00:00
|
|
|
const taskGroups = hash.TaskGroups || {};
|
|
|
|
hash.TaskGroupSummaries = Object.keys(taskGroups).map(key => {
|
|
|
|
const deploymentStats = taskGroups[key];
|
2018-07-30 22:20:58 +00:00
|
|
|
return assign({ Name: key }, deploymentStats);
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-07-30 22:20:58 +00:00
|
|
|
hash.PlainJobId = hash.JobID;
|
|
|
|
hash.Namespace =
|
|
|
|
hash.Namespace ||
|
|
|
|
get(hash, 'Job.Namespace') ||
|
|
|
|
this.get('system.activeNamespace.id') ||
|
|
|
|
'default';
|
2018-07-28 02:28:05 +00:00
|
|
|
|
2018-07-30 22:20:58 +00:00
|
|
|
// Ember Data doesn't support multiple inverses. This means that since jobs have
|
|
|
|
// two relationships to a deployment (hasMany deployments, and belongsTo latestDeployment),
|
|
|
|
// the deployment must in turn have two relationships to the job, despite it being the
|
|
|
|
// same job.
|
|
|
|
hash.JobID = hash.JobForLatestID = JSON.stringify([hash.JobID, hash.Namespace]);
|
|
|
|
}
|
2017-10-23 17:22:58 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
return super.normalize(typeHash, hash);
|
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
extractRelationships(modelClass, hash) {
|
|
|
|
const namespace = this.store.adapterFor(modelClass.modelName).get('namespace');
|
|
|
|
const id = this.extractId(modelClass, hash);
|
|
|
|
|
|
|
|
return assign(
|
|
|
|
{
|
|
|
|
allocations: {
|
|
|
|
links: {
|
|
|
|
related: `/${namespace}/deployment/allocations/${id}`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-11 21:23:00 +00:00
|
|
|
super.extractRelationships(modelClass, hash)
|
2017-09-19 14:47:10 +00:00
|
|
|
);
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
|
|
|
}
|