github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/app/adapters/job.js (about) 1 import Ember from 'ember'; 2 import ApplicationAdapter from './application'; 3 4 const { RSVP, inject, assign } = Ember; 5 6 export default ApplicationAdapter.extend({ 7 system: inject.service(), 8 9 shouldReloadAll: () => true, 10 11 buildQuery() { 12 const namespace = this.get('system.activeNamespace.id'); 13 14 if (namespace && namespace !== 'default') { 15 return { namespace }; 16 } 17 }, 18 19 findAll() { 20 const namespace = this.get('system.activeNamespace'); 21 return this._super(...arguments).then(data => { 22 data.forEach(job => { 23 job.Namespace = namespace ? namespace.get('id') : 'default'; 24 }); 25 return data; 26 }); 27 }, 28 29 findRecord(store, { modelName }, id, snapshot) { 30 // To make a findRecord response reflect the findMany response, the JobSummary 31 // from /summary needs to be stitched into the response. 32 33 // URL is the form of /job/:name?namespace=:namespace with arbitrary additional query params 34 const [name, namespace] = JSON.parse(id); 35 const namespaceQuery = namespace && namespace !== 'default' ? { namespace } : {}; 36 return RSVP.hash({ 37 job: this.ajax(this.buildURL(modelName, name, snapshot, 'findRecord'), 'GET', { 38 data: assign(this.buildQuery() || {}, namespaceQuery), 39 }), 40 summary: this.ajax( 41 `${this.buildURL(modelName, name, snapshot, 'findRecord')}/summary`, 42 'GET', 43 { 44 data: assign(this.buildQuery() || {}, namespaceQuery), 45 } 46 ), 47 }).then(({ job, summary }) => { 48 job.JobSummary = summary; 49 return job; 50 }); 51 }, 52 53 findAllocations(job) { 54 const url = `${this.buildURL('job', job.get('id'), job, 'findRecord')}/allocations`; 55 return this.ajax(url, 'GET', { data: this.buildQuery() }).then(allocs => { 56 return this.store.pushPayload('allocation', { 57 allocations: allocs, 58 }); 59 }); 60 }, 61 62 fetchRawDefinition(job) { 63 const [name, namespace] = JSON.parse(job.get('id')); 64 const namespaceQuery = namespace && namespace !== 'default' ? { namespace } : {}; 65 const url = this.buildURL('job', name, job, 'findRecord'); 66 return this.ajax(url, 'GET', { data: assign(this.buildQuery() || {}, namespaceQuery) }); 67 }, 68 });