Show only first 15 elements from each queue for now

With shitloads of jobs in queues app becomes unusable, this is a quick
solution to make it better.
This commit is contained in:
Piotr Sarnacki 2012-11-28 00:04:21 +01:00
parent 834e45ceb5
commit afa1d07fbe
4 changed files with 47 additions and 9 deletions

View File

@ -18,6 +18,12 @@
{{t no_job}}
{{/each}}
</ul>
{{#if queue.isMore}}
<a {{action loadMoreJobs this.queue target="view"}} class="show-more-jobs">
{{queue.leftLength}} more jobs - show more
</a>
{{/if}}
</li>
{{/each}}
</ul>

View File

@ -38,10 +38,14 @@
templateName: 'queues/list'
controller: Em.ArrayController.create()
loadMoreJobs: (event) ->
queue = event.context
queue.incrementProperty('limit', 20)
didInsertElement: ->
queues = for queue in Travis.QUEUES
Em.ArrayController.create
content: Travis.Job.queued(queue.name)
Travis.LimitedArray.create
content: Travis.Job.queued(queue.name), limit: 15
id: "queue_#{queue.name}"
name: queue.display
@set 'controller.content', queues

View File

@ -8,17 +8,42 @@ Travis.LimitedArray = Em.ArrayProxy.extend
arrangedContent: (->
if content = @get('content')
content.slice(0, @get('limit'))
).property('content')
).property('content', 'limit')
totalLength: (->
@get('content.length')
).property('content.length')
leftLength: (->
totalLength = @get('totalLength')
limit = @get('limit')
if totalLength > limit
totalLength - limit
else
0
).property('totalLength', 'limit')
isMore: (->
@get('leftLength') > 0
).property('leftLength')
contentArrayDidChange: (array, index, removedCount, addedCount) ->
@_super.apply this, arguments
if addedCount > 0
limit = @get 'limit'
arrangedContent = @get('arrangedContent')
length = arrangedContent.get 'length'
if addedCount > 0 && length < limit
addedObjects = array.slice(index, index + addedCount)
arrangedContent = @get('arrangedContent')
for object in addedObjects
arrangedContent.unshiftObject(object)
limit = @get 'limit'
length = arrangedContent.get 'length'
if length > limit
arrangedContent.replace(limit, length - limit)
if removedCount
removedObjects = array.slice(index, index + removedCount);
arrangedContent.removeObjects(removedObjects)
if length > limit
arrangedContent.replace(limit, length - limit)
else if length < limit
@set('arrangedContent', @get('content').slice(0, @get('limit')))

View File

@ -37,3 +37,6 @@
&:hover
background-color: $color-border-slider-hover
#right .show-more-jobs
text-decoration: underline
cursor: pointer