Implement missing pieces for cancel build

We allow to cancel only created builds at this point.
This commit is contained in:
Piotr Sarnacki 2013-08-09 15:07:29 +02:00
parent 93e7b40346
commit 0217b20943
4 changed files with 37 additions and 20 deletions

View File

@ -22,6 +22,9 @@ unless window.TravisApplication
lookup: ->
@__container__.lookup.apply @__container__, arguments
flash: (options) ->
Travis.lookup('controller:flash').loadFlashes([options])
storeAfterSignInPath: (path) ->
@get('auth').storeAfterSignInPath(path)

View File

@ -62,11 +62,11 @@ require 'travis/model'
).property('rawConfigKeys.length')
canCancel: (->
@get('state') == 'created' # TODO
).property('state')
!@get('isFinished') && @get('jobs').filter( (j) -> j.get('canCancel') ).get('length') > 0
).property('isFinished', 'jobs.@each.canCancel')
cancel: (->
Travis.ajax.post "/builds/#{@get('id')}", _method: 'delete'
Travis.ajax.post "/builds/#{@get('id')}/cancel"
)
requeue: ->

View File

@ -73,11 +73,11 @@ require 'travis/model'
).property('config', 'build.rawConfigKeys.length')
canCancel: (->
@get('state') == 'created' || @get('state') == 'queued' # TODO
@get('state') == 'created'
).property('state')
cancel: (->
Travis.ajax.post "/jobs/#{@get('id')}", _method: 'delete'
Travis.ajax.post "/jobs/#{@get('id')}/cancel"
)
requeue: ->

View File

@ -94,12 +94,30 @@ Travis.reopen
cancelBuild: ->
if @get('canCancelBuild')
@closeMenu()
@get('build').cancel()
Travis.flash(notice: 'Build cancelation has been scheduled.')
@get('build').cancel().then ->
Travis.flash(success: 'Build has been successfuly canceled.')
, (xhr) ->
if xhr.status == 422
Travis.flash(error: 'This build can\'t be canceled')
else if xhr.status == 403
Travis.flash(error: 'You don\'t have sufficient access to cancel this build')
else
Travis.flash(error: 'An error occured when canceling the build')
cancelJob: ->
if @get('canCancelJob')
@closeMenu()
@get('job').cancel()
Travis.flash(notice: 'Job cancelation has been scheduled.')
@get('job').cancel().then ->
Travis.flash(success: 'Job has been successfuly canceled.')
, (xhr) ->
if xhr.status == 422
Travis.flash(error: 'This job can\'t be canceled')
else if xhr.status == 403
Travis.flash(error: 'You don\'t have sufficient access to cancel this job')
else
Travis.flash(error: 'An error occured when canceling the job')
statusImages: ->
@set('active', true)
@ -168,26 +186,22 @@ Travis.reopen
Travis.Urls.plainTextLog(id)
).property('jobIdForLog')
displayCancelBuild: (->
# @get('isBuildTab') && @get('build.canCancel')
false
).property('build.state', 'tab')
canCancelBuild: (->
# @get('displayCancelBuild') && @get('hasPermission')
false
@get('displayCancelBuild') && @get('hasPermission')
).property('displayCancelBuild', 'hasPermission')
displayCancelJob: (->
# @get('isJobTab') && @get('job.canCancel')
false
).property('job.state', 'tab')
displayCancelBuild: (->
@get('isBuildTab') && @get('build.canCancel')
).property('isBuildTab', 'build.canCancel')
canCancelJob: (->
# @get('displayCancelJob') && @get('hasPermission')
false
@get('displayCancelJob') && @get('hasPermission')
).property('displayCancelJob', 'hasPermission')
displayCancelJob: (->
@get('isJobTab') && @get('job.canCancel')
).property('isJobTab', 'job.canCancel')
displayRegenerateKey: true
canRegenerateKey: (->