diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-16 13:19:28 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-16 15:23:12 +0200 |
commit | 8df6d36d49d89f3bb7186b36436606adb039b3f8 (patch) | |
tree | 2fbbe1e55995d0f9277557838a25f351e371540e /js/app | |
parent | efc118431b6afbb7cc1df887e11195d8c7e761a7 (diff) |
move instantiation into file where object is declared, fix unittests that overwrote services for all unittests and caused them to fail
Diffstat (limited to 'js/app')
-rw-r--r-- | js/app/directives/newsitemscroll.coffee (renamed from js/app/directives/scrollmarksread.coffee) | 6 | ||||
-rw-r--r-- | js/app/services/activefeed.coffee | 4 | ||||
-rw-r--r-- | js/app/services/businesslayer/itembusinesslayer.coffee | 2 | ||||
-rw-r--r-- | js/app/services/models/feedmodel.coffee | 10 | ||||
-rw-r--r-- | js/app/services/models/foldermodel.coffee | 4 | ||||
-rw-r--r-- | js/app/services/models/itemmodel.coffee | 4 | ||||
-rw-r--r-- | js/app/services/persistence.coffee | 139 | ||||
-rw-r--r-- | js/app/services/services.coffee | 43 | ||||
-rw-r--r-- | js/app/services/showall.coffee | 4 | ||||
-rw-r--r-- | js/app/services/starredcount.coffee | 5 |
10 files changed, 130 insertions, 91 deletions
diff --git a/js/app/directives/scrollmarksread.coffee b/js/app/directives/newsitemscroll.coffee index 854f17923..5e7e42a3e 100644 --- a/js/app/directives/scrollmarksread.coffee +++ b/js/app/directives/newsitemscroll.coffee @@ -23,7 +23,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. scrolling = true markingRead = true -angular.module('News').directive 'scrollMarksRead', ['$rootScope', 'Config', +angular.module('News').directive 'newsItemScroll', ['$rootScope', 'Config', ($rootScope, Config) -> return (scope, elm, attr) -> @@ -49,14 +49,14 @@ angular.module('News').directive 'scrollMarksRead', ['$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.scrollMarksRead + scope.$apply attr.newsItemScroll ] diff --git a/js/app/services/activefeed.coffee b/js/app/services/activefeed.coffee index 8af9f7573..bdd963f78 100644 --- a/js/app/services/activefeed.coffee +++ b/js/app/services/activefeed.coffee @@ -20,7 +20,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. ### -angular.module('News').factory '_ActiveFeed', -> +angular.module('News').factory 'ActiveFeed', -> class ActiveFeed @@ -45,4 +45,4 @@ angular.module('News').factory '_ActiveFeed', -> return @_id - return ActiveFeed + return new ActiveFeed() diff --git a/js/app/services/businesslayer/itembusinesslayer.coffee b/js/app/services/businesslayer/itembusinesslayer.coffee index 7f8d4fba6..b93f9035d 100644 --- a/js/app/services/businesslayer/itembusinesslayer.coffee +++ b/js/app/services/businesslayer/itembusinesslayer.coffee @@ -73,7 +73,7 @@ StarredBusinessLayer) -> item = @_itemModel.getById(itemId) if angular.isDefined(item) - keptUnread = angular.isDefined(item.keptUnread) and + keptUnread = angular.isDefined(item.keptUnread) and item.keptUnread if not (item.isRead() or keptUnread) diff --git a/js/app/services/models/feedmodel.coffee b/js/app/services/models/feedmodel.coffee index e0006e8d2..fb0ba8e14 100644 --- a/js/app/services/models/feedmodel.coffee +++ b/js/app/services/models/feedmodel.coffee @@ -20,10 +20,9 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. ### - -angular.module('News').factory '_FeedModel', -['_Model', '_EqualQuery', -(_Model, _EqualQuery) -> +angular.module('News').factory 'FeedModel', +['_Model', '_EqualQuery', 'Utils', +(_Model, _EqualQuery, Utils) -> class FeedModel extends _Model @@ -166,5 +165,6 @@ angular.module('News').factory '_FeedModel', @_invalidateCache() break - return FeedModel + + return new FeedModel(Utils) ]
\ No newline at end of file diff --git a/js/app/services/models/foldermodel.coffee b/js/app/services/models/foldermodel.coffee index 5dad0bdae..b724ad044 100644 --- a/js/app/services/models/foldermodel.coffee +++ b/js/app/services/models/foldermodel.coffee @@ -20,7 +20,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. ### -angular.module('News').factory '_FolderModel', +angular.module('News').factory 'FolderModel', ['_Model', '_EqualQuery', (_Model, _EqualQuery) -> class FolderModel extends _Model @@ -138,5 +138,5 @@ angular.module('News').factory '_FolderModel', break - return FolderModel + return new FolderModel() ]
\ No newline at end of file diff --git a/js/app/services/models/itemmodel.coffee b/js/app/services/models/itemmodel.coffee index 61030b50e..70b3a9f5c 100644 --- a/js/app/services/models/itemmodel.coffee +++ b/js/app/services/models/itemmodel.coffee @@ -20,7 +20,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. ### -angular.module('News').factory '_ItemModel', +angular.module('News').factory 'ItemModel', ['_Model', '_MaximumQuery', '_MinimumQuery', 'StatusFlag', (_Model, _MaximumQuery, _MinimumQuery, StatusFlag) -> @@ -109,5 +109,5 @@ angular.module('News').factory '_ItemModel', return 0 - return ItemModel + return new ItemModel() ]
\ No newline at end of file diff --git a/js/app/services/persistence.coffee b/js/app/services/persistence.coffee index 2b627301a..4c4ceb370 100644 --- a/js/app/services/persistence.coffee +++ b/js/app/services/persistence.coffee @@ -20,33 +20,31 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. ### +angular.module('News').factory 'Persistence', +['Request', 'FeedLoading', 'AutoPageLoading', 'NewLoading', 'Config', +'ActiveFeed', '$rootScope', +(Request, FeedLoading, AutoPageLoading, NewLoading, Config, ActiveFeed, +$rootScope) -> -angular.module('News').factory '_Persistence', -> - class Persistence - constructor: (@_request, @_loading, @_config, @_activeFeed, - @_$rootScope) -> + constructor: (@_request, @_feedLoading, @_autoPageLoading, @_newLoading, + @_config, @_activeFeed, @_$rootScope) -> init: -> ### Loads the initial data from the server ### - @_loading.increase() # items can only be loaded after the active feed is known @getActiveFeed => - @getItems @_activeFeed.getType(), @_activeFeed.getId(), 0, => - @_loading.decrease() + @getItems(@_activeFeed.getType(), @_activeFeed.getId()) - triggerHideRead = => - @_triggerHideRead - - @getAllFolders(triggerHideRead) - @getAllFeeds(triggerHideRead) - @userSettingsRead(triggerHideRead) - @getStarredItems(triggerHideRead) + @getAllFolders() + @getAllFeeds() + @userSettingsRead() + @getStarredItems() @userSettingsLanguage() @@ -54,9 +52,22 @@ angular.module('News').factory '_Persistence', -> ITEM CONTROLLER ### getItems: (type, id, offset, onSuccess=null, updatedSince=null) -> - onSuccess or= -> + # show different loading signs + if offset == 0 + loading = @_feedLoading + else + loading = @_autoPageLoading + + # loading sign handling + loading.increase() + successCallbackWrapper = (data) => + onSuccess() + loading.decrease() + failureCallbackWrapper = (data) => + loading.decrease() + if updatedSince != null data = updatedSince: updatedSince @@ -71,14 +82,27 @@ angular.module('News').factory '_Persistence', -> params = data: data - onSuccess: onSuccess + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper @_request.get 'news_items', params getStarredItems: (onSuccess) -> + onSuccess or= -> + + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + params = - onSuccess: onSuccess + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper + @_request.get 'news_items_starred', params @@ -132,17 +156,36 @@ angular.module('News').factory '_Persistence', -> ### FEED CONTROLLER ### - getAllFeeds: (callback) -> - callback or= -> + getAllFeeds: (onSuccess) -> + onSuccess or= -> + + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + params = - onSuccess: callback + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper @_request.get 'news_feeds', params getActiveFeed: (onSuccess) -> + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + params = - onSuccess: onSuccess + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper @_request.get 'news_feeds_active', params @@ -208,10 +251,20 @@ angular.module('News').factory '_Persistence', -> ### FOLDER CONTROLLER ### - getAllFolders: (callback) -> - callback or= -> + getAllFolders: (onSuccess) -> + onSuccess or= -> + + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + params = - onSuccess: callback + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper @_request.get 'news_folders', params @@ -292,13 +345,23 @@ angular.module('News').factory '_Persistence', -> ### USERSETTINGS CONTROLLER ### - userSettingsRead: (callback=null) -> + userSettingsRead: (onSuccess=null) -> ### Gets the configs for read settings ### - callback or= -> + onSuccess or= -> + + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + params = - onSuccess: callback + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper @_request.get 'news_usersettings_read', params @@ -321,10 +384,21 @@ angular.module('News').factory '_Persistence', -> @_request.post 'news_usersettings_read_hide', data - userSettingsLanguage: (callback=null) -> - callback or= -> + userSettingsLanguage: (onSuccess=null) -> + onSuccess or= -> + + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + data = - onSuccess: callback + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper + @_request.get 'news_usersettings_language', data @@ -332,5 +406,8 @@ angular.module('News').factory '_Persistence', -> @_$rootScope.$broadcast('triggerHideRead') - return Persistence + return new Persistence(Request, FeedLoading, AutoPageLoading, NewLoading, + Config, ActiveFeed, $rootScope) + +] diff --git a/js/app/services/services.coffee b/js/app/services/services.coffee index d67e1d2c5..537a4492c 100644 --- a/js/app/services/services.coffee +++ b/js/app/services/services.coffee @@ -22,12 +22,6 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. # request related stuff -angular.module('News').factory 'Persistence', ['_Persistence', 'Request', -'FeedLoading', 'Config', 'ActiveFeed', '$rootScope', -(_Persistence, Request, FeedLoading, Config, ActiveFeed, $rootScope) -> - return new _Persistence(Request, FeedLoading, Config, ActiveFeed, $rootScope) -] - angular.module('News').factory 'Request', ['_Request', '$http', 'Publisher', 'Router', (_Request, $http, Publisher, Router) -> @@ -36,49 +30,18 @@ angular.module('News').factory 'Request', # loading helpers -angular.module('News').factory 'FeedLoading', -['_Loading', (_Loading) -> +angular.module('News').factory 'FeedLoading', ['_Loading', (_Loading) -> return new _Loading() ] -angular.module('News').factory 'AutoPageLoading', -['_Loading', (_Loading) -> +angular.module('News').factory 'AutoPageLoading', ['_Loading', (_Loading) -> return new _Loading() ] -angular.module('News').factory 'NewLoading', -['_Loading', (_Loading) -> +angular.module('News').factory 'NewLoading', ['_Loading', (_Loading) -> return new _Loading() ] -# models -angular.module('News').factory 'ActiveFeed', ['_ActiveFeed', (_ActiveFeed) -> - return new _ActiveFeed() -] - -angular.module('News').factory 'ShowAll', ['_ShowAll', (_ShowAll) -> - return new _ShowAll() -] - -angular.module('News').factory 'StarredCount', ['_StarredCount', -(_StarredCount) -> - return new _StarredCount() -] - -angular.module('News').factory 'FeedModel', ['_FeedModel', 'Utils', -(_FeedModel, Utils) -> - return new _FeedModel(Utils) -] - -angular.module('News').factory 'FolderModel', -['_FolderModel', (_FolderModel) -> - return new _FolderModel() -] - -angular.module('News').factory 'ItemModel', ['_ItemModel', (_ItemModel) -> - return new _ItemModel() -] - angular.module('News').factory 'Publisher', ['_Publisher', 'ActiveFeed', 'ShowAll', 'StarredCount', 'ItemModel', diff --git a/js/app/services/showall.coffee b/js/app/services/showall.coffee index a40f176bc..1d12864c6 100644 --- a/js/app/services/showall.coffee +++ b/js/app/services/showall.coffee @@ -21,7 +21,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. ### -angular.module('News').factory '_ShowAll', -> +angular.module('News').factory 'ShowAll', -> class ShowAll @@ -41,4 +41,4 @@ angular.module('News').factory '_ShowAll', -> @_showAll = showAll - return ShowAll + return new ShowAll() diff --git a/js/app/services/starredcount.coffee b/js/app/services/starredcount.coffee index 9d3d9deb5..1157b4748 100644 --- a/js/app/services/starredcount.coffee +++ b/js/app/services/starredcount.coffee @@ -21,7 +21,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. ### -angular.module('News').factory '_StarredCount', -> +angular.module('News').factory 'StarredCount', -> class StarredCount @@ -41,5 +41,4 @@ angular.module('News').factory '_StarredCount', -> return @_count - - return StarredCount + return new StarredCount() |