Implement concurrent builds limit in settings

This commit is contained in:
Piotr Sarnacki 2015-07-21 18:01:46 +02:00
parent e7aa74872d
commit 271724f994
5 changed files with 41 additions and 5 deletions

View File

@ -1,6 +1,13 @@
`import Ember from 'ember'`
SettingsController = Ember.Controller.extend
concurrentBuildsLimitDescription: (->
description = "Limit concurrent jobs"
if @get('concurrentBuildsLimit')
description += ": "
description
).property('concurrentBuildsLimit')
envVars: Ember.computed.filterBy('model.envVars', 'isNew', false)
actions:
@ -10,4 +17,26 @@ SettingsController = Ember.Controller.extend
sshKeyDeleted: ->
@set('model.customSshKey', null)
concurrentBuildsLimitChanged: ->
unless @get('concurrentBuildsLimit')
return if @get('isSaving')
@set('isSaving', true)
savingFinished = =>
@set('isSaving', false)
@get('repo').saveSettings(maximum_number_of_builds: 0).then(savingFinished, savingFinished)
@set('model.settings.maximum_number_of_builds', 0)
concurrentBuildsLimitValueChanged: ->
repo = @get('repo')
concurrentBuildsLimit = parseInt(@get('model.settings.maximum_number_of_builds'))
if concurrentBuildsLimit
@set('isSaving', true)
savingFinished = =>
@set('isSaving', false)
repo.saveSettings(maximum_number_of_builds: concurrentBuildsLimit).
then(savingFinished, savingFinished)
`export default SettingsController`

View File

@ -8,6 +8,8 @@ Route = TravisRoute.extend
controller.set('repo', @modelFor('repo'))
@controllerFor('repo').activate('settings')
controller.set('concurrentBuildsLimit', !!model.settings.maximum_number_of_builds)
fetchEnvVars: () ->
repo = @modelFor('repo')
repo.get('envVars.promise')

View File

@ -9,7 +9,7 @@
{{input value=value class="env-value" placeholder="Value"}}
</div>
<div class="form-elem">
{{travis-switch active=public}}
{{travis-switch active=public description="Display value in build log"}}
</div>
<div class="form-elem">
{{#if isSaving}}

View File

@ -6,4 +6,4 @@
OFF
</span>
</div>
<span class="label">Display value in build log</span>
<span class="label">{{description}}</span>

View File

@ -1,12 +1,17 @@
<div class="settings">
<section class="settings-section">
<h2 class="small-title">General Settings</h2>
<ul class="settings-list--columns">
<li>{{settings-switch active=model.settings.builds_only_with_travis_yml repo=repo description="Build only if .travis.yml is present" key="builds_only_with_travis_yml"}}</li>
<li>
<div class="settings-input"><input type="text" pattern="/^[0-9]+$/" value="4"></div><span class="label">Concurrent jobs</span>
<li>{{travis-switch active=concurrentBuildsLimit description=concurrentBuildsLimitDescription action="concurrentBuildsLimitChanged"}}
{{#if concurrentBuildsLimit}}
{{input pattern="/^[0-9]+$/" value=model.settings.maximum_number_of_builds on="key-up" action="concurrentBuildsLimitValueChanged"}}
{{/if}}
{{#if isSaving}}
{{loading-indicator}}
{{/if}}
</li>
<li>{{settings-switch active=model.settings.build_pushes repo=repo description="Build pushes" key="build_pushes"}}</li>
<li>{{settings-switch active=model.settings.build_pull_requests repo=repo description="Build pull requests" key="build_pull_requests"}}</li>