From f6975e5b02d014a73109228a2154864d42865ae6 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Mon, 26 Nov 2012 05:41:33 +0100 Subject: [PATCH] add cancel menu items --- assets/scripts/app/models/build.coffee | 14 ++++++-- assets/scripts/app/models/job.coffee | 17 +++++++--- .../app/templates/repos/show/tools.hbs | 10 ++++++ assets/scripts/app/views/repo/show.coffee | 32 ++++++++++++++++--- 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/assets/scripts/app/models/build.coffee b/assets/scripts/app/models/build.coffee index 438a1771..fd37e623 100644 --- a/assets/scripts/app/models/build.coffee +++ b/assets/scripts/app/models/build.coffee @@ -14,9 +14,9 @@ require 'travis/model' startedAt: DS.attr('string', key: 'started_at') finishedAt: DS.attr('string', key: 'finished_at') - repo: DS.belongsTo('Travis.Repo', key: 'repository_id') - commit: DS.belongsTo('Travis.Commit') - jobs: DS.hasMany('Travis.Job', key: 'job_ids') + repo: DS.belongsTo('Travis.Repo', key: 'repository_id') + commit: DS.belongsTo('Travis.Commit') + jobs: DS.hasMany('Travis.Job', key: 'job_ids') config: (-> Travis.Helpers.compact(@get('data.config')) @@ -49,6 +49,14 @@ require 'travis/model' $.map(headers.concat(keys), (key) -> return $.camelize(key)) ).property('config') + canCancel: (-> + @get('state') == 'created' # TODO + ).property('state') + + cancel: (-> + Travis.ajax.post "/builds/#{@get('id')}", _method: 'delete' + ) + requeue: -> Travis.ajax.post '/requests', build_id: @get('id') diff --git a/assets/scripts/app/models/job.coffee b/assets/scripts/app/models/job.coffee index 613e4d84..349e3ff2 100644 --- a/assets/scripts/app/models/job.coffee +++ b/assets/scripts/app/models/job.coffee @@ -15,11 +15,10 @@ require 'travis/model' allowFailure: DS.attr('boolean', key: 'allow_failure') repositorySlug: DS.attr('string') - - repo: DS.belongsTo('Travis.Repo', key: 'repository_id') - build: DS.belongsTo('Travis.Build', key: 'build_id') - commit: DS.belongsTo('Travis.Commit', key: 'commit_id') - log: DS.belongsTo('Travis.Artifact', key: 'log_id') + repo: DS.belongsTo('Travis.Repo', key: 'repository_id') + build: DS.belongsTo('Travis.Build', key: 'build_id') + commit: DS.belongsTo('Travis.Commit', key: 'commit_id') + log: DS.belongsTo('Travis.Artifact', key: 'log_id') repoSlug: (-> @get('repositorySlug') @@ -59,6 +58,14 @@ require 'travis/model' [] ).property('config') + canCancel: (-> + @get('state') == 'created' || @get('state') == 'queued' # TODO + ).property('state') + + cancel: (-> + Travis.ajax.post "/jobs/#{@get('id')}", _method: 'delete' + ) + requeue: -> Travis.ajax.post '/requests', job_id: @get('id') diff --git a/assets/scripts/app/templates/repos/show/tools.hbs b/assets/scripts/app/templates/repos/show/tools.hbs index cd8ea082..e2441476 100644 --- a/assets/scripts/app/templates/repos/show/tools.hbs +++ b/assets/scripts/app/templates/repos/show/tools.hbs @@ -4,6 +4,16 @@
  • Status Images
  • + {{#if view.canCancelBuild}} +
  • + Cancel Build +
  • + {{/if}} + {{#if view.canCancelJob}} +
  • + Cancel Job +
  • + {{/if}} {{#if view.canRequeueBuild}}
  • Rebuild diff --git a/assets/scripts/app/views/repo/show.coffee b/assets/scripts/app/views/repo/show.coffee index 873a7300..92f501a5 100644 --- a/assets/scripts/app/views/repo/show.coffee +++ b/assets/scripts/app/views/repo/show.coffee @@ -90,6 +90,18 @@ element = $('#tools .menu').toggleClass('display') event.stopPropagation() + requeue: -> + @closeMenu() + @get('build').requeue() + + cancelBuild: -> + @closeMenu() + @get('build').cancel() + + cancelJob: -> + @closeMenu() + @get('job').cancel() + statusImages: (event) -> @set('active', true) @closeMenu() @@ -128,20 +140,30 @@ @get('isJobTab') && @get('job.isFinished') && @get('hasPermissions') ).property('isJobTab', 'job.isFinished', 'hasPermissions') + canCancelBuild: (-> + @get('isBuildTab') && @get('build.canCancel') && @get('hasPermission') + ).property('build.state', 'hasPushPermissions', 'tab') + canRegenerateKey: (-> @get('hasPermissions') ).property('hasPermissions') - isBuildTab: (-> - # ['current', 'build', 'job'].indexOf(@get('tab')) > -1 - @get('tab') in ['current', 'build'] - ).property('tab') + canCancelJob: (-> + console.log @get('isJobTab') + console.log @get('job.canCancel') + console.log @get('hasPermission') + @get('isJobTab') && @get('job.canCancel') && @get('hasPermission') + ).property('job.state', 'hasPushPermissions', 'tab') isJobTab: (-> @get('tab') == 'job' ).property('tab') - hasPermissions: (-> + isBuildTab: (-> + ['current', 'build'].indexOf(@get('tab')) > -1 + ).property('tab') + + hasPermission: (-> if permissions = Travis.app.get('currentUser.permissions') permissions.indexOf(@get('repo.id')) > -1 ).property('Travis.app.currentUser.permissions.length', 'repo.id')