summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-09-14 02:44:32 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-09-14 02:44:32 +0200
commitbfa090ed5d6fd8fa22487d239d3bb1e0b5e60f69 (patch)
tree9cc16eb2573fa7a8ff552230b2b9a612720c5474
parentdf8f6b5fee643c5b2af8e8d33a7865e898518485 (diff)
dont do pull to refresh when loading in items
-rw-r--r--js/app/directives/pulltorefresh.coffee16
-rw-r--r--js/app/services/businesslayer/businesslayer.coffee7
-rw-r--r--js/app/services/businesslayer/feedbusinesslayer.coffee4
-rw-r--r--js/app/services/businesslayer/folderbusinesslayer.coffee4
-rw-r--r--js/app/services/businesslayer/starredbusinesslayer.coffee11
-rw-r--r--js/app/services/businesslayer/subscriptionsbusinesslayer.coffee12
-rw-r--r--js/public/app.js74
-rw-r--r--js/tests/controllers/feedcontrollerSpec.coffee2
-rw-r--r--js/tests/services/businesslayer/businesslayerSpec.coffee13
9 files changed, 87 insertions, 56 deletions
diff --git a/js/app/directives/pulltorefresh.coffee b/js/app/directives/pulltorefresh.coffee
index 436280793..00f3bcae5 100644
--- a/js/app/directives/pulltorefresh.coffee
+++ b/js/app/directives/pulltorefresh.coffee
@@ -20,11 +20,21 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
###
-angular.module('News').directive 'newsPullToRefresh', ->
+angular.module('News').directive 'newsPullToRefresh', ['$rootScope',
+($rootScope) ->
+
+ allowed = false
+ $rootScope.$on 'loadingNewItems', ->
+ allowed = false
+ $rootScope.$on 'loadedNewItems', ->
+ allowed = true
+
+
directive =
restrict: 'A'
link: (scope, elm, attrs) ->
scrollTop = 0
elm.scroll ->
- if @scrollTop == 0
- scope.$apply attrs.newsPullToRefresh \ No newline at end of file
+ if @scrollTop == 0 && allowed
+ scope.$apply attrs.newsPullToRefresh
+] \ No newline at end of file
diff --git a/js/app/services/businesslayer/businesslayer.coffee b/js/app/services/businesslayer/businesslayer.coffee
index fdf74817d..14d692084 100644
--- a/js/app/services/businesslayer/businesslayer.coffee
+++ b/js/app/services/businesslayer/businesslayer.coffee
@@ -25,12 +25,15 @@ angular.module('News').factory '_BusinessLayer', ->
class BusinessLayer
- constructor: (@_activeFeed, @_persistence, @_itemModel, @_type) ->
+ constructor: (@_activeFeed, @_persistence, @_itemModel, @_type,
+ @_$rootScope) ->
load: (id) ->
+ @_$rootScope.$broadcast 'loadingNewItems'
@_itemModel.clear()
- @_persistence.getItems(@_type, id, 0)
+ @_persistence.getItems @_type, id, 0, =>
+ @_$rootScope.$broadcast 'loadedNewItems'
@_activeFeed.handle({id: id, type: @_type})
diff --git a/js/app/services/businesslayer/feedbusinesslayer.coffee b/js/app/services/businesslayer/feedbusinesslayer.coffee
index 9b5f08a1c..fd92209ab 100644
--- a/js/app/services/businesslayer/feedbusinesslayer.coffee
+++ b/js/app/services/businesslayer/feedbusinesslayer.coffee
@@ -31,9 +31,9 @@ FeedModel, NewLoading, _ExistsError, Utils, $rootScope, NewestItem)->
class FeedBusinessLayer extends _BusinessLayer
constructor: (@_showAll, @_feedModel, persistence, activeFeed, feedType,
- itemModel, @_newLoading, @_utils, @_$rootScope,
+ itemModel, @_newLoading, @_utils, $rootScope,
@_newestItem) ->
- super(activeFeed, persistence, itemModel, feedType.Feed)
+ super(activeFeed, persistence, itemModel, feedType.Feed, $rootScope)
@_feedType = feedType
diff --git a/js/app/services/businesslayer/folderbusinesslayer.coffee b/js/app/services/businesslayer/folderbusinesslayer.coffee
index e6e582d6b..6c5457e91 100644
--- a/js/app/services/businesslayer/folderbusinesslayer.coffee
+++ b/js/app/services/businesslayer/folderbusinesslayer.coffee
@@ -33,8 +33,8 @@ FeedModel, $rootScope) ->
constructor: (@_folderModel, @_feedBusinessLayer, @_showAll, activeFeed,
persistence, @_feedType, itemModel, @_opmlParser,
- @_newestItem, @_feedModel, @_$rootScope) ->
- super(activeFeed, persistence, itemModel, @_feedType.Folder)
+ @_newestItem, @_feedModel, $rootScope) ->
+ super(activeFeed, persistence, itemModel, @_feedType.Folder, $rootScope)
getById: (folderId) ->
diff --git a/js/app/services/businesslayer/starredbusinesslayer.coffee b/js/app/services/businesslayer/starredbusinesslayer.coffee
index 38e7a2437..50ef0f37f 100644
--- a/js/app/services/businesslayer/starredbusinesslayer.coffee
+++ b/js/app/services/businesslayer/starredbusinesslayer.coffee
@@ -23,14 +23,15 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
angular.module('News').factory 'StarredBusinessLayer',
['_BusinessLayer', 'StarredCount', 'Persistence', 'ActiveFeed', 'FeedType',
-'ItemModel',
-(_BusinessLayer, StarredCount, Persistence, ActiveFeed, FeedType, ItemModel) ->
+'ItemModel', '$rootScope',
+(_BusinessLayer, StarredCount, Persistence, ActiveFeed, FeedType, ItemModel,
+$rootScope) ->
class StarredBusinessLayer extends _BusinessLayer
constructor: (@_starredCount, feedType,
- persistence, activeFeed, itemModel) ->
- super(activeFeed, persistence, itemModel, feedType.Starred)
+ persistence, activeFeed, itemModel, $rootScope) ->
+ super(activeFeed, persistence, itemModel, feedType.Starred, $rootScope)
isVisible: ->
if @isActive(0)
@@ -51,5 +52,5 @@ angular.module('News').factory 'StarredBusinessLayer',
@_starredCount.setStarredCount(@_starredCount.getStarredCount() - 1)
return new StarredBusinessLayer(StarredCount, FeedType, Persistence,
- ActiveFeed, ItemModel)
+ ActiveFeed, ItemModel, $rootScope)
]
diff --git a/js/app/services/businesslayer/subscriptionsbusinesslayer.coffee b/js/app/services/businesslayer/subscriptionsbusinesslayer.coffee
index d0f9b33ab..0851e18a4 100644
--- a/js/app/services/businesslayer/subscriptionsbusinesslayer.coffee
+++ b/js/app/services/businesslayer/subscriptionsbusinesslayer.coffee
@@ -23,15 +23,17 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
angular.module('News').factory 'SubscriptionsBusinessLayer',
['_BusinessLayer', 'FeedBusinessLayer', 'Persistence', 'ShowAll', 'ActiveFeed',
-'FeedType', 'ItemModel', 'FeedModel', 'NewestItem',
+'FeedType', 'ItemModel', 'FeedModel', 'NewestItem', '$rootScope',
(_BusinessLayer, FeedBusinessLayer, Persistence, ShowAll, ActiveFeed, FeedType,
-ItemModel, FeedModel, NewestItem) ->
+ItemModel, FeedModel, NewestItem, $rootScope) ->
class SubscriptionsBusinessLayer extends _BusinessLayer
constructor: (@_feedBusinessLayer, @_showAll, feedType,
- persistence, activeFeed, itemModel, @_feedModel, @_newestItem) ->
- super(activeFeed, persistence, itemModel, feedType.Subscriptions)
+ persistence, activeFeed, itemModel, @_feedModel, @_newestItem,
+ $rootScope) ->
+ super(activeFeed, persistence, itemModel, feedType.Subscriptions,
+ $rootScope)
isVisible: ->
if @isActive(0) and @_feedBusinessLayer.getNumberOfFeeds() > 0
@@ -62,5 +64,5 @@ ItemModel, FeedModel, NewestItem) ->
return new SubscriptionsBusinessLayer(FeedBusinessLayer, ShowAll, FeedType,
Persistence, ActiveFeed, ItemModel,
- FeedModel, NewestItem)
+ FeedModel, NewestItem, $rootScope)
]
diff --git a/js/public/app.js b/js/public/app.js
index ab237c645..886436f9a 100644
--- a/js/public/app.js
+++ b/js/public/app.js
@@ -452,21 +452,30 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
(function() {
- angular.module('News').directive('newsPullToRefresh', function() {
- var directive;
- return directive = {
- restrict: 'A',
- link: function(scope, elm, attrs) {
- var scrollTop;
- scrollTop = 0;
- return elm.scroll(function() {
- if (this.scrollTop === 0) {
- return scope.$apply(attrs.newsPullToRefresh);
- }
- });
- }
- };
- });
+ angular.module('News').directive('newsPullToRefresh', [
+ '$rootScope', function($rootScope) {
+ var allowed, directive;
+ allowed = false;
+ $rootScope.$on('loadingNewItems', function() {
+ return allowed = false;
+ });
+ $rootScope.$on('loadedNewItems', function() {
+ return allowed = true;
+ });
+ return directive = {
+ restrict: 'A',
+ link: function(scope, elm, attrs) {
+ var scrollTop;
+ scrollTop = 0;
+ return elm.scroll(function() {
+ if (this.scrollTop === 0 && allowed) {
+ return scope.$apply(attrs.newsPullToRefresh);
+ }
+ });
+ }
+ };
+ }
+ ]);
}).call(this);
@@ -948,16 +957,21 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
angular.module('News').factory('_BusinessLayer', function() {
var BusinessLayer;
BusinessLayer = (function() {
- function BusinessLayer(_activeFeed, _persistence, _itemModel, _type) {
+ function BusinessLayer(_activeFeed, _persistence, _itemModel, _type, _$rootScope) {
this._activeFeed = _activeFeed;
this._persistence = _persistence;
this._itemModel = _itemModel;
this._type = _type;
+ this._$rootScope = _$rootScope;
}
BusinessLayer.prototype.load = function(id) {
+ var _this = this;
+ this._$rootScope.$broadcast('loadingNewItems');
this._itemModel.clear();
- this._persistence.getItems(this._type, id, 0);
+ this._persistence.getItems(this._type, id, 0, function() {
+ return _this._$rootScope.$broadcast('loadedNewItems');
+ });
return this._activeFeed.handle({
id: id,
type: this._type
@@ -1009,14 +1023,13 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
FeedBusinessLayer = (function(_super) {
__extends(FeedBusinessLayer, _super);
- function FeedBusinessLayer(_showAll, _feedModel, persistence, activeFeed, feedType, itemModel, _newLoading, _utils, _$rootScope, _newestItem) {
+ function FeedBusinessLayer(_showAll, _feedModel, persistence, activeFeed, feedType, itemModel, _newLoading, _utils, $rootScope, _newestItem) {
this._showAll = _showAll;
this._feedModel = _feedModel;
this._newLoading = _newLoading;
this._utils = _utils;
- this._$rootScope = _$rootScope;
this._newestItem = _newestItem;
- FeedBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, feedType.Feed);
+ FeedBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, feedType.Feed, $rootScope);
this._feedType = feedType;
}
@@ -1230,7 +1243,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
FolderBusinessLayer = (function(_super) {
__extends(FolderBusinessLayer, _super);
- function FolderBusinessLayer(_folderModel, _feedBusinessLayer, _showAll, activeFeed, persistence, _feedType, itemModel, _opmlParser, _newestItem, _feedModel, _$rootScope) {
+ function FolderBusinessLayer(_folderModel, _feedBusinessLayer, _showAll, activeFeed, persistence, _feedType, itemModel, _opmlParser, _newestItem, _feedModel, $rootScope) {
this._folderModel = _folderModel;
this._feedBusinessLayer = _feedBusinessLayer;
this._showAll = _showAll;
@@ -1238,8 +1251,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
this._opmlParser = _opmlParser;
this._newestItem = _newestItem;
this._feedModel = _feedModel;
- this._$rootScope = _$rootScope;
- FolderBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, this._feedType.Folder);
+ FolderBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, this._feedType.Folder, $rootScope);
}
FolderBusinessLayer.prototype.getById = function(folderId) {
@@ -1616,14 +1628,14 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
angular.module('News').factory('StarredBusinessLayer', [
- '_BusinessLayer', 'StarredCount', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', function(_BusinessLayer, StarredCount, Persistence, ActiveFeed, FeedType, ItemModel) {
+ '_BusinessLayer', 'StarredCount', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', '$rootScope', function(_BusinessLayer, StarredCount, Persistence, ActiveFeed, FeedType, ItemModel, $rootScope) {
var StarredBusinessLayer;
StarredBusinessLayer = (function(_super) {
__extends(StarredBusinessLayer, _super);
- function StarredBusinessLayer(_starredCount, feedType, persistence, activeFeed, itemModel) {
+ function StarredBusinessLayer(_starredCount, feedType, persistence, activeFeed, itemModel, $rootScope) {
this._starredCount = _starredCount;
- StarredBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, feedType.Starred);
+ StarredBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, feedType.Starred, $rootScope);
}
StarredBusinessLayer.prototype.isVisible = function() {
@@ -1649,7 +1661,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
return StarredBusinessLayer;
})(_BusinessLayer);
- return new StarredBusinessLayer(StarredCount, FeedType, Persistence, ActiveFeed, ItemModel);
+ return new StarredBusinessLayer(StarredCount, FeedType, Persistence, ActiveFeed, ItemModel, $rootScope);
}
]);
@@ -1683,17 +1695,17 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
angular.module('News').factory('SubscriptionsBusinessLayer', [
- '_BusinessLayer', 'FeedBusinessLayer', 'Persistence', 'ShowAll', 'ActiveFeed', 'FeedType', 'ItemModel', 'FeedModel', 'NewestItem', function(_BusinessLayer, FeedBusinessLayer, Persistence, ShowAll, ActiveFeed, FeedType, ItemModel, FeedModel, NewestItem) {
+ '_BusinessLayer', 'FeedBusinessLayer', 'Persistence', 'ShowAll', 'ActiveFeed', 'FeedType', 'ItemModel', 'FeedModel', 'NewestItem', '$rootScope', function(_BusinessLayer, FeedBusinessLayer, Persistence, ShowAll, ActiveFeed, FeedType, ItemModel, FeedModel, NewestItem, $rootScope) {
var SubscriptionsBusinessLayer;
SubscriptionsBusinessLayer = (function(_super) {
__extends(SubscriptionsBusinessLayer, _super);
- function SubscriptionsBusinessLayer(_feedBusinessLayer, _showAll, feedType, persistence, activeFeed, itemModel, _feedModel, _newestItem) {
+ function SubscriptionsBusinessLayer(_feedBusinessLayer, _showAll, feedType, persistence, activeFeed, itemModel, _feedModel, _newestItem, $rootScope) {
this._feedBusinessLayer = _feedBusinessLayer;
this._showAll = _showAll;
this._feedModel = _feedModel;
this._newestItem = _newestItem;
- SubscriptionsBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, feedType.Subscriptions);
+ SubscriptionsBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, feedType.Subscriptions, $rootScope);
}
SubscriptionsBusinessLayer.prototype.isVisible = function() {
@@ -1734,7 +1746,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
return SubscriptionsBusinessLayer;
})(_BusinessLayer);
- return new SubscriptionsBusinessLayer(FeedBusinessLayer, ShowAll, FeedType, Persistence, ActiveFeed, ItemModel, FeedModel, NewestItem);
+ return new SubscriptionsBusinessLayer(FeedBusinessLayer, ShowAll, FeedType, Persistence, ActiveFeed, ItemModel, FeedModel, NewestItem, $rootScope);
}
]);
diff --git a/js/tests/controllers/feedcontrollerSpec.coffee b/js/tests/controllers/feedcontrollerSpec.coffee
index 01170509d..2d51000ea 100644
--- a/js/tests/controllers/feedcontrollerSpec.coffee
+++ b/js/tests/controllers/feedcontrollerSpec.coffee
@@ -211,5 +211,5 @@ describe 'FeedController', ->
expect(@scope.feedUrl).toBe('')
expect(@scope.isAddingFeed()).toBe(false)
expect(@persistence.getItems).toHaveBeenCalledWith(
- @FeedType.Feed, 3, 0
+ @FeedType.Feed, 3, 0, jasmine.any(Function)
) \ No newline at end of file
diff --git a/js/tests/services/businesslayer/businesslayerSpec.coffee b/js/tests/services/businesslayer/businesslayerSpec.coffee
index 433201b25..48be7f0c0 100644
--- a/js/tests/services/businesslayer/businesslayerSpec.coffee
+++ b/js/tests/services/businesslayer/businesslayerSpec.coffee
@@ -25,7 +25,10 @@ describe 'BusinessLayer', ->
beforeEach module 'News'
- beforeEach inject (@_BusinessLayer, @ActiveFeed, @FeedType, @ItemModel) =>
+ beforeEach inject (@_BusinessLayer, @ActiveFeed, @FeedType, @ItemModel,
+ $rootScope) =>
+ @scope = $rootScope.$new()
+
type = @FeedType.Starred
@getItemsSpy = jasmine.createSpy('getItems')
@@ -35,11 +38,11 @@ describe 'BusinessLayer', ->
class TestBusinessLayer extends @_BusinessLayer
- constructor: (activeFeed, persistence, itemModel) ->
- super(activeFeed, persistence, itemModel, type)
+ constructor: (activeFeed, persistence, itemModel, scope) ->
+ super(activeFeed, persistence, itemModel, type, scope)
@BusinessLayer = new TestBusinessLayer(@ActiveFeed, @persistence,
- @ItemModel)
+ @ItemModel, @scope)
it 'should reset the item cache when a different feed is being loaded', =>
@@ -61,7 +64,7 @@ describe 'BusinessLayer', ->
@BusinessLayer.load(3)
expect(@persistence.getItems).toHaveBeenCalledWith(@FeedType.Starred, 3,
- 0)
+ 0, jasmine.any(Function))
it 'should be active when its selected', =>