Change running jobs and queue into components

This commit is contained in:
Piotr Sarnacki 2015-08-06 13:14:41 +02:00
parent 8c35e42b2b
commit a0ca1ec66b
9 changed files with 69 additions and 58 deletions

View File

@ -0,0 +1,16 @@
`import Ember from 'ember'`
`import config from 'travis/config/environment'`
QueuedJobsComponent = Ember.Component.extend
store: Ember.inject.service()
init: ->
@_super.apply this, arguments
if !Ember.testing
Visibility.every config.intervals.updateTimes, @updateTimes.bind(this)
updateTimes: ->
if jobs = @get('jobs')
jobs.forEach (job) -> job.updateTimes()
`export default QueuedJobsComponent`

View File

@ -0,0 +1,20 @@
`import Ember from 'ember'`
`import Polling from 'travis/mixins/polling'`
`import config from 'travis/config/environment'`
RunningJobsComponent = Ember.Component.extend Polling,
store: Ember.inject.service()
pollHook: (store) ->
@get('store').find('job', {})
init: ->
@_super.apply this, arguments
if !Ember.testing
Visibility.every config.intervals.updateTimes, @updateTimes.bind(this)
updateTimes: ->
if jobs = @get('jobs')
jobs.forEach (job) -> job.updateTimes()
`export default RunningJobsComponent`

View File

@ -1,14 +0,0 @@
`import Ember from 'ember'`
Controller = Ember.ArrayController.extend
isLoaded: false
content: (->
result = @store.filter('job', {}, (job) ->
['created', 'queued'].indexOf(job.get('state')) != -1
)
result.then =>
@set('isLoaded', true)
result
).property()
`export default Controller`

View File

@ -31,7 +31,7 @@ Controller = Ember.Controller.extend
@container.lookup('router:main').send('redirectToGettingStarted')
isLoadedBinding: 'repos.isLoaded'
needs: ['currentUser', 'repo', 'runningJobs', 'queue']
needs: ['currentUser', 'repo']
currentUserBinding: 'controllers.currentUser.model'
selectedRepo: (->
# we need to observe also repo.content here, because we use
@ -40,16 +40,37 @@ Controller = Ember.Controller.extend
@get('controllers.repo.repo.content') || @get('controllers.repo.repo')
).property('controllers.repo.repo', 'controllers.repo.repo.content')
startedJobsCount: Ember.computed.alias('controllers.runningJobs.length')
startedJobsCount: Ember.computed.alias('runningJobs.length')
allJobsCount: (->
@get('startedJobsCount') + @get('controllers.queue.length')
).property('startedJobsCount', 'controllers.queue.length')
@get('startedJobsCount') + @get('queuedJobs.length')
).property('startedJobsCount', 'queuedJobs.length')
init: ->
@_super.apply this, arguments
if !Ember.testing
Visibility.every @config.intervals.updateTimes, @updateTimes.bind(this)
runningJobs: (->
# TODO: this should also query for received jobs
result = @store.filter('job', {}, (job) ->
['started', 'received'].indexOf(job.get('state')) != -1
)
result.set('isLoaded', false)
result.then =>
result.set('isLoaded', true)
result
).property()
queuedJobs: (->
result = @get('store').filter('job', {}, (job) ->
['created', 'queued'].indexOf(job.get('state')) != -1
)
result.set('isLoaded', false)
result.then =>
result.set('isLoaded', true)
result
).property()
recentRepos: (->
# I return an empty array here, because we're removing left sidebar, but
# I don't want to refactor too much code (it will be all changed anyway

View File

@ -1,24 +0,0 @@
`import Ember from 'ember'`
Controller = Ember.ArrayController.extend
init: ->
@_super.apply this, arguments
if !Ember.testing
Visibility.every @config.intervals.updateTimes, @updateTimes.bind(this)
updateTimes: ->
if content = @get('content')
content.forEach (job) -> job.updateTimes()
isLoaded: false
content: (->
# TODO: this should also query for received jobs
result = @store.filter('job', {}, (job) ->
['started', 'received'].indexOf(job.get('state')) != -1
)
result.then =>
@set('isLoaded', true)
result
).property()
`export default Controller`

View File

@ -1,6 +1,6 @@
{{#if isLoaded}}
{{#if length}}
{{#each job in controller}}
{{#if jobs.isLoaded}}
{{#if jobs.length}}
{{#each jobs as |job|}}
<div class="tile tile--sidebar {{job.state}}">
{{#if job.repo.slug}}
<span class="icon icon--job {{job.state}}"></span>

View File

@ -1,6 +1,6 @@
{{#if isLoaded}}
{{#if controller.length}}
{{#each job in controller}}
{{#if jobs.isLoaded}}
{{#if jobs.length}}
{{#each jobs as |job| }}
<div class="tile tile--sidebar {{job.state}}">
{{#if job.repo.slug}}
<span class="icon icon--job {{job.state}}"></span>

View File

@ -9,11 +9,11 @@
{{#if showRunningJobs}}
<div class="tabbody sidebar-list">
<div>
{{render "runningJobs"}}
{{running-jobs jobs=runningJobs}}
</div>
<hr class="sidebar-seperator">
<div>
{{render "queue"}}
{{queued-jobs jobs=queuedJobs}}
</div>
</div>
{{else}}

View File

@ -1,8 +0,0 @@
`import BasicView from 'travis/views/basic'`
`import Polling from 'travis/mixins/polling'`
View = BasicView.extend Polling,
pollHook: (store) ->
@get('controller.store').find('job', {})
`export default View`