diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-31 01:12:20 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-31 01:12:20 +0200 |
commit | 82f0a877a001ead0bd0cdd76d96fe46a071535d8 (patch) | |
tree | a37f50a00c77c5e6afd1790ccde75ab3639c6c96 /js | |
parent | 32f2759945521129e00a7cd4933682ff63d9440f (diff) |
add active and unread stuff
Diffstat (limited to 'js')
-rw-r--r-- | js/build/app.js | 86 | ||||
-rw-r--r-- | js/controller/NavigationController.js | 92 | ||||
-rw-r--r-- | js/filter/UnreadCountFormatter.js | 19 | ||||
-rw-r--r-- | js/service/FeedResource.js | 2 | ||||
-rw-r--r-- | js/service/ItemResource.js | 1 | ||||
-rw-r--r-- | js/tests/unit/controller/NavigationControllerSpec.js | 156 | ||||
-rw-r--r-- | js/tests/unit/filter/UnreadCountFormatterSpec.js | 27 | ||||
-rw-r--r-- | js/tests/unit/service/FeedResourceSpec.js | 2 |
8 files changed, 351 insertions, 34 deletions
diff --git a/js/build/app.js b/js/build/app.js index c482c3fb4..9d544268f 100644 --- a/js/build/app.js +++ b/js/build/app.js @@ -293,11 +293,13 @@ var $__build_47_app__ = function () { } ]); app.controller('NavigationController', [ + '$route', + 'FEED_TYPE', 'FeedResource', 'FolderResource', 'ItemResource', 'SettingsResource', - function (FeedResource, FolderResource, ItemResource, SettingsResource) { + function ($route, FEED_TYPE, FeedResource, FolderResource, ItemResource, SettingsResource) { 'use strict'; this.feedError = ''; this.folderError = ''; @@ -334,14 +336,67 @@ var $__build_47_app__ = function () { this.getFeedsOfFolder = function (folderId) { return FeedResource.getByFolderId(folderId); }; - this.createFeed = function () { - console.log('TBD'); + this.getUnreadCount = function () { + return FeedResource.getUnreadCount(); }; - this.createFolder = function () { - console.log('TBD'); + this.getFeedUnreadCount = function (feedId) { + return FeedResource.getById(feedId).unreadCount; }; - this.renameFeed = function () { - console.log('TBD'); + this.getFolderUnreadCount = function (folderId) { + return FeedResource.getFolderUnreadCount(folderId); + }; + this.getStarredCount = function () { + return ItemResource.getStarredCount(); + }; + this.toggleFolder = function (folderName) { + FolderResource.toggleOpen(folderName); + }; + this.hasFeeds = function (folderId) { + return FeedResource.getFolderUnreadCount(folderId) !== undefined; + }; + this.subFeedActive = function (folderId) { + var type = $route.current.$$route.type; + if (type === FEED_TYPE.FEED) { + try { + throw undefined; + } catch (feed) { + feed = FeedResource.getById($route.current.params.id); + if (feed.folderId === folderId) { + return true; + } + } + } + return false; + }; + this.isSubscriptionsActive = function () { + return $route.current.$$route.type === FEED_TYPE.SUBSCRIPTIONS; + }; + this.isStarredActive = function () { + return $route.current.$$route.type === FEED_TYPE.STARRED; + }; + this.isFolderActive = function (folderId) { + return $route.current.$$route.type === FEED_TYPE.FOLDER && $route.current.params.id === folderId; + }; + this.isFeedActive = function (feedId) { + return $route.current.$$route.type === FEED_TYPE.FEED && $route.current.params.id === feedId; + }; + this.isAddingFolder = function () { + return true; + }; + this.createFeed = function (feedUrl, folderId) { + console.log(feedUrl + folderId); + }; + this.createFolder = function (folderName) { + console.log(folderName); + }; + this.cancelRenameFolder = function (folderId) { + console.log(folderId); + }; + this.renameFeed = function (feedId, feedTitle) { + console.log(feedId + feedTitle); + }; + this.cancelRenameFeed = function (feedId) { + console.log(feedId); }; this.renameFolder = function () { console.log('TBD'); @@ -355,12 +410,6 @@ var $__build_47_app__ = function () { this.moveFeed = function () { console.log('TBD'); }; - this.isActive = function () { - console.log('TBD'); - }; - this.isVisible = function () { - console.log('TBD'); - }; } ]); app.controller('SettingsController', [ @@ -408,6 +457,15 @@ var $__build_47_app__ = function () { }; } ]); + app.filter('unreadCountFormatter', function () { + 'use strict'; + return function (unreadCount) { + if (unreadCount > 999) { + return '999+'; + } + return unreadCount; + }; + }); app.factory('FeedResource', [ 'Resource', '$http', @@ -541,7 +599,7 @@ var $__build_47_app__ = function () { return this.unreadCount; }, getFolderUnreadCount: function (folderId) { - return this.folderUnreadCount[$traceurRuntime.toProperty(folderId)] || 0; + return this.folderUnreadCount[$traceurRuntime.toProperty(folderId)]; }, getByFolderId: function (folderId) { return this.folderIds[$traceurRuntime.toProperty(folderId)] || []; diff --git a/js/controller/NavigationController.js b/js/controller/NavigationController.js index e6cb14a93..17ef923aa 100644 --- a/js/controller/NavigationController.js +++ b/js/controller/NavigationController.js @@ -8,7 +8,8 @@ * @copyright Bernhard Posselt 2014 */ app.controller('NavigationController', -function (FeedResource, FolderResource, ItemResource, SettingsResource) { +function ($route, FEED_TYPE, + FeedResource, FolderResource, ItemResource, SettingsResource) { 'use strict'; this.feedError = ''; @@ -48,42 +49,101 @@ function (FeedResource, FolderResource, ItemResource, SettingsResource) { return FeedResource.getByFolderId(folderId); }; + this.getUnreadCount = () => { + return FeedResource.getUnreadCount(); + }; + + this.getFeedUnreadCount = (feedId) => { + return FeedResource.getById(feedId).unreadCount; + }; + + this.getFolderUnreadCount= (folderId) => { + return FeedResource.getFolderUnreadCount(folderId); + }; + + this.getStarredCount = () => { + return ItemResource.getStarredCount(); + }; + + this.toggleFolder = (folderName) => { + FolderResource.toggleOpen(folderName); + }; + + this.hasFeeds = (folderId) => { + return FeedResource.getFolderUnreadCount(folderId) !== undefined; + }; + + this.subFeedActive = (folderId) => { + let type = $route.current.$$route.type; + + if (type === FEED_TYPE.FEED) { + let feed = FeedResource.getById($route.current.params.id); + + if (feed.folderId === folderId) { + return true; + } + } + + return false; + }; + + this.isSubscriptionsActive = () => { + return $route.current.$$route.type === FEED_TYPE.SUBSCRIPTIONS; + }; + + this.isStarredActive = () => { + return $route.current.$$route.type === FEED_TYPE.STARRED; + }; + + this.isFolderActive = (folderId) => { + return $route.current.$$route.type === FEED_TYPE.FOLDER && + $route.current.params.id === folderId; + }; + + this.isFeedActive = (feedId) => { + return $route.current.$$route.type === FEED_TYPE.FEED && + $route.current.params.id === feedId; + }; + // TBD - this.createFeed = () => { - console.log('TBD'); + this.isAddingFolder = () => { + return true; }; - this.createFolder = () => { - console.log('TBD'); + this.createFeed = (feedUrl, folderId) => { + console.log(feedUrl + folderId); }; - this.renameFeed = () => { - console.log('TBD'); + this.createFolder = (folderName) => { + console.log(folderName); }; - this.renameFolder = () => { - console.log('TBD'); + this.cancelRenameFolder = (folderId) => { + console.log(folderId); }; - this.deleteFeed = () => { - console.log('TBD'); + this.renameFeed = (feedId, feedTitle) => { + console.log(feedId + feedTitle); }; - this.deleteFolder = () => { - console.log('TBD'); + this.cancelRenameFeed = (feedId) => { + console.log(feedId); }; - this.moveFeed = () => { + this.renameFolder = () => { console.log('TBD'); }; - this.isActive = () => { + this.deleteFeed = () => { console.log('TBD'); }; - this.isVisible = () => { + this.deleteFolder = () => { console.log('TBD'); }; + this.moveFeed = () => { + console.log('TBD'); + }; });
\ No newline at end of file diff --git a/js/filter/UnreadCountFormatter.js b/js/filter/UnreadCountFormatter.js new file mode 100644 index 000000000..3450114b1 --- /dev/null +++ b/js/filter/UnreadCountFormatter.js @@ -0,0 +1,19 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.filter('unreadCountFormatter', () => { + 'use strict'; + + return (unreadCount) => { + if (unreadCount > 999) { + return '999+'; + } + return unreadCount; + }; +});
\ No newline at end of file diff --git a/js/service/FeedResource.js b/js/service/FeedResource.js index 9759724ac..1bbb3cbd2 100644 --- a/js/service/FeedResource.js +++ b/js/service/FeedResource.js @@ -130,7 +130,7 @@ app.factory('FeedResource', (Resource, $http, BASE_URL) => { getFolderUnreadCount (folderId) { - return this.folderUnreadCount[folderId] || 0; + return this.folderUnreadCount[folderId]; } diff --git a/js/service/ItemResource.js b/js/service/ItemResource.js index 79a07efd9..420e20775 100644 --- a/js/service/ItemResource.js +++ b/js/service/ItemResource.js @@ -30,6 +30,7 @@ app.factory('ItemResource', (Resource, $http, BASE_URL, ITEM_BATCH_SIZE) => { case 'starred': this.starredCount = value; break; + default: super.receive(value, channel); } diff --git a/js/tests/unit/controller/NavigationControllerSpec.js b/js/tests/unit/controller/NavigationControllerSpec.js index adefd157f..6837160bf 100644 --- a/js/tests/unit/controller/NavigationControllerSpec.js +++ b/js/tests/unit/controller/NavigationControllerSpec.js @@ -14,11 +14,24 @@ describe('NavigationController', () => { beforeEach(module('News', ($provide) => { $provide.value('BASE_URL', 'base'); + $provide.value('FEED_TYPE', { + FEED: 0, + FOLDER: 1, + STARRED: 2, + SUBSCRIPTIONS: 3, + SHARED: 4 + }); $provide.constant('ITEM_BATCH_SIZE', 5); })); - beforeEach(inject(($controller) => { + beforeEach(inject(($controller, FeedResource) => { controller = $controller('NavigationController'); + FeedResource.receive([ + {id: 1, folderId: 3, url: 'ye', unreadCount: 45}, + {id: 2, folderId: 4, url: 'sye', unreadCount: 25}, + {id: 3, folderId: 3, title: 'hore', url: '1sye', unreadCount: 1} + ]); + })); @@ -126,4 +139,143 @@ describe('NavigationController', () => { })); -});
\ No newline at end of file + it('should get the unreadcount', inject((FeedResource, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + }); + + + expect(ctrl.getUnreadCount()).toBe(71); + expect(ctrl.getFeedUnreadCount(1)).toBe(45); + expect(ctrl.getFolderUnreadCount(3)).toBe(46); + })); + + + it('should get the starred count', inject((ItemResource, $controller) => { + let ctrl = $controller('NavigationController', { + ItemResource: ItemResource, + }); + + ItemResource.receive(99, 'starred'); + + expect(ctrl.getStarredCount()).toBe(99); + })); + + + it('should toggle a folder', inject((FolderResource, $controller) => { + let ctrl = $controller('NavigationController', { + FolderResource: FolderResource, + }); + + FolderResource.toggleOpen = jasmine.createSpy('open'); + + ctrl.toggleFolder(3); + + expect(FolderResource.toggleOpen).toHaveBeenCalledWith(3); + })); + + + it('should check if a folder has feeds', inject((FeedResource, + $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + }); + + expect(ctrl.hasFeeds(3)).toBe(true); + expect(ctrl.hasFeeds(1)).toBe(false); + })); + + + it('should check if a subfeed is active', inject((FeedResource, + FEED_TYPE, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + $route: { + current: { + params: { + id: 3 + }, + $$route: { + type: FEED_TYPE.FEED + } + } + } + }); + + expect(ctrl.subFeedActive(3)).toBe(true); + })); + + it('should check if a subscriptions is active', inject((FeedResource, + FEED_TYPE, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + $route: { + current: { + $$route: { + type: FEED_TYPE.SUBSCRIPTIONS + } + } + } + }); + + expect(ctrl.isSubscriptionsActive()).toBe(true); + })); + + + it('should check if a starred is active', inject((FeedResource, + FEED_TYPE, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + $route: { + current: { + $$route: { + type: FEED_TYPE.STARRED + } + } + } + }); + + expect(ctrl.isStarredActive()).toBe(true); + })); + + + + it('should check if a feed is active', inject((FeedResource, + FEED_TYPE, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + $route: { + current: { + params: { + id: 3 + }, + $$route: { + type: FEED_TYPE.FEED + } + } + } + }); + + expect(ctrl.isFeedActive(3)).toBe(true); + })); + + + it('should check if a folder is active', inject((FeedResource, + FEED_TYPE, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + $route: { + current: { + params: { + id: 3 + }, + $$route: { + type: FEED_TYPE.FOLDER + } + } + } + }); + + expect(ctrl.isFolderActive(3)).toBe(true); + })); +}); diff --git a/js/tests/unit/filter/UnreadCountFormatterSpec.js b/js/tests/unit/filter/UnreadCountFormatterSpec.js new file mode 100644 index 000000000..14152f047 --- /dev/null +++ b/js/tests/unit/filter/UnreadCountFormatterSpec.js @@ -0,0 +1,27 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +describe('unreadCountFormatter', () => { + 'use strict'; + + let filter; + + beforeEach(module('News')); + + beforeEach(inject(($filter) => { + filter = $filter('unreadCountFormatter'); + })); + + it('should format the unread count', () => { + expect(filter(999)).toBe(999); + expect(filter(1000)).toBe('999+'); + }); + + +});
\ No newline at end of file diff --git a/js/tests/unit/service/FeedResourceSpec.js b/js/tests/unit/service/FeedResourceSpec.js index a37ff42f3..d7473cb70 100644 --- a/js/tests/unit/service/FeedResourceSpec.js +++ b/js/tests/unit/service/FeedResourceSpec.js @@ -97,7 +97,7 @@ describe('FeedResource', () => { expect(FeedResource.getFolderUnreadCount(3)).toBe(0); FeedResource.markRead(); - expect(FeedResource.getFolderUnreadCount(4)).toBe(0); + expect(FeedResource.getFolderUnreadCount(4)).toBe(undefined); })); |