From c00aa911d73cd7b3c8104425454e3a379495e25a Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Mon, 3 Dec 2012 03:54:48 +0100
Subject: [PATCH] Add regenerate key option in repo view
---
assets/scripts/app/models/repo.coffee | 3 ++
.../app/templates/repos/show/tools.hbs | 33 +++++++++++++++++++
assets/scripts/app/views.coffee | 3 +-
assets/scripts/app/views/repo/show.coffee | 20 +++++++++++
assets/styles/app/popup.sass | 23 +++++++++++++
assets/styles/main/tools.sass | 2 +-
6 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/assets/scripts/app/models/repo.coffee b/assets/scripts/app/models/repo.coffee
index bb706ac2..145c0fd4 100644
--- a/assets/scripts/app/models/repo.coffee
+++ b/assets/scripts/app/models/repo.coffee
@@ -94,6 +94,9 @@ require 'travis/model'
updateTimes: ->
@notifyPropertyChange 'lastBuildDuration'
+ regenerateKey: (options) ->
+ Travis.ajax.ajax '/repos/' + @get('id') + '/key', 'post', options
+
@Travis.Repo.reopenClass
recent: ->
@find()
diff --git a/assets/scripts/app/templates/repos/show/tools.hbs b/assets/scripts/app/templates/repos/show/tools.hbs
index ad95fdd5..cd8ea082 100644
--- a/assets/scripts/app/templates/repos/show/tools.hbs
+++ b/assets/scripts/app/templates/repos/show/tools.hbs
@@ -14,6 +14,11 @@
Rebuild
{{/if}}
+ {{#if view.canRegenerateKey}}
+
+
+
+ {{/if}}
@@ -44,3 +49,31 @@
+
+
+
+
diff --git a/assets/scripts/app/views.coffee b/assets/scripts/app/views.coffee
index 4523c318..39381515 100644
--- a/assets/scripts/app/views.coffee
+++ b/assets/scripts/app/views.coffee
@@ -4,7 +4,8 @@ require 'ext/ember/namespace'
View: Em.View.extend
popup: (event) ->
@popupCloseAll()
- $("##{event.target.name}").toggleClass('display')
+ name = if event.target then event.target.name else event
+ $("##{name}").toggleClass('display')
popupClose: (event) ->
$(event.target).closest('.popup').removeClass('display')
popupCloseAll: ->
diff --git a/assets/scripts/app/views/repo/show.coffee b/assets/scripts/app/views/repo/show.coffee
index f9edd3a4..873a7300 100644
--- a/assets/scripts/app/views/repo/show.coffee
+++ b/assets/scripts/app/views/repo/show.coffee
@@ -96,6 +96,12 @@
@popup(event)
event.stopPropagation()
+ regenerateKeyPopup: (event) ->
+ @set('active', true)
+ @closeMenu()
+ @popup(event)
+ event.stopPropagation()
+
requeueBuild: ->
@closeMenu()
@get('build').requeue()
@@ -104,6 +110,16 @@
@closeMenu()
@get('job').requeue()
+ regenerateKey: ->
+ @popupCloseAll()
+ self = this
+
+ @get('repo').regenerateKey
+ success: ->
+ self.popup('regeneration-success')
+ error: ->
+ Travis.app.router.flashController.loadFlashes([{ error: 'Travis encountered an error while trying to regenerate the key, please try again.'}])
+
canRequeueBuild: (->
@get('isBuildTab') && @get('build.isFinished') && @get('hasPermissions')
).property('isBuildTab', 'build.isFinished', 'hasPermissions')
@@ -112,6 +128,10 @@
@get('isJobTab') && @get('job.isFinished') && @get('hasPermissions')
).property('isJobTab', 'job.isFinished', 'hasPermissions')
+ canRegenerateKey: (->
+ @get('hasPermissions')
+ ).property('hasPermissions')
+
isBuildTab: (->
# ['current', 'build', 'job'].indexOf(@get('tab')) > -1
@get('tab') in ['current', 'build']
diff --git a/assets/styles/app/popup.sass b/assets/styles/app/popup.sass
index 3e22dce5..53d2da04 100644
--- a/assets/styles/app/popup.sass
+++ b/assets/styles/app/popup.sass
@@ -58,4 +58,27 @@
padding: 4px
@include border-radius(3px)
+#regenerate-key
+ .cancel
+ text-decoration: underline
+ p
+ text-align: center
+ .or
+ display: inline-block
+ margin: 20px 10px 0 10px
+ p:last-of-type
+ margin-bottom: 5px
+ a.button
+ font-size: 13px
+#status-images, #regenerate-key
+ input
+ border: 1px solid $color-border-light
+ width: 505px
+ padding: 4px
+ @include border-radius(3px)
+
+#regenerate-key, #regeneration-success
+ display: none
+ width: 400px
+ margin: -95px 0 0 -300px
diff --git a/assets/styles/main/tools.sass b/assets/styles/main/tools.sass
index e2b65842..67fcdca8 100644
--- a/assets/styles/main/tools.sass
+++ b/assets/styles/main/tools.sass
@@ -17,7 +17,7 @@
position: absolute
right: 0
top: -3px
- width: 130px
+ width: 135px
background-color: $color-bg-menu
border: 1px solid $color-border-light
@include border-bottom-radius(4px)