github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/app/components/allocation-row.js (about) 1 import Ember from 'ember'; 2 import { lazyClick } from '../helpers/lazy-click'; 3 4 const { Component, inject, run } = Ember; 5 6 export default Component.extend({ 7 store: inject.service(), 8 9 tagName: 'tr', 10 11 classNames: ['allocation-row', 'is-interactive'], 12 13 allocation: null, 14 15 // Used to determine whether the row should mention the node or the job 16 context: null, 17 18 onClick() {}, 19 20 click(event) { 21 lazyClick([this.get('onClick'), event]); 22 }, 23 24 didReceiveAttrs() { 25 // TODO: Use this code again once the temporary workaround below 26 // is resolved. 27 28 // If the job for this allocation is incomplete, reload it to get 29 // detailed information. 30 // const allocation = this.get('allocation'); 31 // if ( 32 // allocation && 33 // allocation.get('job') && 34 // !allocation.get('job.isPending') && 35 // !allocation.get('taskGroup') 36 // ) { 37 // const job = allocation.get('job.content'); 38 // job && job.reload(); 39 // } 40 41 // TEMPORARY: https://github.com/emberjs/data/issues/5209 42 // Ember Data doesn't like it when relationships aren't reflective, 43 // which means the allocation's job will be null if it hasn't been 44 // resolved through the allocation (allocation.get('job')) before 45 // being resolved through the store (store.findAll('job')). The 46 // workaround is to persist the jobID as a string on the allocation 47 // and manually re-link the two records here. 48 run.scheduleOnce('afterRender', this, qualifyJob); 49 }, 50 }); 51 52 function qualifyJob() { 53 const allocation = this.get('allocation'); 54 if (allocation.get('originalJobId')) { 55 const job = this.get('store').peekRecord('job', allocation.get('originalJobId')); 56 if (job) { 57 allocation.setProperties({ 58 job, 59 originalJobId: null, 60 }); 61 } else { 62 this.get('store') 63 .findRecord('job', allocation.get('originalJobId')) 64 .then(job => { 65 allocation.set('job', job); 66 }); 67 } 68 } 69 }