From 2cb077748972018027e21436da4e55e567cabe5f Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 27 Jul 2018 17:40:09 -0700 Subject: [PATCH] Get the latest deployment for a job by using the appropriate API --- ui/app/models/deployment.js | 7 +++++-- ui/app/models/job.js | 7 +++++-- ui/app/routes/jobs/job/index.js | 13 ++++++++++--- ui/app/serializers/job.js | 13 +++++++++---- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/ui/app/models/deployment.js b/ui/app/models/deployment.js index 02dfb4c81..e745249d5 100644 --- a/ui/app/models/deployment.js +++ b/ui/app/models/deployment.js @@ -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'), diff --git a/ui/app/models/job.js b/ui/app/models/job.js index 621b869ca..01a0c9f16 100644 --- a/ui/app/models/job.js +++ b/ui/app/models/job.js @@ -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() { diff --git a/ui/app/routes/jobs/job/index.js b/ui/app/routes/jobs/job/index.js index 84daab9a2..58bf30beb 100644 --- a/ui/app/routes/jobs/job/index.js +++ b/ui/app/routes/jobs/job/index.js @@ -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' + ), }); diff --git a/ui/app/serializers/job.js b/ui/app/serializers/job.js index a723f7f3d..a43badba1 100644 --- a/ui/app/serializers/job.js +++ b/ui/app/serializers/job.js @@ -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 }), }, }, });