Skip to content
This repository has been archived by the owner on Nov 17, 2018. It is now read-only.

Commit

Permalink
Add simple group feature [#7].
Browse files Browse the repository at this point in the history
I'd like to roll up statuses for grouped jobs to their group header in
the index, i.e. if any of the grouped jobs has failed, then the group
should be marked failed.
  • Loading branch information
seven1m committed Apr 29, 2013
1 parent 5ebfc2e commit 2414536
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/collections/jobs.coffee
Expand Up @@ -3,6 +3,7 @@ class app.collections.jobs extends Backbone.Collection
namespace: 'job'

comparator: (job) ->
new String(job.get('group') || 'zzz').toLowerCase() +
new String(job.get('name')).toLowerCase()

getOrFetch: (id, callback) ->
Expand Down
3 changes: 3 additions & 0 deletions app/stylesheets/main.styl
Expand Up @@ -101,3 +101,6 @@ td.data table td

textarea.input-large
width 275px

tr.grouped
display none
5 changes: 5 additions & 0 deletions app/templates/jobs/_form.jade
Expand Up @@ -8,6 +8,11 @@ fieldset
.control-group
label.control-label(for='description') Description
textarea.input-large#description(name='description')
.control-group
label.control-label(for='group') Group
input.input-large#group(name='group')
span.help-inline
| jobs with the same group name will be grouped together in the index
.control-group
label.control-label(for='enabled') Enabled
input#enabled(type='checkbox', name='enabled', value='enabled')
Expand Down
6 changes: 6 additions & 0 deletions app/templates/jobs/group_row.jade
@@ -0,0 +1,6 @@
tr
td(colspan=6)
a(href='#')
i.icon-plus
|
span.name
1 change: 1 addition & 0 deletions app/views/jobs/edit.coffee
Expand Up @@ -8,6 +8,7 @@ class app.views.jobs.edit extends Backbone.BoundView
bindings:
name: '#name'
description: '#description'
group: '#group'
path: '#path'
enabled:
selector: '#enabled'
Expand Down
27 changes: 27 additions & 0 deletions app/views/jobs/group_row.coffee
@@ -0,0 +1,27 @@
app.views.jobs ?= {}

class app.views.jobs.group_row extends Backbone.View

events:
click: 'expandGroup'

tagName: 'tr'

template: =>
$(jade.render 'jobs/group_row').html()

render: =>
@$el
.html(@template())
.addClass('group-row')
.attr('id', "group-#{@options.groupId}")
.find('.name').html(@options.name)
@

expandGroup: =>
@$el.find('i').toggleClass ->
if $(this).hasClass('icon-plus')
'icon-minus'
else
'icon-plus'
$(".group-#{@options.groupId}").toggle()
16 changes: 15 additions & 1 deletion app/views/jobs/index.coffee
Expand Up @@ -5,10 +5,24 @@ class app.views.jobs.index extends Backbone.View
initialize: ->
@collection.on 'add', @add
@collection.on 'reset', @reset
@lastGroup = null
@lastGroupId = 0

add: (job) =>
group = job.get('group')
if group and group != @lastGroup
@addGroup(group, ++@lastGroupId)
@lastGroup = group
job.set('groupId', group && @lastGroupId)
view = new app.views.jobs.row(model: job).render()
@$el.find('tbody').append view.$el
@appendRow view.$el

addGroup: (name, groupId) =>
view = new app.views.jobs.group_row(name: name, groupId: groupId).render()
@appendRow view.$el

appendRow: (html) =>
@$el.find('tbody').append(html)

reset: (jobs) =>
@$el.find('tbody').empty()
Expand Down
6 changes: 6 additions & 0 deletions app/views/jobs/row.coffee
Expand Up @@ -33,3 +33,9 @@ class app.views.jobs.row extends Backbone.BoundView
selector: '.name, .schedule, .hooks'
elAttribute: 'class'
converter: (_, v) -> 'disabled' unless v

render: =>
super()
if group = @model.get('groupId')
@$el.addClass("grouped group-#{group}")
@
5 changes: 4 additions & 1 deletion models/job.coffee
Expand Up @@ -10,6 +10,8 @@ schema = new Schema
required: true
description:
type: String
group:
type: String
schedule:
type: String
validate: (v) ->
Expand Down Expand Up @@ -61,6 +63,7 @@ schema.pre 'save', (next) ->
schema.methods.updateAttributes = (attrs) ->
@name = attrs.name
@description = attrs.description
@group = attrs.group
@schedule = attrs.schedule
@enabled = attrs.enabled == '1'
@mutex = attrs.mutex == '1'
Expand Down Expand Up @@ -112,7 +115,7 @@ model.sync = (socket) ->
if err or not job
callback err || 'job not found'
else
for attr in ['name', 'description', 'enabled', 'schedule', 'hooks', 'workerName', 'mutex', 'timeout']
for attr in ['name', 'description', 'group', 'enabled', 'schedule', 'hooks', 'workerName', 'mutex', 'timeout']
job[attr] = data[attr] if data[attr]?
job.save (err) =>
if err
Expand Down

0 comments on commit 2414536

Please sign in to comment.