diff options
-rw-r--r-- | js/build/app.js | 14 | ||||
-rw-r--r-- | js/controller/SettingsController.js | 7 | ||||
-rw-r--r-- | js/service/FeedResource.js | 6 | ||||
-rw-r--r-- | js/service/SettingsResource.js (renamed from js/service/Settings.js) | 2 | ||||
-rw-r--r-- | js/tests/unit/controller/SettingsControllerSpec.js | 16 | ||||
-rw-r--r-- | js/tests/unit/service/SettingsResourceSpec.js (renamed from js/tests/unit/service/SettingsSpec.js) | 14 |
6 files changed, 32 insertions, 27 deletions
diff --git a/js/build/app.js b/js/build/app.js index 422adafb1..7a63b37b7 100644 --- a/js/build/app.js +++ b/js/build/app.js @@ -197,17 +197,17 @@ var $__build_47_app__ = function () { console.log('here'); }); app.controller('SettingsController', [ - 'Settings', '$route', + 'SettingsResource', 'FeedResource', - function (Settings, $route, FeedResource) { + function ($route, SettingsResource, FeedResource) { 'use strict'; var $__0 = this; this.importing = false; this.opmlImportError = false; this.articleImportError = false; var set = function (key, value) { - Settings.set(key, value); + SettingsResource.set(key, value); if ([ 'showAll', 'oldestFirst' @@ -219,7 +219,7 @@ var $__build_47_app__ = function () { set(key, !$__0.getSetting(key)); }; this.getSetting = function (key) { - return Settings.get(key); + return SettingsResource.get(key); }; this.importOpml = function (content) { console.log(content); @@ -250,7 +250,9 @@ var $__build_47_app__ = function () { $traceurRuntime.createClass(FeedResource, { add: function (value) { $traceurRuntime.superCall(this, $FeedResource.prototype, 'add', [value]); - $traceurRuntime.setProperty(this.ids, value.id, this.hashMap[$traceurRuntime.toProperty(value.url)]); + if (value.id !== undefined) { + $traceurRuntime.setProperty(this.ids, value.id, this.hashMap[$traceurRuntime.toProperty(value.url)]); + } }, delete: function (id) { var feed = this.get(id); @@ -583,7 +585,7 @@ var $__build_47_app__ = function () { }, {}); return Resource; }); - app.service('Settings', [ + app.service('SettingsResource', [ '$http', 'BASE_URL', function ($http, BASE_URL) { diff --git a/js/controller/SettingsController.js b/js/controller/SettingsController.js index ae0e1ee52..37dbaa9b3 100644 --- a/js/controller/SettingsController.js +++ b/js/controller/SettingsController.js @@ -7,7 +7,8 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.controller('SettingsController', function (Settings, $route, FeedResource) { +app.controller('SettingsController', +function ($route, SettingsResource, FeedResource) { 'use strict'; this.importing = false; @@ -15,7 +16,7 @@ app.controller('SettingsController', function (Settings, $route, FeedResource) { this.articleImportError = false; let set = (key, value) => { - Settings.set(key, value); + SettingsResource.set(key, value); if (['showAll', 'oldestFirst'].indexOf(key) >= 0) { $route.reload(); @@ -29,7 +30,7 @@ app.controller('SettingsController', function (Settings, $route, FeedResource) { this.getSetting = (key) => { - return Settings.get(key); + return SettingsResource.get(key); }; diff --git a/js/service/FeedResource.js b/js/service/FeedResource.js index 1f0c6c34d..548c5a27c 100644 --- a/js/service/FeedResource.js +++ b/js/service/FeedResource.js @@ -20,7 +20,9 @@ app.factory('FeedResource', (Resource, $http, BASE_URL) => { add (value) { super.add(value); - this.ids[value.id] = this.hashMap[value.url]; + if (value.id !== undefined) { + this.ids[value.id] = this.hashMap[value.url]; + } } @@ -32,7 +34,7 @@ app.factory('FeedResource', (Resource, $http, BASE_URL) => { markRead () { - for(let feed of this.values) { + for (let feed of this.values) { feed.unreadCount = 0; } } diff --git a/js/service/Settings.js b/js/service/SettingsResource.js index e8189fcd5..26b26145d 100644 --- a/js/service/Settings.js +++ b/js/service/SettingsResource.js @@ -9,7 +9,7 @@ */ /*jshint unused:false*/ -app.service('Settings', function ($http, BASE_URL) { +app.service('SettingsResource', function ($http, BASE_URL) { 'use strict'; this.settings = {}; diff --git a/js/tests/unit/controller/SettingsControllerSpec.js b/js/tests/unit/controller/SettingsControllerSpec.js index 523d74bc0..fbe8b3438 100644 --- a/js/tests/unit/controller/SettingsControllerSpec.js +++ b/js/tests/unit/controller/SettingsControllerSpec.js @@ -23,37 +23,37 @@ describe('SettingsController', () => { }); it('should set values', inject(($controller) => { - let Settings = { - set: jasmine.createSpy('Settings'), + let SettingsResource = { + set: jasmine.createSpy('SettingsResource'), get: key => key }; let ctrl = $controller('SettingsController', { - Settings: Settings, + SettingsResource: SettingsResource, $route: route }); ctrl.toggleSetting(3); - expect(Settings.set).toHaveBeenCalledWith(3, false); + expect(SettingsResource.set).toHaveBeenCalledWith(3, false); })); it('should reload page if set needed', inject(($controller) => { - let settings = { - set: jasmine.createSpy('Settings'), + let SettingsResource = { + set: jasmine.createSpy('SettingsResource'), get: key => key }; let ctrl = $controller('SettingsController', { - Settings: settings, + SettingsResource: SettingsResource, $route: route }); ctrl.toggleSetting('showAll'); ctrl.toggleSetting('oldestFirst'); - expect(settings.set).toHaveBeenCalledWith('showAll', false); + expect(SettingsResource.set).toHaveBeenCalledWith('showAll', false); expect(route.reload).toHaveBeenCalled(); expect(route.reload.callCount).toBe(2); })); diff --git a/js/tests/unit/service/SettingsSpec.js b/js/tests/unit/service/SettingsResourceSpec.js index 06bb365b6..912e342d1 100644 --- a/js/tests/unit/service/SettingsSpec.js +++ b/js/tests/unit/service/SettingsResourceSpec.js @@ -7,7 +7,7 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('Settings', () => { +describe('SettingsResource', () => { 'use strict'; let http; @@ -21,23 +21,23 @@ describe('Settings', () => { })); - it('should receive default settings', inject((Settings) => { - Settings.receive({ + it('should receive default SettingsResource', inject((SettingsResource) => { + SettingsResource.receive({ 'showAll': true }); - expect(Settings.get('showAll')).toBe(true); + expect(SettingsResource.get('showAll')).toBe(true); })); - it('should set values', inject((Settings) => { + it('should set values', inject((SettingsResource) => { http.expectPOST('base/settings', {showAll: true}).respond(200, {}); - Settings.set('showAll', true); + SettingsResource.set('showAll', true); http.flush(); - expect(Settings.get('showAll')).toBe(true); + expect(SettingsResource.get('showAll')).toBe(true); })); |