Display running jobs

This commit is contained in:
Piotr Sarnacki 2013-02-07 04:15:24 +01:00
parent c17b9cd271
commit ad6f9e59c7
8 changed files with 132 additions and 0 deletions

View File

@ -20,5 +20,6 @@ require 'controllers/home'
require 'controllers/profile'
require 'controllers/repos'
require 'controllers/repo'
require 'controllers/running_jobs'
require 'controllers/sidebar'
require 'controllers/stats'

View File

@ -0,0 +1,68 @@
Travis.RunningJobsController = Em.ArrayProxy.extend
Group: Em.Object.extend
build: (-> @get('jobs.firstObject.build') ).property('jobs.firstObject.build')
init: ->
@set 'jobs', []
add: (job) ->
@get('jobs').pushObject(job) unless @get('jobs').contains job
@attach()
remove: (job) ->
@get('jobs').removeObject(job)
@clean()
attach: ->
@get('parent').addGroup(this)
clean: ->
@get('parent').removeGroup(this) if @get('isEmpty')
isEmpty: (->
@get('jobs.length') == 0
).property('jobs.length')
groups: []
groupsByBuildIds: {}
init: ->
@_super.apply this, arguments
@addedJobs @get('content') if @get('content')
contentArrayWillChange: (array, index, removedCount, addedCount) ->
@_super.apply this, arguments
if removedCount
@removedJobs array.slice(index, index + removedCount)
contentArrayDidChange: (array, index, removedCount, addedCount) ->
@_super.apply this, arguments
if addedCount
@addedJobs array.slice(index, index + addedCount)
addedJobs: (jobs) ->
self = this
jobs.forEach (job) ->
buildId = job.get('buildId')
group = self.groupForBuild(buildId)
group.add(job)
removedJobs: (jobs) ->
self = this
jobs.forEach (job) ->
buildId = job.get('buildId')
group = self.groupForBuild(buildId)
group.remove(job)
groupForBuild: (buildId) ->
@groupsByBuildIds[buildId] ||= @Group.create(buildId: buildId, parent: this)
addGroup: (group) ->
@get('groups').pushObject group unless @get('groups').contains group
removeGroup: (group) ->
@get('groups').removeObject group
delete @groupsByBuildIds[group.get('buildId')]

View File

@ -103,6 +103,11 @@ require 'travis/model'
# TODO: why queue is sometimes just common instead of build.common?
queued && (!queue || job.get('queue') == "builds.#{queue}" || job.get('queue') == queue)
running: ->
@find(state: 'started')
Travis.app.store.filter this, (job) ->
job.get('state') == 'started'
findMany: (ids) ->
Travis.app.store.findMany this, ids

View File

@ -0,0 +1,6 @@
<h4>Running jobs</h4>
<ul class="groups">
{{#each group in view.groups}}
{{view view.GroupView groupBinding="group"}}
{{/each}}
</ul>

View File

@ -0,0 +1,14 @@
<a {{action toggle target="view"}}>
<span class="slug">{{build.repo.slug}}</span>
#{{build.number}}
</a>
<ul class="jobs">
{{#each job in jobs}}
<li class="job">
<a {{action showJob job.repoData job target="Travis.app.router" href=true}}>
#{{job.number}}
</a>
</li>
{{/each}}
</ul>

View File

@ -10,6 +10,7 @@
{{view view.DecksView}}
{{view view.WorkersView}}
{{view view.RunningJobsView}}
{{view view.QueuesView}}
{{view view.LinksView}}

View File

@ -51,6 +51,27 @@
@set 'controller.content', queues
@_super.apply this, arguments
RunningJobsView: Em.View.extend
templateName: 'jobs/running'
elementId: 'running-jobs'
controller: Travis.RunningJobsController.create()
groupsBinding: 'controller.groups'
didInsertElement: ->
@get('controller').set 'content', Travis.Job.running()
GroupView: Em.View.extend
templateName: 'jobs/running/group'
tagName: 'li'
contextBinding: 'group'
expanded: false
classNameBindings: ['expanded']
classNames: ['group']
toggle: ->
@toggleProperty('expanded')
WorkersView: Travis.View.extend
toggleWorkers: (event) ->
handle = $(event.target).toggleClass('open')

View File

@ -40,3 +40,19 @@
#right .show-more-jobs
text-decoration: underline
cursor: pointer
#running-jobs
.jobs
display: none
.expanded .jobs
display: block
.job
padding-left: 20px
.slug
max-width: 150px
overflow: hidden
white-space: nowrap
text-overflow: ellipsis
display: inline-block
.group a
cursor: pointer