Allow to change the place of insertion for limited array

This commit is contained in:
Piotr Sarnacki 2012-12-11 14:40:55 +01:00
parent fa5de8ba66
commit 79e6f5e037
3 changed files with 11 additions and 3 deletions

View File

@ -68,6 +68,7 @@ Travis.Store = DS.Store.extend
{ id: id, clientId: clientId }
receive: (event, data) ->
console.log event, data
[name, type] = event.split(':')
mappings = @adapter.get('mappings')

View File

@ -45,7 +45,7 @@
didInsertElement: ->
queues = for queue in Travis.QUEUES
Travis.LimitedArray.create
debug: true
insertAtTheBeginning: false
content: Travis.Job.queued(queue.name), limit: 20
id: "queue_#{queue.name}"
name: queue.display

View File

@ -1,6 +1,7 @@
Travis.LimitedArray = Em.ArrayProxy.extend
limit: 10
isLoadedBinding: 'content.isLoaded'
insertAtTheBeginning: true
init: ->
@_super.apply this, arguments
@ -46,7 +47,10 @@ Travis.LimitedArray = Em.ArrayProxy.extend
if addedCount > 0
addedObjects = array.slice(index, index + addedCount)
for object in addedObjects
arrangedContent.unshiftObject(object)
if @get('insertAtTheBeginning')
arrangedContent.unshiftObject(object)
else
arrangedContent.pushObject(object)
if removedCount
removedObjects = array.slice(index, index + removedCount);
@ -61,5 +65,8 @@ Travis.LimitedArray = Em.ArrayProxy.extend
count = limit - length
while count > 0
if next = content.find( (object) -> !arrangedContent.contains(object) )
arrangedContent.unshiftObject(next)
if @get('insertAtTheBeginning')
arrangedContent.unshiftObject(object)
else
arrangedContent.pushObject(object)
count -= 1