diff options
-rw-r--r-- | js/app/controllers/controllers.coffee | 14 | ||||
-rw-r--r-- | js/app/controllers/feedcontroller.coffee | 98 | ||||
-rw-r--r-- | js/app/services/bl/feedbl.coffee | 12 | ||||
-rw-r--r-- | js/app/services/bl/folderbl.coffee | 6 | ||||
-rw-r--r-- | js/app/services/unreadcountformatter.coffee | 28 | ||||
-rw-r--r-- | js/public/app.js | 149 | ||||
-rw-r--r-- | js/tests/controllers/feedcontrollerSpec.coffee | 125 | ||||
-rw-r--r-- | js/tests/services/bl/feedblSpec.coffee | 28 | ||||
-rw-r--r-- | js/tests/services/bl/folderblSpec.coffee | 12 | ||||
-rw-r--r-- | js/tests/services/unreadcountformaterSpec.coffee | 35 |
10 files changed, 206 insertions, 301 deletions
diff --git a/js/app/controllers/controllers.coffee b/js/app/controllers/controllers.coffee index a7d86b074..6598ac692 100644 --- a/js/app/controllers/controllers.coffee +++ b/js/app/controllers/controllers.coffee @@ -29,14 +29,12 @@ angular.module('News').controller 'SettingsController', angular.module('News').controller 'FeedController', -['$scope', '_FeedController', 'FolderModel', 'FeedModel', 'ActiveFeed', -'ShowAll', 'FeedType', 'StarredCount', 'Persistence', 'FolderBl', 'FeedBl', -($scope, _FeedController, FolderModel, FeedModel, ActiveFeed, -ShowAll, FeedType, StarredCount, Persistence, FolderBl, FeedBl)-> - - return new _FeedController($scope, FolderModel, FeedModel, ActiveFeed, - ShowAll, FeedType, StarredCount, Persistence, - FolderBl, FeedBl) +['$scope', '_FeedController', 'Persistence', 'FolderBl', 'FeedBl', +'unreadCountFormatter', +($scope, _FeedController, Persistence, FolderBl, FeedBl, unreadCountFormatter)-> + + return new _FeedController($scope, Persistence, FolderBl, FeedBl, + unreadCountFormatter) ] angular.module('News').controller 'ItemController', diff --git a/js/app/controllers/feedcontroller.coffee b/js/app/controllers/feedcontroller.coffee index 1b6a79c53..1438b4fbb 100644 --- a/js/app/controllers/feedcontroller.coffee +++ b/js/app/controllers/feedcontroller.coffee @@ -25,66 +25,24 @@ angular.module('News').factory '_FeedController', -> class FeedController - constructor: (@$scope, @_folderModel, @_feedModel, @_active, - @_showAll, @_feedType, @_starredCount, @_persistence, - @_folderBl, @_feedBl) -> + constructor: (@$scope, @_persistence, @_folderBl, @_feedBl, + @_unreadCountFormatter) -> @_isAddingFolder = false @_isAddingFeed = false # bind internal stuff to scope - @$scope.feeds = @_feedModel.getAll() - @$scope.folders = @_folderModel.getAll() - @$scope.feedType = @_feedType @$scope.folderBl = @_folderBl @$scope.feedBl = @_feedBl + @$scope.unreadCountFormatter = @_unreadCountFormatter - @$scope.isShown = (type, id) => - return true - - @$scope.getUnreadCount = => - return @_transFormCount(@_feedBl.getUnreadCount()) - - @$scope.getStarredCount = => - return @_transFormCount(@_starredCount.getStarredCount()) - - @$scope.getFeedUnreadCount = (feedId) => - return @_transFormCount(@_feedBl.getFeedUnreadCount(feedId)) - - @$scope.getUnreadCount = (folderId) => - return @_transFormCount(@_feedBl.getFolderUnreadCount(folderId)) - - @$scope.isShowAll = => - return @isShowAll() - - @$scope.loadFeed = (type, id) => - @loadFeed(type, id) - - @$scope.hasFeeds = (folderId) => - return @hasFeeds(folderId) - - @$scope.delete = (type, id) => - @delete(type, id) - - @$scope.markAllRead = (type, id) => - @markAllRead(type, id) - - @$scope.getFeedsOfFolder = (folderId) => - return @getFeedsOfFolder(folderId) - - @$scope.setShowAll = (showAll) => - @setShowAll(showAll) - @$scope.isAddingFolder = => return @_isAddingFolder @$scope.isAddingFeed = => return @_isAddingFeed - @$scope.toggleFolder = (folderId) => - @toggleFolder(folderId) - @$scope.addFeed = (feedUrl, parentFolderId=0) => @$scope.feedEmptyError = false @$scope.feedError = false @@ -129,54 +87,4 @@ angular.module('News').factory '_FeedController', -> @_isAddingFolder = false - isFeedActive: (type, id) -> - return type == @_active.getType() and id == @_active.getId() - - - #isShown: (type, id) -> - # hasUnread = @getUnreadCount(type, id) > 0 - # if hasUnread - # return true - # else - # if @isShowAll() - # switch type - # when @_feedType.Subscriptions - # return @_feedModel.size() > 0 - # when @_feedType.Folder - # return @_folderModel.size() > 0 - # when @_feedType.Feed - # return @_feedModel.size() > 0 - # return false - - - isShowAll: -> - return @_showAll.getShowAll() - - - _transFormCount: (count) -> - if count > 999 - count = '999+' - - return count - - - loadFeed: (type, id) -> - # TODO: use polymorphism instead of switches - if type != @_active.getType() or id != @_active.getId() - @_itemModel.clear() - @_persistence.getItems(type, id, 0) - @_active.handle({id: id, type: type}) - else - lastModified = @_itemModel.getHighestId() - @_persistence.getItems(type, id, 0, null, lastModified) - - - setShowAll: (showAll) -> - @_showAll.setShowAll(showAll) - if showAll - @_persistence.userSettingsReadShow() - else - @_persistence.userSettingsReadHide() - - return FeedController
\ No newline at end of file diff --git a/js/app/services/bl/feedbl.coffee b/js/app/services/bl/feedbl.coffee index fa324f20f..ad51fa339 100644 --- a/js/app/services/bl/feedbl.coffee +++ b/js/app/services/bl/feedbl.coffee @@ -90,6 +90,18 @@ angular.module('News').factory 'FeedBl', @_persistence.moveFeed(feedId, folderId) + setShowAll: (showAll) -> + @_showAll.setShowAll(showAll) + if showAll + @_persistence.userSettingsReadShow() + else + @_persistence.userSettingsReadHide() + + + getAll: -> + return @_feedModel.getAll() + + return new FeedBl(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType, ItemModel) diff --git a/js/app/services/bl/folderbl.coffee b/js/app/services/bl/folderbl.coffee index 16e020063..d9b2b2cff 100644 --- a/js/app/services/bl/folderbl.coffee +++ b/js/app/services/bl/folderbl.coffee @@ -61,7 +61,7 @@ ItemModel, ShowAll)-> getUnreadCount: (folderId) -> return @_feedBl.getFolderUnreadCount(folderId) - + isVisible: (folderId) -> if @_showAll.getShowAll() @@ -77,6 +77,10 @@ ItemModel, ShowAll)-> return false + getAll: -> + return @_folderModel.getAll() + + return new FolderBl(FolderModel, FeedBl, ShowAll, ActiveFeed, Persistence, FeedType, ItemModel) diff --git a/js/app/services/unreadcountformatter.coffee b/js/app/services/unreadcountformatter.coffee new file mode 100644 index 000000000..76993ef5c --- /dev/null +++ b/js/app/services/unreadcountformatter.coffee @@ -0,0 +1,28 @@ +### + +ownCloud - News + +@author Bernhard Posselt +@copyright 2012 Bernhard Posselt nukeawhale@gmail.com + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +License as published by the Free Software Foundation; either +version 3 of the License, or any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU AFFERO GENERAL PUBLIC LICENSE for more details. + +You should have received a copy of the GNU Affero General Public +License along with this library. If not, see <http://www.gnu.org/licenses/>. + +### + + +angular.module('News').factory 'unreadCountFormatter', -> + return (unreadCount) -> + if unreadCount > 999 + unreadCount = '999+' + return unreadCount
\ No newline at end of file diff --git a/js/public/app.js b/js/public/app.js index bdb196fbf..20d687649 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -171,8 +171,8 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. ]); angular.module('News').controller('FeedController', [ - '$scope', '_FeedController', 'FolderModel', 'FeedModel', 'ActiveFeed', 'ShowAll', 'FeedType', 'StarredCount', 'Persistence', 'FolderBl', 'FeedBl', function($scope, _FeedController, FolderModel, FeedModel, ActiveFeed, ShowAll, FeedType, StarredCount, Persistence, FolderBl, FeedBl) { - return new _FeedController($scope, FolderModel, FeedModel, ActiveFeed, ShowAll, FeedType, StarredCount, Persistence, FolderBl, FeedBl); + '$scope', '_FeedController', 'Persistence', 'FolderBl', 'FeedBl', 'unreadCountFormatter', function($scope, _FeedController, Persistence, FolderBl, FeedBl, unreadCountFormatter) { + return new _FeedController($scope, Persistence, FolderBl, FeedBl, unreadCountFormatter); } ]); @@ -214,70 +214,24 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. var FeedController; FeedController = (function() { - function FeedController($scope, _folderModel, _feedModel, _active, _showAll, _feedType, _starredCount, _persistence, _folderBl, _feedBl) { + function FeedController($scope, _persistence, _folderBl, _feedBl, _unreadCountFormatter) { var _this = this; this.$scope = $scope; - this._folderModel = _folderModel; - this._feedModel = _feedModel; - this._active = _active; - this._showAll = _showAll; - this._feedType = _feedType; - this._starredCount = _starredCount; this._persistence = _persistence; this._folderBl = _folderBl; this._feedBl = _feedBl; + this._unreadCountFormatter = _unreadCountFormatter; this._isAddingFolder = false; this._isAddingFeed = false; - this.$scope.feeds = this._feedModel.getAll(); - this.$scope.folders = this._folderModel.getAll(); - this.$scope.feedType = this._feedType; this.$scope.folderBl = this._folderBl; this.$scope.feedBl = this._feedBl; - this.$scope.isShown = function(type, id) { - return true; - }; - this.$scope.getUnreadCount = function() { - return _this._transFormCount(_this._feedBl.getUnreadCount()); - }; - this.$scope.getStarredCount = function() { - return _this._transFormCount(_this._starredCount.getStarredCount()); - }; - this.$scope.getFeedUnreadCount = function(feedId) { - return _this._transFormCount(_this._feedBl.getFeedUnreadCount(feedId)); - }; - this.$scope.getUnreadCount = function(folderId) { - return _this._transFormCount(_this._feedBl.getFolderUnreadCount(folderId)); - }; - this.$scope.isShowAll = function() { - return _this.isShowAll(); - }; - this.$scope.loadFeed = function(type, id) { - return _this.loadFeed(type, id); - }; - this.$scope.hasFeeds = function(folderId) { - return _this.hasFeeds(folderId); - }; - this.$scope["delete"] = function(type, id) { - return _this["delete"](type, id); - }; - this.$scope.markAllRead = function(type, id) { - return _this.markAllRead(type, id); - }; - this.$scope.getFeedsOfFolder = function(folderId) { - return _this.getFeedsOfFolder(folderId); - }; - this.$scope.setShowAll = function(showAll) { - return _this.setShowAll(showAll); - }; + this.$scope.unreadCountFormatter = this._unreadCountFormatter; this.$scope.isAddingFolder = function() { return _this._isAddingFolder; }; this.$scope.isAddingFeed = function() { return _this._isAddingFeed; }; - this.$scope.toggleFolder = function(folderId) { - return _this.toggleFolder(folderId); - }; this.$scope.addFeed = function(feedUrl, parentFolderId) { var onError, onSuccess; if (parentFolderId == null) { @@ -327,45 +281,6 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. }; } - FeedController.prototype.isFeedActive = function(type, id) { - return type === this._active.getType() && id === this._active.getId(); - }; - - FeedController.prototype.isShowAll = function() { - return this._showAll.getShowAll(); - }; - - FeedController.prototype._transFormCount = function(count) { - if (count > 999) { - count = '999+'; - } - return count; - }; - - FeedController.prototype.loadFeed = function(type, id) { - var lastModified; - if (type !== this._active.getType() || id !== this._active.getId()) { - this._itemModel.clear(); - this._persistence.getItems(type, id, 0); - return this._active.handle({ - id: id, - type: type - }); - } else { - lastModified = this._itemModel.getHighestId(); - return this._persistence.getItems(type, id, 0, null, lastModified); - } - }; - - FeedController.prototype.setShowAll = function(showAll) { - this._showAll.setShowAll(showAll); - if (showAll) { - return this._persistence.userSettingsReadShow(); - } else { - return this._persistence.userSettingsReadHide(); - } - }; - return FeedController; })(); @@ -718,6 +633,19 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. } }; + FeedBl.prototype.setShowAll = function(showAll) { + this._showAll.setShowAll(showAll); + if (showAll) { + return this._persistence.userSettingsReadShow(); + } else { + return this._persistence.userSettingsReadHide(); + } + }; + + FeedBl.prototype.getAll = function() { + return this._feedModel.getAll(); + }; + return FeedBl; })(_Bl); @@ -828,6 +756,10 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. } }; + FolderBl.prototype.getAll = function() { + return this._folderModel.getAll(); + }; + return FolderBl; })(_Bl); @@ -2177,4 +2109,41 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. }).call(this); +// Generated by CoffeeScript 1.4.0 + +/* + +ownCloud - News + +@author Bernhard Posselt +@copyright 2012 Bernhard Posselt nukeawhale@gmail.com + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +License as published by the Free Software Foundation; either +version 3 of the License, or any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU AFFERO GENERAL PUBLIC LICENSE for more details. + +You should have received a copy of the GNU Affero General Public +License along with this library. If not, see <http://www.gnu.org/licenses/>. +*/ + + +(function() { + + angular.module('News').factory('unreadCountFormatter', function() { + return function(unreadCount) { + if (unreadCount > 999) { + unreadCount = '999+'; + } + return unreadCount; + }; + }); + +}).call(this); + })(window.angular, jQuery);
\ No newline at end of file diff --git a/js/tests/controllers/feedcontrollerSpec.coffee b/js/tests/controllers/feedcontrollerSpec.coffee index 293a55f47..755e84440 100644 --- a/js/tests/controllers/feedcontrollerSpec.coffee +++ b/js/tests/controllers/feedcontrollerSpec.coffee @@ -23,130 +23,43 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. describe '_FeedController', -> - beforeEach module 'News' + beforeEach => + angular.module('News').factory 'Persistence', => + @persistence = {} - beforeEach inject (@_FeedController, @ActiveFeed, @ShowAll, @FeedType, - @StarredCount, @FeedModel, @FolderModel, @FeedBl) => - @scope = - $on: -> - - @persistence = - getItems: -> - - @controller = new @_FeedController(@scope, @FolderModel, @FeedModel, - @ActiveFeed, @ShowAll, @FeedType, - @StarredCount, @persistence, - @FeedBl) - - - xit 'should make folders available', => - @FolderModel.getAll = jasmine.createSpy('FolderModel') - new @_FeedController(@scope, @FolderModel, @FeedModel, @_ActiveFeed) - - expect(@FolderModel.getAll).toHaveBeenCalled() - - - xit 'should make feeds availabe', => - @FeedModel.getAll = jasmine.createSpy('FeedModel') - new @_FeedController(@scope, @FolderModel, @FeedModel, @_ActiveFeed) - - expect(@FeedModel.getAll).toHaveBeenCalled() - - - xit 'should make feedtype available', => - expect(@scope.feedType).toBe(@FeedType) - - - xit 'should check the active feed', => - @ActiveFeed.getType = => - return @FeedType.Feed - @ActiveFeed.getId = => - return 5 - - expect(@scope.isFeedActive(@FeedType.Feed, 5)).toBeTruthy() - - - xit 'should provide ShowAll', => - expect(@scope.isShowAll()).toBeFalsy() - - @ShowAll.setShowAll(true) - expect(@scope.isShowAll()).toBeTruthy() - - - xit 'should handle show all correctly', => - @persistence.userSettingsReadHide = jasmine.createSpy('hide') - @persistence.userSettingsReadShow = jasmine.createSpy('show') - @scope.setShowAll(true) - expect(@ShowAll.getShowAll()).toBeTruthy() - expect(@persistence.userSettingsReadShow).toHaveBeenCalled() - expect(@persistence.userSettingsReadHide).not.toHaveBeenCalled() + beforeEach inject (@_FeedController, @FolderBl, @FeedBl, $rootScope, + @unreadCountFormatter) => + @scope = $rootScope.$new() + @controller = new @_FeedController(@scope, @persistence, @FolderBl, + @FeedBl, @unreadCountFormatter) - xit 'should handle hide all correctly', => - @persistence.userSettingsReadHide = jasmine.createSpy('hide') - @persistence.userSettingsReadShow = jasmine.createSpy('show') - @scope.setShowAll(false) - expect(@ShowAll.getShowAll()).toBeFalsy() - expect(@persistence.userSettingsReadShow).not.toHaveBeenCalled() - expect(@persistence.userSettingsReadHide).toHaveBeenCalled() + it 'isAddingFolder should return false in the beginning', => + expect(@scope.isAddingFolder()).toBeFalsy() - xit 'should get the correct count for starred items', => - @StarredCount.setStarredCount(133) - count = @scope.getUnreadCount(@FeedType.Starred, 0) - - expect(count).toBe(133) - - - xit 'should set the count to 999+ if the count is over 999', => - @StarredCount.setStarredCount(1000) - count = @scope.getUnreadCount(@FeedType.Starred, 0) - - expect(count).toBe('999+') - - - - - - xit 'should set active feed to new feed if changed', => - @ActiveFeed.handle({id: 3, type: 3}) - @scope.loadFeed(4, 3) - - expect(@ActiveFeed.getId()).toBe(3) - expect(@ActiveFeed.getType()).toBe(4) - - - xit 'should return true when calling isShown and there are feeds', => - @FeedModel.add({id: 3}) - @ShowAll.setShowAll(true) - expect(@scope.isShown(3, 4)).toBeTruthy() - - @ShowAll.setShowAll(false) - expect(@scope.isShown(3, 4)).toBeFalsy() + it 'isAddingFeed should return false in the beginning', => + expect(@scope.isAddingFeed()).toBeFalsy() - xit 'should return true if ShowAll is false but unreadcount is not 0', => - @ShowAll.setShowAll(false) - @FeedModel.add({id: 4, unreadCount: 0, urlHash: 'a1'}) - expect(@scope.isShown(@FeedType.Feed, 4)).toBeFalsy() - @FeedModel.add({id: 4, unreadCount: 12, urlHash: 'a2'}) - expect(@scope.isShown(@FeedType.Feed, 4)).toBeTruthy() + it 'should make unreadCountFormatter available', => + expect(@scope.unreadCountFormatter).toBe(@unreadCountFormatter) - xit 'isAddingFolder should return false in the beginning', => - expect(@scope.isAddingFolder()).toBeFalsy() + it 'should make FeedBl available', => + expect(@scope.feedBl).toBe(@FeedBl) - xit 'isAddingFeed should return false in the beginning', => - expect(@scope.isAddingFeed()).toBeFalsy() + it 'should make FolderBl available', => + expect(@scope.folderBl).toBe(@FolderBl) - xit 'should not add folders that have no name', => + it 'should not add folders that have no name', => @persistence.createFolder = jasmine.createSpy('create') @scope.addFolder(' ') diff --git a/js/tests/services/bl/feedblSpec.coffee b/js/tests/services/bl/feedblSpec.coffee index 2ca742cc7..27b681a32 100644 --- a/js/tests/services/bl/feedblSpec.coffee +++ b/js/tests/services/bl/feedblSpec.coffee @@ -152,4 +152,30 @@ describe 'FeedBl', -> @FeedModel.add({id: 2, unreadCount:134, urlHash: 'a1', folderId: 3}) @FeedBl.move(2, 3) - expect(@persistence.moveFeed).not.toHaveBeenCalled()
\ No newline at end of file + expect(@persistence.moveFeed).not.toHaveBeenCalled() + + + it 'should set the show all setting', => + @persistence.userSettingsReadShow = jasmine.createSpy('Show All') + @FeedBl.setShowAll(true) + + expect(@persistence.userSettingsReadShow).toHaveBeenCalled() + + + + it 'should set the hide read setting', => + @persistence.userSettingsReadHide = jasmine.createSpy('Hide Read') + @FeedBl.setShowAll(false) + + expect(@persistence.userSettingsReadHide).toHaveBeenCalled() + + + it 'should return all feeds', => + item1 = {id: 2, unreadCount:134, urlHash: 'a1', folderId: 3} + item2 = {id: 4, unreadCount:134, urlHash: 'a2', folderId: 3} + @FeedModel.add(item1) + @FeedModel.add(item2) + + expect(@FeedBl.getAll()).toContain(item1) + expect(@FeedBl.getAll()).toContain(item2) + diff --git a/js/tests/services/bl/folderblSpec.coffee b/js/tests/services/bl/folderblSpec.coffee index c7590f51f..5c36cf203 100644 --- a/js/tests/services/bl/folderblSpec.coffee +++ b/js/tests/services/bl/folderblSpec.coffee @@ -118,3 +118,15 @@ describe 'FolderBl', -> @ActiveFeed.handle({type: @FeedType.Folder, id:2}) expect(@FolderBl.isVisible(3)).toBe(true) + + + it 'should return all folders', => + item1 = {id: 3, open: false} + item2 = {id: 4, open: true} + @FolderModel.add(item1) + @FolderModel.add(item2) + + expect(@FolderBl.getAll()).toContain(item1) + expect(@FolderBl.getAll()).toContain(item2) + + diff --git a/js/tests/services/unreadcountformaterSpec.coffee b/js/tests/services/unreadcountformaterSpec.coffee new file mode 100644 index 000000000..f4dabb8cc --- /dev/null +++ b/js/tests/services/unreadcountformaterSpec.coffee @@ -0,0 +1,35 @@ +### + +ownCloud - News + +@author Bernhard Posselt +@copyright 2012 Bernhard Posselt nukeawhale@gmail.com + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +License as published by the Free Software Foundation; either +version 3 of the License, or any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU AFFERO GENERAL PUBLIC LICENSE for more details. + +You should have received a copy of the GNU Affero General Public +License along with this library. If not, see <http://www.gnu.org/licenses/>. + +### + + +describe 'unreadCountFormatter', -> + + beforeEach module 'News' + + beforeEach inject (@unreadCountFormatter) => + + it 'should return the normal count if its below 999', => + expect(@unreadCountFormatter(999)).toBe(999) + + + it 'should set the count to 999+ if the count is over 999', => + expect(@unreadCountFormatter(1000)).toBe('999+')
\ No newline at end of file |