diff options
Diffstat (limited to 'js/service/FeedResource.js')
-rw-r--r-- | js/service/FeedResource.js | 305 |
1 files changed, 154 insertions, 151 deletions
diff --git a/js/service/FeedResource.js b/js/service/FeedResource.js index 4466b502a..5c85fdc4e 100644 --- a/js/service/FeedResource.js +++ b/js/service/FeedResource.js @@ -7,221 +7,224 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.factory('FeedResource', (Resource, $http, BASE_URL) => { +app.factory('FeedResource', function (Resource, $http, BASE_URL) { 'use strict'; - class FeedResource extends Resource { - - constructor ($http, BASE_URL) { - super($http, BASE_URL, 'url'); - this.ids = {}; - this.unreadCount = 0; - this.folderUnreadCount = {}; - this.folderIds = {}; - this.deleted = null; - } + var FeedResource = function ($http, BASE_URL) { + Resource.call(this, $http, BASE_URL, 'url'); + this.ids = {}; + this.unreadCount = 0; + this.folderUnreadCount = {}; + this.folderIds = {}; + this.deleted = null; + }; + FeedResource.prototype = Object.create(Resource.prototype); - receive (data) { - super.receive(data); - this.updateUnreadCache(); - this.updateFolderCache(); - } + FeedResource.prototype.receive = function (data) { + Resource.prototype.receive.call(this, data); + this.updateUnreadCache(); + this.updateFolderCache(); + }; - updateUnreadCache () { - this.unreadCount = 0; - this.folderUnreadCount = {}; + FeedResource.prototype.updateUnreadCache = function () { + this.unreadCount = 0; + this.folderUnreadCount = {}; - for (let value of this.values) { - if (value.unreadCount) { - this.unreadCount += value.unreadCount; - } - if (value.folderId !== undefined) { - this.folderUnreadCount[value.folderId] = - this.folderUnreadCount[value.folderId] || 0; - this.folderUnreadCount[value.folderId] += value.unreadCount; - } + var self = this; + this.values.forEach(function (feed) { + if (feed.unreadCount) { + self.unreadCount += feed.unreadCount; } - } + if (feed.folderId !== undefined) { + self.folderUnreadCount[feed.folderId] = + self.folderUnreadCount[feed.folderId] || 0; + self.folderUnreadCount[feed.folderId] += feed.unreadCount; + } + }); + }; - updateFolderCache () { - this.folderIds = {}; + FeedResource.prototype.updateFolderCache = function () { + this.folderIds = {}; - for (let feed of this.values) { - this.folderIds[feed.folderId] = - this.folderIds[feed.folderId] || []; - this.folderIds[feed.folderId].push(feed); - } - } + var self = this; + this.values.forEach(function (feed) { + self.folderIds[feed.folderId] = + self.folderIds[feed.folderId] || []; + self.folderIds[feed.folderId].push(feed); + }); + }; - add (value) { - super.add(value); - if (value.id !== undefined) { - this.ids[value.id] = this.hashMap[value.url]; - } + FeedResource.prototype.add = function (value) { + Resource.prototype.add.call(this, value); + if (value.id !== undefined) { + this.ids[value.id] = this.hashMap[value.url]; } + }; - delete (url) { - let feed = this.get(url); - this.deleted = feed; - delete this.ids[feed.id]; + FeedResource.prototype.delete = function (url) { + var feed = this.get(url); + this.deleted = feed; + delete this.ids[feed.id]; - super.delete(url); + Resource.prototype.delete.call(this, url); - this.updateUnreadCache(); - this.updateFolderCache(); + this.updateUnreadCache(); + this.updateFolderCache(); - return this.http.delete(`${this.BASE_URL}/feeds/${feed.id}`); - } + return this.http.delete(this.BASE_URL + '/feeds/' + feed.id); + }; - markRead () { - for (let feed of this.values) { - feed.unreadCount = 0; - } - this.unreadCount = 0; - this.folderUnreadCount = {}; - } + FeedResource.prototype.markRead = function () { + this.values.forEach(function (feed) { + feed.unreadCount = 0; + }); + this.unreadCount = 0; + this.folderUnreadCount = {}; + }; - markFeedRead (feedId) { - this.ids[feedId].unreadCount = 0; - this.updateUnreadCache(); - } + FeedResource.prototype.markFeedRead = function (feedId) { + this.ids[feedId].unreadCount = 0; + this.updateUnreadCache(); + }; - markFolderRead (folderId) { - for (let feed of this.values) { - if (feed.folderId === folderId) { - feed.unreadCount = 0; - } - } - this.updateUnreadCache(); - } + FeedResource.prototype.markFolderRead = function (folderId) { + this.values.forEach(function (feed) { + if (feed.folderId === folderId) { + feed.unreadCount = 0; + } + }); - markItemOfFeedRead (feedId) { - this.ids[feedId].unreadCount -= 1; - this.updateUnreadCache(); - } + this.updateUnreadCache(); + }; - markItemsOfFeedsRead (feedIds) { - for (let feedId of feedIds) { - this.ids[feedId].unreadCount -= 1; - } - this.updateUnreadCache(); - } + FeedResource.prototype.markItemOfFeedRead = function (feedId) { + this.ids[feedId].unreadCount -= 1; + this.updateUnreadCache(); + }; - markItemOfFeedUnread (feedId) { - this.ids[feedId].unreadCount += 1; - this.updateUnreadCache(); - } + FeedResource.prototype.markItemsOfFeedsRead = function (feedIds) { + var self = this; + feedIds.forEach(function (feedId) { + self.ids[feedId].unreadCount -= 1; + }); + this.updateUnreadCache(); + }; - getUnreadCount () { - return this.unreadCount; - } + FeedResource.prototype.markItemOfFeedUnread = function (feedId) { + this.ids[feedId].unreadCount += 1; + this.updateUnreadCache(); + }; - getFolderUnreadCount (folderId) { - return this.folderUnreadCount[folderId]; - } + FeedResource.prototype.getUnreadCount = function () { + return this.unreadCount; + }; - getByFolderId (folderId) { - return this.folderIds[folderId] || []; - } + FeedResource.prototype.getFolderUnreadCount = function (folderId) { + return this.folderUnreadCount[folderId]; + }; - getById (feedId) { - return this.ids[feedId]; - } + FeedResource.prototype.getByFolderId = function (folderId) { + return this.folderIds[folderId] || []; + }; - rename (url, name) { - let feed = this.get(url); - feed.title = name; - return this.http({ - method: 'POST', - url: `${this.BASE_URL}/feeds/${feed.id}/rename`, - data: { - feedTitle: name - } - }); - } + FeedResource.prototype.getById = function (feedId) { + return this.ids[feedId]; + }; - move (url, folderId) { - let feed = this.get(url); - feed.folderId = folderId; + FeedResource.prototype.rename = function (url, name) { + var feed = this.get(url); + feed.title = name; - this.updateFolderCache(); + return this.http({ + method: 'POST', + url: this.BASE_URL + '/feeds/' + feed.id + '/rename', + data: { + feedTitle: name + } + }); + }; - return this.http({ - method: 'POST', - url: `${this.BASE_URL}/feeds/${feed.id}/move`, - data: { - parentFolderId: folderId - } - }); - } + FeedResource.prototype.move = function (url, folderId) { + var feed = this.get(url); + feed.folderId = folderId; + this.updateFolderCache(); - create (url, folderId, title=null) { - if (title) { - title = title.toUpperCase(); + return this.http({ + method: 'POST', + url: this.BASE_URL + '/feeds/' + feed.id + '/move', + data: { + parentFolderId: folderId } + }); - let feed = { - url: url, - folderId: folderId, - title: title, - faviconLink: '../css/loading.gif' - }; + }; - if (!this.get(url)) { - this.add(feed); - } - this.updateFolderCache(); + FeedResource.prototype.create = function (url, folderId, title) { + if (title) { + title = title.toUpperCase(); + } - console.log(feed); + var feed = { + url: url, + folderId: folderId, + title: title, + faviconLink: '../css/loading.gif' + }; - /*return this.http({ - method: 'POST', - url: `${this.BASE_URL}/feeds`, - data: { - url: url, - parentFolderId: folderId, - title: title - } - });*/ + if (!this.get(url)) { + this.add(feed); } + this.updateFolderCache(); - undoDelete () { - if (this.deleted) { - this.add(this.deleted); + console.log(feed); - return this.http.post( - `${this.BASE_URL}/feeds/${this.deleted.id}/restore` - ); + /*return this.http({ + method: 'POST', + url: this.BASE_URL + '/feeds', + data: { + url: url, + parentFolderId: folderId, + title: title } + });*/ + }; + + + FeedResource.prototype.undoDelete = function () { + if (this.deleted) { + this.add(this.deleted); - this.updateFolderCache(); - this.updateUnreadCache(); + return this.http.post( + this.BASE_URL + '/feeds/${this.deleted.id}/restore' + ); } + this.updateFolderCache(); + this.updateUnreadCache(); + }; - } return new FeedResource($http, BASE_URL); });
\ No newline at end of file |