github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/app/serializers/deployment.js (about) 1 import { get } from '@ember/object'; 2 import { assign } from '@ember/polyfills'; 3 import ApplicationSerializer from './application'; 4 5 export default ApplicationSerializer.extend({ 6 attrs: { 7 versionNumber: 'JobVersion', 8 }, 9 10 normalize(typeHash, hash) { 11 if (hash) { 12 hash.TaskGroupSummaries = Object.keys(get(hash, 'TaskGroups') || {}).map(key => { 13 const deploymentStats = get(hash, `TaskGroups.${key}`); 14 return assign({ Name: key }, deploymentStats); 15 }); 16 17 hash.PlainJobId = hash.JobID; 18 hash.Namespace = 19 hash.Namespace || 20 get(hash, 'Job.Namespace') || 21 this.get('system.activeNamespace.id') || 22 'default'; 23 24 // Ember Data doesn't support multiple inverses. This means that since jobs have 25 // two relationships to a deployment (hasMany deployments, and belongsTo latestDeployment), 26 // the deployment must in turn have two relationships to the job, despite it being the 27 // same job. 28 hash.JobID = hash.JobForLatestID = JSON.stringify([hash.JobID, hash.Namespace]); 29 } 30 31 return this._super(typeHash, hash); 32 }, 33 34 extractRelationships(modelClass, hash) { 35 const namespace = this.store.adapterFor(modelClass.modelName).get('namespace'); 36 const id = this.extractId(modelClass, hash); 37 38 return assign( 39 { 40 allocations: { 41 links: { 42 related: `/${namespace}/deployment/allocations/${id}`, 43 }, 44 }, 45 }, 46 this._super(modelClass, hash) 47 ); 48 }, 49 });