github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/app/models/deployment.js (about) 1 import Ember from 'ember'; 2 import Model from 'ember-data/model'; 3 import attr from 'ember-data/attr'; 4 import { belongsTo, hasMany } from 'ember-data/relationships'; 5 import { fragmentArray } from 'ember-data-model-fragments/attributes'; 6 import shortUUIDProperty from '../utils/properties/short-uuid'; 7 import sumAggregation from '../utils/properties/sum-aggregation'; 8 9 const { computed } = Ember; 10 11 export default Model.extend({ 12 shortId: shortUUIDProperty('id'), 13 14 job: belongsTo('job'), 15 versionNumber: attr('number'), 16 17 // If any task group is not promoted yet requires promotion and the deployment 18 // is still running, the deployment needs promotion. 19 requiresPromotion: computed('taskGroupSummaries.@each.promoted', function() { 20 return ( 21 this.get('status') === 'running' && 22 this.get('taskGroupSummaries') 23 .toArray() 24 .some(summary => summary.get('requiresPromotion') && !summary.get('promoted')) 25 ); 26 }), 27 28 status: attr('string'), 29 statusDescription: attr('string'), 30 taskGroupSummaries: fragmentArray('task-group-deployment-summary'), 31 allocations: hasMany('allocations'), 32 33 version: computed('versionNumber', 'job.versions.content.@each.number', function() { 34 return (this.get('job.versions') || []).findBy('number', this.get('versionNumber')); 35 }), 36 37 placedCanaries: sumAggregation('taskGroupSummaries', 'placedCanaries'), 38 desiredCanaries: sumAggregation('taskGroupSummaries', 'desiredCanaries'), 39 desiredTotal: sumAggregation('taskGroupSummaries', 'desiredTotal'), 40 placedAllocs: sumAggregation('taskGroupSummaries', 'placedAllocs'), 41 healthyAllocs: sumAggregation('taskGroupSummaries', 'healthyAllocs'), 42 unhealthyAllocs: sumAggregation('taskGroupSummaries', 'unhealthyAllocs'), 43 44 statusClass: computed('status', function() { 45 const classMap = { 46 running: 'is-running', 47 successful: 'is-primary', 48 paused: 'is-light', 49 failed: 'is-error', 50 cancelled: 'is-cancelled', 51 }; 52 53 return classMap[this.get('status')] || 'is-dark'; 54 }), 55 });