github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/app/controllers/allocations/allocation/index.js (about) 1 import Controller from '@ember/controller'; 2 import { inject as service } from '@ember/service'; 3 import { computed, observer } from '@ember/object'; 4 import { computed as overridable } from 'ember-overridable-computed'; 5 import { alias } from '@ember/object/computed'; 6 import { task } from 'ember-concurrency'; 7 import Sortable from 'nomad-ui/mixins/sortable'; 8 import { lazyClick } from 'nomad-ui/helpers/lazy-click'; 9 import { watchRecord } from 'nomad-ui/utils/properties/watch'; 10 11 export default Controller.extend(Sortable, { 12 token: service(), 13 14 queryParams: { 15 sortProperty: 'sort', 16 sortDescending: 'desc', 17 }, 18 19 sortProperty: 'name', 20 sortDescending: false, 21 22 listToSort: alias('model.states'), 23 sortedStates: alias('listSorted'), 24 25 // Set in the route 26 preempter: null, 27 28 error: overridable(() => { 29 // { title, description } 30 return null; 31 }), 32 33 network: alias('model.allocatedResources.networks.firstObject'), 34 35 services: computed('model.taskGroup.services.@each.name', function() { 36 return this.get('model.taskGroup.services').sortBy('name'); 37 }), 38 39 onDismiss() { 40 this.set('error', null); 41 }, 42 43 watchNext: watchRecord('allocation'), 44 45 observeWatchNext: observer('model.nextAllocation.clientStatus', function() { 46 const nextAllocation = this.model.nextAllocation; 47 if (nextAllocation && nextAllocation.content) { 48 this.watchNext.perform(nextAllocation); 49 } else { 50 this.watchNext.cancelAll(); 51 } 52 }), 53 54 stopAllocation: task(function*() { 55 try { 56 yield this.model.stop(); 57 // Eagerly update the allocation clientStatus to avoid flickering 58 this.model.set('clientStatus', 'complete'); 59 } catch (err) { 60 this.set('error', { 61 title: 'Could Not Stop Allocation', 62 description: 'Your ACL token does not grant allocation lifecycle permissions.', 63 }); 64 } 65 }), 66 67 restartAllocation: task(function*() { 68 try { 69 yield this.model.restart(); 70 } catch (err) { 71 this.set('error', { 72 title: 'Could Not Restart Allocation', 73 description: 'Your ACL token does not grant allocation lifecycle permissions.', 74 }); 75 } 76 }), 77 78 actions: { 79 gotoTask(allocation, task) { 80 this.transitionToRoute('allocations.allocation.task', task); 81 }, 82 83 taskClick(allocation, task, event) { 84 lazyClick([() => this.send('gotoTask', allocation, task), event]); 85 }, 86 }, 87 });