f747cc79e4
This reverts commits 141ecd8d9170f56c8302b5c776532e6d287a40e3 d2d838c2de08aac716a9431d9720b5c12bb19ba1 8099db433641429816e8479c6d23116269f744c0 86262b3ceff607627a9c9e0e25eb81b9b5ee739c eb4104ec528982e0ee6ae9a05fb0460e53139f3f 0e0e23e238017815bdb6dcfbc056275b3deaacca 6d45658d77fb4c40760a63cced71b74757356e48 b52a8176e85b9c6f13ec012f7fce2ec3df1c8751
78 lines
2.3 KiB
JavaScript
78 lines
2.3 KiB
JavaScript
import Ember from 'ember';
|
|
import Model from 'ember-data/model';
|
|
import attr from 'ember-data/attr';
|
|
import { belongsTo, hasMany } from 'ember-data/relationships';
|
|
import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
|
import sumAggregation from '../utils/properties/sum-aggregation';
|
|
|
|
const { computed } = Ember;
|
|
|
|
export default Model.extend({
|
|
region: attr('string'),
|
|
name: attr('string'),
|
|
plainId: attr('string'),
|
|
type: attr('string'),
|
|
priority: attr('number'),
|
|
allAtOnce: attr('boolean'),
|
|
|
|
status: attr('string'),
|
|
statusDescription: attr('string'),
|
|
createIndex: attr('number'),
|
|
modifyIndex: attr('number'),
|
|
|
|
periodic: attr('boolean'),
|
|
parameterized: attr('boolean'),
|
|
|
|
datacenters: attr(),
|
|
taskGroups: fragmentArray('task-group', { defaultValue: () => [] }),
|
|
taskGroupSummaries: fragmentArray('task-group-summary'),
|
|
|
|
// Aggregate allocation counts across all summaries
|
|
queuedAllocs: sumAggregation('taskGroupSummaries', 'queuedAllocs'),
|
|
startingAllocs: sumAggregation('taskGroupSummaries', 'startingAllocs'),
|
|
runningAllocs: sumAggregation('taskGroupSummaries', 'runningAllocs'),
|
|
completeAllocs: sumAggregation('taskGroupSummaries', 'completeAllocs'),
|
|
failedAllocs: sumAggregation('taskGroupSummaries', 'failedAllocs'),
|
|
lostAllocs: sumAggregation('taskGroupSummaries', 'lostAllocs'),
|
|
|
|
allocsList: computed.collect(
|
|
'queuedAllocs',
|
|
'startingAllocs',
|
|
'runningAllocs',
|
|
'completeAllocs',
|
|
'failedAllocs',
|
|
'lostAllocs'
|
|
),
|
|
|
|
totalAllocs: computed.sum('allocsList'),
|
|
|
|
pendingChildren: attr('number'),
|
|
runningChildren: attr('number'),
|
|
deadChildren: attr('number'),
|
|
|
|
versions: hasMany('job-versions'),
|
|
allocations: hasMany('allocations'),
|
|
deployments: hasMany('deployments'),
|
|
namespace: belongsTo('namespace'),
|
|
|
|
supportsDeployments: computed.equal('type', 'service'),
|
|
|
|
runningDeployment: computed('deployments.@each.status', function() {
|
|
return this.get('deployments').findBy('status', 'running');
|
|
}),
|
|
|
|
fetchRawDefinition() {
|
|
return this.store.adapterFor('job').fetchRawDefinition(this);
|
|
},
|
|
|
|
statusClass: computed('status', function() {
|
|
const classMap = {
|
|
pending: 'is-pending',
|
|
running: 'is-primary',
|
|
dead: 'is-light',
|
|
};
|
|
|
|
return classMap[this.get('status')] || 'is-dark';
|
|
}),
|
|
});
|