diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/app/services/bl/feedbl.coffee | 30 | ||||
-rw-r--r-- | js/app/services/persistence.coffee | 12 | ||||
-rw-r--r-- | js/public/app.js | 39 | ||||
-rw-r--r-- | js/tests/services/bl/feedblSpec.coffee | 9 | ||||
-rw-r--r-- | js/tests/services/persistenceSpec.coffee | 15 |
5 files changed, 67 insertions, 38 deletions
diff --git a/js/app/services/bl/feedbl.coffee b/js/app/services/bl/feedbl.coffee index 088f2e623..77b3d81e2 100644 --- a/js/app/services/bl/feedbl.coffee +++ b/js/app/services/bl/feedbl.coffee @@ -23,13 +23,14 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. angular.module('News').factory 'FeedBl', ['_Bl', 'ShowAll', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', -'FeedModel', -(_Bl, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, FeedModel) -> +'FeedModel', 'NewLoading', +(_Bl, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, FeedModel, +NewLoading) -> class FeedBl extends _Bl constructor: (@_showAll, @_feedModel, persistence, activeFeed, feedType, - itemModel) -> + itemModel, @_newLoading) -> super(activeFeed, persistence, itemModel, feedType.Feed) @@ -92,15 +93,22 @@ angular.module('News').factory 'FeedBl', setShowAll: (showAll) -> @_showAll.setShowAll(showAll) - @_persistence.getItems( - @_activeFeed.getType(), - @_activeFeed.getId(), - 0 - ) + + # TODO: this callback is not tested with a unittest + callback = => + @_itemModel.clear() + @_newLoading.increase() + @_persistence.getItems( + @_activeFeed.getType(), + @_activeFeed.getId(), + 0, + => + @_newLoading.decrease() + ) if showAll - @_persistence.userSettingsReadShow() + @_persistence.userSettingsReadShow(callback) else - @_persistence.userSettingsReadHide() + @_persistence.userSettingsReadHide(callback) isShowAll: -> @@ -112,6 +120,6 @@ angular.module('News').factory 'FeedBl', return new FeedBl(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType, - ItemModel) + ItemModel, NewLoading) ]
\ No newline at end of file diff --git a/js/app/services/persistence.coffee b/js/app/services/persistence.coffee index 2231a5b79..7d0ecd5a0 100644 --- a/js/app/services/persistence.coffee +++ b/js/app/services/persistence.coffee @@ -302,18 +302,22 @@ angular.module('News').factory '_Persistence', -> @_request.get 'news_usersettings_read', params - userSettingsReadShow: -> + userSettingsReadShow: (callback) -> ### Sets the reader mode to show all ### - @_request.post 'news_usersettings_read_show' + data = + onSuccess: callback + @_request.post 'news_usersettings_read_show', data - userSettingsReadHide: -> + userSettingsReadHide: (callback) -> ### Sets the reader mode to show only unread ### - @_request.post 'news_usersettings_read_hide' + data = + onSuccess: callback + @_request.post 'news_usersettings_read_hide', data _triggerHideRead: -> diff --git a/js/public/app.js b/js/public/app.js index a70e513a4..e393af255 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -551,15 +551,16 @@ 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('FeedBl', [ - '_Bl', 'ShowAll', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', 'FeedModel', function(_Bl, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, FeedModel) { + '_Bl', 'ShowAll', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', 'FeedModel', 'NewLoading', function(_Bl, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, FeedModel, NewLoading) { var FeedBl; FeedBl = (function(_super) { __extends(FeedBl, _super); - function FeedBl(_showAll, _feedModel, persistence, activeFeed, feedType, itemModel) { + function FeedBl(_showAll, _feedModel, persistence, activeFeed, feedType, itemModel, _newLoading) { this._showAll = _showAll; this._feedModel = _feedModel; + this._newLoading = _newLoading; FeedBl.__super__.constructor.call(this, activeFeed, persistence, itemModel, feedType.Feed); } @@ -638,12 +639,20 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. }; FeedBl.prototype.setShowAll = function(showAll) { + var callback, + _this = this; this._showAll.setShowAll(showAll); - this._persistence.getItems(this._activeFeed.getType(), this._activeFeed.getId(), 0); + callback = function() { + _this._itemModel.clear(); + _this._newLoading.increase(); + return _this._persistence.getItems(_this._activeFeed.getType(), _this._activeFeed.getId(), 0, function() { + return _this._newLoading.decrease(); + }); + }; if (showAll) { - return this._persistence.userSettingsReadShow(); + return this._persistence.userSettingsReadShow(callback); } else { - return this._persistence.userSettingsReadHide(); + return this._persistence.userSettingsReadHide(callback); } }; @@ -658,7 +667,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. return FeedBl; })(_Bl); - return new FeedBl(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType, ItemModel); + return new FeedBl(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType, ItemModel, NewLoading); } ]); @@ -1932,18 +1941,28 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. return this._request.get('news_usersettings_read', params); }; - Persistence.prototype.userSettingsReadShow = function() { + Persistence.prototype.userSettingsReadShow = function(callback) { /* Sets the reader mode to show all */ - return this._request.post('news_usersettings_read_show'); + + var data; + data = { + onSuccess: callback + }; + return this._request.post('news_usersettings_read_show', data); }; - Persistence.prototype.userSettingsReadHide = function() { + Persistence.prototype.userSettingsReadHide = function(callback) { /* Sets the reader mode to show only unread */ - return this._request.post('news_usersettings_read_hide'); + + var data; + data = { + onSuccess: callback + }; + return this._request.post('news_usersettings_read_hide', data); }; Persistence.prototype._triggerHideRead = function() { diff --git a/js/tests/services/bl/feedblSpec.coffee b/js/tests/services/bl/feedblSpec.coffee index 798fd2e6f..70d0c6e8b 100644 --- a/js/tests/services/bl/feedblSpec.coffee +++ b/js/tests/services/bl/feedblSpec.coffee @@ -190,15 +190,6 @@ describe 'FeedBl', -> expect(@FeedBl.isShowAll()).toBe(true) - it 'should reload the active feed if showall changed', => - @persistence.userSettingsReadShow = jasmine.createSpy('Show All') - @persistence.userSettingsReadHide = jasmine.createSpy('Hide All') - - @FeedBl.setShowAll(true) - - expect(@getItemsSpy).toHaveBeenCalledWith(@FeedType.Folder, 0, 0) - - it 'should return all feeds of a folder', => item1 = {id: 2, unreadCount:134, urlHash: 'a1', folderId: 3} item2 = {id: 4, unreadCount:134, urlHash: 'a2', folderId: 2} diff --git a/js/tests/services/persistenceSpec.coffee b/js/tests/services/persistenceSpec.coffee index dc36661a4..2934fdfb5 100644 --- a/js/tests/services/persistenceSpec.coffee +++ b/js/tests/services/persistenceSpec.coffee @@ -345,14 +345,21 @@ describe '_Persistence', -> it 'should do a proper user settings read show request', => pers = new @_Persistence(@req, @loading, @config, @active, @$rootScope) - pers.userSettingsReadShow() + params = + onSuccess: -> + + pers.userSettingsReadShow(params.onSuccess) - expect(@req.post).toHaveBeenCalledWith('news_usersettings_read_show') + expect(@req.post).toHaveBeenCalledWith('news_usersettings_read_show', + params) it 'should do a proper user settings read hide request', => pers = new @_Persistence(@req, @loading, @config, @active, @$rootScope) - pers.userSettingsReadHide() + params = + onSuccess: -> + pers.userSettingsReadHide(params.onSuccess) - expect(@req.post).toHaveBeenCalledWith('news_usersettings_read_hide')
\ No newline at end of file + expect(@req.post).toHaveBeenCalledWith('news_usersettings_read_hide', + params)
\ No newline at end of file |