Get the latest deployment for a job by using the appropriate API

This commit is contained in:
Michael Lange
2018-07-27 17:40:09 -07:00
parent b10a2ab7d8
commit 2cb0777489
4 changed files with 29 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
import { alias } from '@ember/object/computed';
import { alias, equal } from '@ember/object/computed';
import { computed } from '@ember/object';
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
@@ -10,7 +10,7 @@ import sumAggregation from '../utils/properties/sum-aggregation';
export default Model.extend({
shortId: shortUUIDProperty('id'),
job: belongsTo('job'),
job: belongsTo('job', { inverse: 'deployments' }),
versionNumber: attr('number'),
// If any task group is not promoted yet requires promotion and the deployment
@@ -26,6 +26,9 @@ export default Model.extend({
status: attr('string'),
statusDescription: attr('string'),
isRunning: equal('status', 'running'),
taskGroupSummaries: fragmentArray('task-group-deployment-summary'),
allocations: hasMany('allocations'),

View File

@@ -172,8 +172,11 @@ export default Model.extend({
supportsDeployments: equal('type', 'service'),
runningDeployment: computed('deployments.@each.status', function() {
return this.get('deployments').findBy('status', 'running');
latestDeployment: belongsTo('deployment', { inverse: null }),
runningDeployment: computed('latestDeployment.isRunning', function() {
const latest = this.get('latestDeployment');
if (latest.get('isRunning')) return latest;
}),
fetchRawDefinition() {

View File

@@ -12,7 +12,8 @@ export default Route.extend(WithWatchers, {
model: this.get('watch').perform(model),
summary: this.get('watchSummary').perform(model.get('summary')),
evaluations: this.get('watchEvaluations').perform(model),
deployments: model.get('supportsDeployments') && this.get('watchDeployments').perform(model),
latestDeployment:
model.get('supportsDeployments') && this.get('watchLatestDeployment').perform(model),
list: model.get('hasChildren') && this.get('watchAll').perform(),
});
},
@@ -21,7 +22,13 @@ export default Route.extend(WithWatchers, {
watchAll: watchAll('job'),
watchSummary: watchRecord('job-summary'),
watchEvaluations: watchRelationship('evaluations'),
watchDeployments: watchRelationship('deployments'),
watchLatestDeployment: watchRelationship('latestDeployment'),
watchers: collect('watch', 'watchAll', 'watchSummary', 'watchEvaluations', 'watchDeployments'),
watchers: collect(
'watch',
'watchAll',
'watchSummary',
'watchEvaluations',
'watchLatestDeployment'
),
});

View File

@@ -61,22 +61,27 @@ export default ApplicationSerializer.extend({
return assign(this._super(...arguments), {
allocations: {
links: {
related: buildURL(`${jobURL}/allocations`, { namespace: namespace }),
related: buildURL(`${jobURL}/allocations`, { namespace }),
},
},
versions: {
links: {
related: buildURL(`${jobURL}/versions`, { namespace: namespace, diffs: true }),
related: buildURL(`${jobURL}/versions`, { namespace, diffs: true }),
},
},
deployments: {
links: {
related: buildURL(`${jobURL}/deployments`, { namespace: namespace }),
related: buildURL(`${jobURL}/deployments`, { namespace }),
},
},
latestDeployment: {
links: {
related: buildURL(`${jobURL}/deployment`, { namespace }),
},
},
evaluations: {
links: {
related: buildURL(`${jobURL}/evaluations`, { namespace: namespace }),
related: buildURL(`${jobURL}/evaluations`, { namespace }),
},
},
});