Fix workers sorting, it should be done based on SortableMixin

This commit is contained in:
Piotr Sarnacki 2012-10-12 20:37:12 +02:00
parent 87bccccde8
commit 3ecbc8f139
4 changed files with 22 additions and 27 deletions

View File

@ -15,31 +15,12 @@ Travis.reopen
groups = {}
for worker in content.toArray()
host = worker.get('host')
groups[host] = Em.ArrayProxy.create(content: []) unless groups[host]
groups[host].pushObject(worker)
prepareForSort = (str) ->
match = str.match /(.*?)-(\d+)/
name = match[1]
id = match[2].toString()
if id.length < 2
id = "00#{id}"
else if id.length < 3
id = "0#{id}"
"#{name}-#{id}"
for own host, workers of groups
groups[host] = workers.toArray().sort (a, b) ->
a = prepareForSort a.get('name')
b = prepareForSort b.get('name')
if a < b
-1
else if b < a
1
else
0
unless groups[host]
groups[host] = Em.ArrayProxy.create(Em.SortableMixin,
content: [],
sortProperties: ['nameForSort']
)
groups[host].addObject(worker)
$.values(groups)
).property('length')

View File

@ -29,3 +29,17 @@ require 'travis/model'
job: (->
Travis.Job.find @get('job_id')
).property('job_id')
nameForSort: (->
if name = @get('name')
match = name.match /(.*?)-(\d+)/
if match
name = match[1]
id = match[2].toString()
if id.length < 2
id = "00#{id}"
else if id.length < 3
id = "0#{id}"
"#{name}-#{id}"
).property('name')

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long