github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/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 const taskGroups = hash.TaskGroups || {}; 13 hash.TaskGroupSummaries = Object.keys(taskGroups).map(key => { 14 const deploymentStats = taskGroups[key]; 15 return assign({ Name: key }, deploymentStats); 16 }); 17 18 hash.PlainJobId = hash.JobID; 19 hash.Namespace = 20 hash.Namespace || 21 get(hash, 'Job.Namespace') || 22 this.get('system.activeNamespace.id') || 23 'default'; 24 25 // Ember Data doesn't support multiple inverses. This means that since jobs have 26 // two relationships to a deployment (hasMany deployments, and belongsTo latestDeployment), 27 // the deployment must in turn have two relationships to the job, despite it being the 28 // same job. 29 hash.JobID = hash.JobForLatestID = JSON.stringify([hash.JobID, hash.Namespace]); 30 } 31 32 return this._super(typeHash, hash); 33 }, 34 35 extractRelationships(modelClass, hash) { 36 const namespace = this.store.adapterFor(modelClass.modelName).get('namespace'); 37 const id = this.extractId(modelClass, hash); 38 39 return assign( 40 { 41 allocations: { 42 links: { 43 related: `/${namespace}/deployment/allocations/${id}`, 44 }, 45 }, 46 }, 47 this._super(modelClass, hash) 48 ); 49 }, 50 });