Skip to content

Commit 812af28

Browse files
committed
datasource min index and max index properties
1 parent 3409732 commit 812af28

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

src/ui-scroll.coffee

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ angular.module('ui.scroll', [])
124124

125125
buffer.next = 1
126126

127+
128+
127129
buffer
128130

129131
Padding = (template) ->
@@ -297,6 +299,15 @@ angular.module('ui.scroll', [])
297299
setTopVisibleElement(viewportScope, item.element)
298300
setTopVisibleScope(viewportScope, item.scope)
299301

302+
if $attr.isLoading
303+
setIsLoading = $parse($attr.isLoading).assign
304+
else
305+
setIsLoading = ->
306+
307+
this.loading = (value) ->
308+
this.isLoading = value
309+
setIsLoading viewportScope, value
310+
300311
return
301312

302313
require: ['?^uiScrollViewport']
@@ -311,7 +322,7 @@ angular.module('ui.scroll', [])
311322
itemName = match[1]
312323
datasourceName = match[2]
313324

314-
325+
bufferSize = Math.max(3, +attr.bufferSize || 10)
315326

316327
($scope, element, $attr, controllers, linker) ->
317328

@@ -325,12 +336,10 @@ angular.module('ui.scroll', [])
325336
if !isDatasourceValid()
326337
throw new Error datasourceName + ' is not a valid datasource'
327338

328-
bufferSize = Math.max(3, +$attr.bufferSize || 10)
329-
330-
# initial settings
331-
332339
ridActual = 0 # current data revision id
340+
333341
pending = []
342+
334343
buffer = new Buffer(itemName, $scope, linker)
335344

336345
viewport = new Viewport(buffer, element, controllers, $attr.padding)
@@ -347,19 +356,7 @@ angular.module('ui.scroll', [])
347356
adapterOnScope = $parse($attr.adapter)($scope)
348357
angular.extend(adapterOnScope, adapter)
349358
adapter = adapterOnScope
350-
###
351-
setTopVisible = (item) ->
352-
353-
viewportScope = viewport.scope() || $rootScope
354-
355-
adapter.topVisible = item.item
356-
adapter.topVisibleElement = item.element
357-
adapter.topVisibleScope = item.scope
358-
$parse($attr.topVisible).assign(viewportScope, adapter.topVisible) if $attr.topVisible
359-
$parse($attr.topVisibleElement).assign(viewportScope, adapter.topVisibleElement) if $attr.topVisibleElement
360-
$parse($attr.topVisibleScope).assign(viewportScope, adapter.topVisibleScope) if $attr.topVisibleScope
361-
datasource.topVisible(item) if angular.isFunction(datasource.topVisible)
362-
###
359+
363360
calculateProperties = ->
364361
if (buffer.length > 0)
365362
buffer.elementHeight = (buffer[buffer.length-1].element.offset().top +
@@ -376,8 +373,9 @@ angular.module('ui.scroll', [])
376373
else
377374
adapter.setTopVisible(item) if newRow
378375
break
376+
console.log "min=#{datasource.minIndex} max=#{datasource.maxIndex}"
379377

380-
# Padding element builder
378+
# Build padding elements
381379
#
382380
# Calling linker is the only way I found to get access to the tag name of the template
383381
# to prevent the directive scope from pollution a new scope is created and destroyed
@@ -391,11 +389,6 @@ angular.module('ui.scroll', [])
391389
# also remove the template when the directive scope is destroyed
392390
$scope.$on '$destroy', -> template.remove()
393391

394-
loading = (value) ->
395-
adapter.isLoading = value
396-
$parse($attr.isLoading).assign($scope, value) if $attr.isLoading
397-
datasource.loading(value) if angular.isFunction(datasource.loading)
398-
399392
dismissPendingRequests = () ->
400393
ridActual++
401394
pending = []
@@ -411,7 +404,7 @@ angular.module('ui.scroll', [])
411404

412405
enqueueFetch = (rid, direction)->
413406
if !adapter.isLoading
414-
loading(true)
407+
adapter.loading(true)
415408
if pending.push(direction) == 1
416409
fetch(rid)
417410

@@ -521,7 +514,7 @@ angular.module('ui.scroll', [])
521514

522515
pending.shift()
523516
if pending.length == 0
524-
loading(false)
517+
adapter.loading(false)
525518
calculateProperties()
526519
else
527520
fetch(rid)
@@ -546,6 +539,10 @@ angular.module('ui.scroll', [])
546539
++buffer.next
547540
buffer.insert 'append', item
548541
#log 'appended: requested ' + bufferSize + ' received ' + result.length + ' buffer size ' + buffer.length + ' first ' + first + ' next ' + next
542+
if buffer.eof
543+
datasource.maxIndex = buffer.next-1
544+
else
545+
datasource.maxIndex = Math.max buffer.next-1, datasource.maxIndex || Number.MIN_VALUE
549546
adjustBufferAfterFetch rid
550547
else
551548
if buffer.length && !viewport.shouldLoadTop()
@@ -565,6 +562,10 @@ angular.module('ui.scroll', [])
565562
--buffer.first
566563
buffer.insert 'prepend', result[i]
567564
#log 'prepended: requested ' + bufferSize + ' received ' + result.length + ' buffer size ' + buffer.length + ' first ' + first + ' next ' + next
565+
if buffer.bof
566+
datasource.minIndex = buffer.first
567+
else
568+
datasource.minIndex = Math.min buffer.first, datasource.minIndex || Number.MAX_VALUE
568569
adjustBufferAfterFetch rid
569570

570571

0 commit comments

Comments
 (0)