diff options
Diffstat (limited to 'js/app')
-rw-r--r-- | js/app/app.coffee | 4 | ||||
-rw-r--r-- | js/app/controllers/itemcontroller.coffee | 10 | ||||
-rw-r--r-- | js/app/directives/newsitemscroll.coffee | 8 | ||||
-rw-r--r-- | js/app/services/businesslayer/itembusinesslayer.coffee | 7 | ||||
-rw-r--r-- | js/app/services/models/itemmodel.coffee | 11 |
5 files changed, 35 insertions, 5 deletions
diff --git a/js/app/app.coffee b/js/app/app.coffee index 2042a9ebf..264078b57 100644 --- a/js/app/app.coffee +++ b/js/app/app.coffee @@ -28,6 +28,10 @@ angular.module('News', ['OC', 'ui']).config ($provide) -> scrollTimeout: 500 feedUpdateInterval: 600000 itemBatchSize: 20 + # the autoPageFactor defines how many heights of the box must be left + # before it starts autopaging e.g. if it was 2, then it will start + # to fetch new items if less than the height*2 px is left to scroll + autoPageFactor: 6 angular.module('News').run ['Persistence', 'Config', 'FeedBusinessLayer', diff --git a/js/app/controllers/itemcontroller.coffee b/js/app/controllers/itemcontroller.coffee index 4fd00ec59..0d912b507 100644 --- a/js/app/controllers/itemcontroller.coffee +++ b/js/app/controllers/itemcontroller.coffee @@ -31,6 +31,8 @@ Language) -> constructor: (@_$scope, @_itemBusinessLayer, @_feedModel, @_feedLoading, @_feedBusinessLayer, @_language) -> + @_autoPaging = true + @_$scope.itemBusinessLayer = @_itemBusinessLayer @_$scope.feedBusinessLayer = @_feedBusinessLayer @@ -54,10 +56,14 @@ Language) -> @_$scope.$on 'readItem', (scope, data) => - console.log data @_itemBusinessLayer.setRead(data) - + @_$scope.$on 'autoPage', => + if @_autoPaging + # prevent multiple autopaging requests + @_autoPaging = false + @_itemBusinessLayer.loadNext => + @_autoPaging = true return new ItemController($scope, ItemBusinessLayer, FeedModel, FeedLoading, diff --git a/js/app/directives/newsitemscroll.coffee b/js/app/directives/newsitemscroll.coffee index 5e7e42a3e..619710bf3 100644 --- a/js/app/directives/newsitemscroll.coffee +++ b/js/app/directives/newsitemscroll.coffee @@ -49,14 +49,18 @@ angular.module('News').directive 'newsItemScroll', ['$rootScope', 'Config', offset = $(feedItem).position().top if offset <= -50 id = parseInt($(feedItem).data('id'), 10) - #$rootScope.$broadcast 'readItem', id + $rootScope.$broadcast 'readItem', id else break , Config.MarkReadTimeout - scope.$apply attr.newsItemScroll + # autopaging + tolerance = elm.height() * Config.autoPageFactor + remaining = elm[0].scrollHeight - elm.scrollTop() - tolerance + if remaining <= 0 + $rootScope.$broadcast 'autoPage' ] diff --git a/js/app/services/businesslayer/itembusinesslayer.coffee b/js/app/services/businesslayer/itembusinesslayer.coffee index b93f9035d..0b79cd638 100644 --- a/js/app/services/businesslayer/itembusinesslayer.coffee +++ b/js/app/services/businesslayer/itembusinesslayer.coffee @@ -105,7 +105,12 @@ StarredBusinessLayer) -> return feed.title - loadNext: -> + loadNext: (callback) -> + lowestItemId = @_itemModel.getLowestId() + if angular.isDefined(lowestItemId) + @_persistence.getItems @_activeFeed.getType(), + @_activeFeed.getId(), lowestItemId, + callback diff --git a/js/app/services/models/itemmodel.coffee b/js/app/services/models/itemmodel.coffee index 70b3a9f5c..1b03d65f8 100644 --- a/js/app/services/models/itemmodel.coffee +++ b/js/app/services/models/itemmodel.coffee @@ -109,5 +109,16 @@ angular.module('News').factory 'ItemModel', return 0 + getLowestId: -> + query = new _MinimumQuery('id') + lowestId = @get(query) + + if angular.isDefined(lowestId) + return lowestId.id + else + return 0 + + + return new ItemModel() ]
\ No newline at end of file |