Fix workers sorting, it should be done based on SortableMixin
This commit is contained in:
parent
87bccccde8
commit
3ecbc8f139
|
@ -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')
|
||||
|
|
|
@ -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
Loading…
Reference in New Issue
Block a user