diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-20 17:01:59 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-20 17:01:59 +0200 |
commit | 5a7b1e0c36c2dd564f44568de766118b07be49ad (patch) | |
tree | 23b9f80bb4509dd51948c3851660f5fa3754031d /js | |
parent | b5d5b2b22a2b4aabd4c9bb5c8b89aae10facc735 (diff) |
rename model to resource
Diffstat (limited to 'js')
-rw-r--r-- | js/app/Run.js | 12 | ||||
-rw-r--r-- | js/build/app.js | 182 | ||||
-rw-r--r-- | js/controller/AppController.js | 4 | ||||
-rw-r--r-- | js/controller/ContentController.js | 6 | ||||
-rw-r--r-- | js/service/FeedResource.js (renamed from js/model/Feed.js) | 10 | ||||
-rw-r--r-- | js/service/FolderResource.js (renamed from js/model/Folder.js) | 10 | ||||
-rw-r--r-- | js/service/ItemResource.js (renamed from js/model/Item.js) | 18 | ||||
-rw-r--r-- | js/service/Resource.js (renamed from js/model/Model.js) | 9 | ||||
-rw-r--r-- | js/tests/unit/controller/AppControllerSpec.js | 8 | ||||
-rw-r--r-- | js/tests/unit/controller/ContentControllerSpec.js | 8 | ||||
-rw-r--r-- | js/tests/unit/models/ItemSpec.js | 43 | ||||
-rw-r--r-- | js/tests/unit/service/ItemResourceSpec.js | 43 | ||||
-rw-r--r-- | js/tests/unit/service/ResourceSpec.js (renamed from js/tests/unit/models/ModelSpec.js) | 10 |
13 files changed, 185 insertions, 178 deletions
diff --git a/js/app/Run.js b/js/app/Run.js index 829c9666c..c60150fbe 100644 --- a/js/app/Run.js +++ b/js/app/Run.js @@ -7,9 +7,9 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.run(function ($rootScope, $location, $http, $q, $interval, Loading, Item, - Feed, Folder, Settings, Publisher, BASE_URL, FEED_TYPE, - REFRESH_RATE) { +app.run(function ($rootScope, $location, $http, $q, $interval, Loading, + ItemResource, FeedResource, FolderResource, Settings, + Publisher, BASE_URL, FEED_TYPE, REFRESH_RATE) { 'use strict'; // show Loading screen @@ -17,9 +17,9 @@ app.run(function ($rootScope, $location, $http, $q, $interval, Loading, Item, // listen to keys in returned queries to automatically distribute the // incoming values to models - Publisher.subscribe(Item).toChannels('items', 'newestItemId', 'starred'); - Publisher.subscribe(Folder).toChannels('folders'); - Publisher.subscribe(Feed).toChannels('feeds'); + Publisher.subscribe(ItemResource).toChannels('items', 'newestItemId', 'starred'); + Publisher.subscribe(FolderResource).toChannels('folders'); + Publisher.subscribe(FeedResource).toChannels('feeds'); Publisher.subscribe(Settings).toChannels('settings'); // load feeds, settings and last read feed diff --git a/js/build/app.js b/js/build/app.js index 3f78f4647..ca4ef9c38 100644 --- a/js/build/app.js +++ b/js/build/app.js @@ -98,23 +98,23 @@ app.run([ '$q', '$interval', 'Loading', - 'Item', - 'Feed', - 'Folder', + 'ItemResource', + 'FeedResource', + 'FolderResource', 'Settings', 'Publisher', 'BASE_URL', 'FEED_TYPE', 'REFRESH_RATE', - function ($rootScope, $location, $http, $q, $interval, Loading, Item, Feed, Folder, Settings, Publisher, BASE_URL, FEED_TYPE, REFRESH_RATE) { + function ($rootScope, $location, $http, $q, $interval, Loading, ItemResource, FeedResource, FolderResource, Settings, Publisher, BASE_URL, FEED_TYPE, REFRESH_RATE) { 'use strict'; // show Loading screen Loading.setLoading('global', true); // listen to keys in returned queries to automatically distribute the // incoming values to models - Publisher.subscribe(Item).toChannels('items', 'newestItemId', 'starred'); - Publisher.subscribe(Folder).toChannels('folders'); - Publisher.subscribe(Feed).toChannels('feeds'); + Publisher.subscribe(ItemResource).toChannels('items', 'newestItemId', 'starred'); + Publisher.subscribe(FolderResource).toChannels('folders'); + Publisher.subscribe(FeedResource).toChannels('feeds'); Publisher.subscribe(Settings).toChannels('settings'); // load feeds, settings and last read feed var settingsDeferred, activeFeedDeferred, folderDeferred, feedDeferred; @@ -180,30 +180,30 @@ app.run([ ]); app.controller('AppController', [ 'Loading', - 'Feed', - 'Folder', - function (Loading, Feed, Folder) { + 'FeedResource', + 'FolderResource', + function (Loading, FeedResource, FolderResource) { 'use strict'; this.loading = Loading; this.isFirstRun = function () { - return Feed.size() === 0 && Folder.size() === 0; + return FeedResource.size() === 0 && FolderResource.size() === 0; }; } ]); app.controller('ContentController', [ 'Publisher', - 'Feed', - 'Item', + 'FeedResource', + 'ItemResource', 'data', - function (Publisher, Feed, Item, data) { + function (Publisher, FeedResource, ItemResource, data) { 'use strict'; // distribute data to models based on key Publisher.publishAll(data); this.getItems = function () { - return Item.getAll(); + return ItemResource.getAll(); }; this.getFeeds = function () { - return Feed.getAll(); + return FeedResource.getAll(); }; } ]); @@ -215,6 +215,60 @@ app.controller('SettingsController', function () { 'use strict'; console.log('here'); }); +app.factory('FeedResource', [ + 'Resource', + '$http', + function (Resource, $http) { + 'use strict'; + var FeedResource = function ($http) { + Resource.call(this, 'url', $http); + }; + FeedResource.prototype = Object.create(Resource.prototype); + return new FeedResource($http); + } +]); +app.factory('FolderResource', [ + 'Resource', + '$http', + function (Resource, $http) { + 'use strict'; + var FolderResource = function ($http) { + Resource.call(this, 'name', $http); + }; + FolderResource.prototype = Object.create(Resource.prototype); + return new FolderResource($http); + } +]); +app.factory('ItemResource', [ + 'Resource', + '$http', + function (Resource, $http) { + 'use strict'; + var ItemResource = function ($http) { + Resource.call(this, 'id', $http); + }; + ItemResource.prototype = Object.create(Resource.prototype); + ItemResource.prototype.receive = function (value, channel) { + switch (channel) { + case 'newestItemId': + this.newestItemId = value; + break; + case 'starred': + this.starredCount = value; + break; + default: + Resource.prototype.receive.call(this, value, channel); + } + }; + ItemResource.prototype.getNewestItemId = function () { + return this.newestItemId; + }; + ItemResource.prototype.getStarredCount = function () { + return this.starredCount; + }; + return new ItemResource($http); + } +]); app.service('Loading', function () { 'use strict'; this.loading = { @@ -256,83 +310,15 @@ app.service('Publisher', function () { } }; }); -app.service('Settings', function () { +app.factory('Resource', function () { 'use strict'; - this.settings = {}; - this.receive = function (data) { - var key; - for (key in data) { - if (data.hasOwnProperty(key)) { - this.settings[key] = data[key]; - } - } - }; - this.get = function (key) { - return this.settings[key]; - }; - this.set = function (key, value) { - this.settings[key] = value; - }; -}); -app.factory('Feed', [ - 'Model', - function (Model) { - 'use strict'; - var Feed = function () { - Model.call(this, 'url'); - }; - Feed.prototype = Object.create(Model.prototype); - return new Feed(); - } -]); -app.factory('Folder', [ - 'Model', - function (Model) { - 'use strict'; - var Folder = function () { - Model.call(this, 'name'); - }; - Folder.prototype = Object.create(Model.prototype); - return new Folder(); - } -]); -app.factory('Item', [ - 'Model', - function (Model) { - 'use strict'; - var Item = function () { - Model.call(this, 'id'); - }; - Item.prototype = Object.create(Model.prototype); - Item.prototype.receive = function (value, channel) { - switch (channel) { - case 'newestItemId': - this.newestItemId = value; - break; - case 'starred': - this.starredCount = value; - break; - default: - Model.prototype.receive.call(this, value, channel); - } - }; - Item.prototype.getNewestItemId = function () { - return this.newestItemId; - }; - Item.prototype.getStarredCount = function () { - return this.starredCount; - }; - return new Item(); - } -]); -app.factory('Model', function () { - 'use strict'; - var Model = function (id) { + var Resource = function (id, http) { this.id = id; this.values = []; this.hashMap = {}; + this.http = http; }; - Model.prototype = { + Resource.prototype = { receive: function (values) { var self = this; values.forEach(function (value) { @@ -389,7 +375,25 @@ app.factory('Model', function () { return this.values; } }; - return Model; + return Resource; +}); +app.service('Settings', function () { + 'use strict'; + this.settings = {}; + this.receive = function (data) { + var key; + for (key in data) { + if (data.hasOwnProperty(key)) { + this.settings[key] = data[key]; + } + } + }; + this.get = function (key) { + return this.settings[key]; + }; + this.set = function (key, value) { + this.settings[key] = value; + }; }); })(angular, jQuery, OC, oc_requesttoken);
\ No newline at end of file diff --git a/js/controller/AppController.js b/js/controller/AppController.js index ee8115c84..b833d3fe1 100644 --- a/js/controller/AppController.js +++ b/js/controller/AppController.js @@ -7,13 +7,13 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.controller('AppController', function (Loading, Feed, Folder) { +app.controller('AppController', function (Loading, FeedResource, FolderResource) { 'use strict'; this.loading = Loading; this.isFirstRun = function () { - return Feed.size() === 0 && Folder.size() === 0; + return FeedResource.size() === 0 && FolderResource.size() === 0; }; });
\ No newline at end of file diff --git a/js/controller/ContentController.js b/js/controller/ContentController.js index 51309a93d..8e4632f7e 100644 --- a/js/controller/ContentController.js +++ b/js/controller/ContentController.js @@ -7,17 +7,17 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.controller('ContentController', function (Publisher, Feed, Item, data) { +app.controller('ContentController', function (Publisher, FeedResource, ItemResource, data) { 'use strict'; // distribute data to models based on key Publisher.publishAll(data); this.getItems = function () { - return Item.getAll(); + return ItemResource.getAll(); }; this.getFeeds = function () { - return Feed.getAll(); + return FeedResource.getAll(); }; });
\ No newline at end of file diff --git a/js/model/Feed.js b/js/service/FeedResource.js index 9223ca6e7..09de0a607 100644 --- a/js/model/Feed.js +++ b/js/service/FeedResource.js @@ -7,14 +7,14 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.factory('Feed', function (Model) { +app.factory('FeedResource', function (Resource, $http) { 'use strict'; - var Feed = function () { - Model.call(this, 'url'); + var FeedResource = function ($http) { + Resource.call(this, 'url', $http); }; - Feed.prototype = Object.create(Model.prototype); + FeedResource.prototype = Object.create(Resource.prototype); - return new Feed(); + return new FeedResource($http); });
\ No newline at end of file diff --git a/js/model/Folder.js b/js/service/FolderResource.js index 101b8ec66..30026b9a2 100644 --- a/js/model/Folder.js +++ b/js/service/FolderResource.js @@ -7,14 +7,14 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.factory('Folder', function (Model) { +app.factory('FolderResource', function (Resource, $http) { 'use strict'; - var Folder = function () { - Model.call(this, 'name'); + var FolderResource = function ($http) { + Resource.call(this, 'name', $http); }; - Folder.prototype = Object.create(Model.prototype); + FolderResource.prototype = Object.create(Resource.prototype); - return new Folder(); + return new FolderResource($http); });
\ No newline at end of file diff --git a/js/model/Item.js b/js/service/ItemResource.js index ec3512f22..9b13f07c7 100644 --- a/js/model/Item.js +++ b/js/service/ItemResource.js @@ -7,16 +7,16 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.factory('Item', function (Model) { +app.factory('ItemResource', function (Resource, $http) { 'use strict'; - var Item = function () { - Model.call(this, 'id'); + var ItemResource = function ($http) { + Resource.call(this, 'id', $http); }; - Item.prototype = Object.create(Model.prototype); + ItemResource.prototype = Object.create(Resource.prototype); - Item.prototype.receive = function (value, channel) { + ItemResource.prototype.receive = function (value, channel) { switch (channel) { case 'newestItemId': @@ -27,18 +27,18 @@ app.factory('Item', function (Model) { this.starredCount = value; break; default: - Model.prototype.receive.call(this, value, channel); + Resource.prototype.receive.call(this, value, channel); } }; - Item.prototype.getNewestItemId = function () { + ItemResource.prototype.getNewestItemId = function () { return this.newestItemId; }; - Item.prototype.getStarredCount = function () { + ItemResource.prototype.getStarredCount = function () { return this.starredCount; }; - return new Item(); + return new ItemResource($http); });
\ No newline at end of file diff --git a/js/model/Model.js b/js/service/Resource.js index d43a40f1d..ecae0fcfd 100644 --- a/js/model/Model.js +++ b/js/service/Resource.js @@ -7,16 +7,17 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.factory('Model', function () { +app.factory('Resource', function () { 'use strict'; - var Model = function (id) { + var Resource = function (id, http) { this.id = id; this.values = []; this.hashMap = {}; + this.http = http; }; - Model.prototype = { + Resource.prototype = { receive: function (values) { var self = this; values.forEach(function (value) { @@ -88,5 +89,5 @@ app.factory('Model', function () { } }; - return Model; + return Resource; });
\ No newline at end of file diff --git a/js/tests/unit/controller/AppControllerSpec.js b/js/tests/unit/controller/AppControllerSpec.js index b7dad7492..d44d8b0c3 100644 --- a/js/tests/unit/controller/AppControllerSpec.js +++ b/js/tests/unit/controller/AppControllerSpec.js @@ -29,15 +29,15 @@ describe('AppController', function () { })); - it('should expose set firstrun if feeds', inject(function (Feed) { - Feed.add({url: 'test'}); + it('should expose set firstrun if feeds', inject(function (FeedResource) { + FeedResource.add({url: 'test'}); expect(controller.isFirstRun()).toBe(false); })); - it('should expose set firstrun if folders', inject(function (Folder) { - Folder.add({name: 'test'}); + it('should expose set firstrun if folders', inject(function (FolderResource) { + FolderResource.add({name: 'test'}); expect(controller.isFirstRun()).toBe(false); })); diff --git a/js/tests/unit/controller/ContentControllerSpec.js b/js/tests/unit/controller/ContentControllerSpec.js index 9e3693e86..c99cb79ab 100644 --- a/js/tests/unit/controller/ContentControllerSpec.js +++ b/js/tests/unit/controller/ContentControllerSpec.js @@ -13,9 +13,11 @@ describe('ContentController', function () { beforeEach(module('News')); - it('should publish data to models', inject(function ($controller, Publisher, Feed, Item) { - Publisher.subscribe(Item).toChannels('items'); - Publisher.subscribe(Feed).toChannels('feeds'); + it('should publish data to models', inject(function ($controller, Publisher, + FeedResource, ItemResource) { + + Publisher.subscribe(ItemResource).toChannels('items'); + Publisher.subscribe(FeedResource).toChannels('feeds'); var controller = $controller('ContentController', { data: { diff --git a/js/tests/unit/models/ItemSpec.js b/js/tests/unit/models/ItemSpec.js deleted file mode 100644 index 85ee5789e..000000000 --- a/js/tests/unit/models/ItemSpec.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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('Item', function () { - 'use strict'; - - beforeEach(module('News')); - - - it('should receive the newestItemId', inject(function (Item) { - Item.receive(3, 'newestItemId'); - - expect(Item.getNewestItemId()).toBe(3); - })); - - - it('should receive the newestItemId', inject(function (Item) { - Item.receive(2, 'starred'); - - expect(Item.getStarredCount()).toBe(2); - })); - - - it('should receive items', inject(function (Item) { - Item.receive([ - { - id: 3 - }, - { - id: 4 - } - ], 'items'); - - expect(Item.size()).toBe(2); - })); - -});
\ No newline at end of file diff --git a/js/tests/unit/service/ItemResourceSpec.js b/js/tests/unit/service/ItemResourceSpec.js new file mode 100644 index 000000000..9d6c10ae0 --- /dev/null +++ b/js/tests/unit/service/ItemResourceSpec.js @@ -0,0 +1,43 @@ +/** + * 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('ItemResource', function () { + 'use strict'; + + beforeEach(module('News')); + + + it('should receive the newestItemId', inject(function (ItemResource) { + ItemResource.receive(3, 'newestItemId'); + + expect(ItemResource.getNewestItemId()).toBe(3); + })); + + + it('should receive the newestItemId', inject(function (ItemResource) { + ItemResource.receive(2, 'starred'); + + expect(ItemResource.getStarredCount()).toBe(2); + })); + + + it('should receive items', inject(function (ItemResource) { + ItemResource.receive([ + { + id: 3 + }, + { + id: 4 + } + ], 'items'); + + expect(ItemResource.size()).toBe(2); + })); + +});
\ No newline at end of file diff --git a/js/tests/unit/models/ModelSpec.js b/js/tests/unit/service/ResourceSpec.js index 6e1d0791b..ba877fcd4 100644 --- a/js/tests/unit/models/ModelSpec.js +++ b/js/tests/unit/service/ResourceSpec.js @@ -7,18 +7,18 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('Model', function () { +describe('Resource', function () { 'use strict'; var childModel; beforeEach(module('News')); - beforeEach(inject(function (Model) { + beforeEach(inject(function (Resource) { var ChildModel = function () { - Model.call(this, 'id'); + Resource.call(this, 'id'); }; - ChildModel.prototype = Object.create(Model.prototype); + ChildModel.prototype = Object.create(Resource.prototype); childModel = new ChildModel(); })); @@ -75,7 +75,7 @@ describe('Model', function () { }); - it('should delete a model', function () { + it('should delete a Resource', function () { var object1, object2; |