diff options
Diffstat (limited to 'js/build/app/services/businesslayer/feedbusinesslayer.js')
-rw-r--r-- | js/build/app/services/businesslayer/feedbusinesslayer.js | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/js/build/app/services/businesslayer/feedbusinesslayer.js b/js/build/app/services/businesslayer/feedbusinesslayer.js new file mode 100644 index 000000000..31a04adb5 --- /dev/null +++ b/js/build/app/services/businesslayer/feedbusinesslayer.js @@ -0,0 +1,233 @@ +// Generated by CoffeeScript 1.6.3 +/* + +ownCloud - News + +@author Bernhard Posselt +@copyright 2012 Bernhard Posselt dev@bernhard-posselt.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() { + var __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + angular.module('News').factory('FeedBusinessLayer', [ + '_BusinessLayer', 'ShowAll', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', 'FeedModel', 'NewLoading', '_ExistsError', 'Utils', '$rootScope', 'NewestItem', function(_BusinessLayer, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, FeedModel, NewLoading, _ExistsError, Utils, $rootScope, NewestItem) { + var FeedBusinessLayer; + FeedBusinessLayer = (function(_super) { + __extends(FeedBusinessLayer, _super); + + function FeedBusinessLayer(_showAll, _feedModel, persistence, activeFeed, feedType, itemModel, _newLoading, _utils, _$rootScope, _newestItem) { + this._showAll = _showAll; + this._feedModel = _feedModel; + this._newLoading = _newLoading; + this._utils = _utils; + this._$rootScope = _$rootScope; + this._newestItem = _newestItem; + FeedBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, feedType.Feed); + this._feedType = feedType; + } + + FeedBusinessLayer.prototype.getUnreadCount = function(feedId) { + return this._feedModel.getFeedUnreadCount(feedId); + }; + + FeedBusinessLayer.prototype.getFeedsOfFolder = function(folderId) { + return this._feedModel.getAllOfFolder(folderId); + }; + + FeedBusinessLayer.prototype.getFolderUnreadCount = function(folderId) { + return this._feedModel.getFolderUnreadCount(folderId); + }; + + FeedBusinessLayer.prototype.getAllUnreadCount = function() { + return this._feedModel.getUnreadCount(); + }; + + FeedBusinessLayer.prototype["delete"] = function(feedId) { + var data, feed, + _this = this; + feed = this._feedModel.removeById(feedId); + data = { + undoCallback: function() { + _this._persistence.restoreFeed(feedId, function() {}); + return _this._persistence.getAllFeeds(); + }, + caption: feed.title + }; + this._$rootScope.$broadcast('undoMessage', data); + return this._persistence.deleteFeed(feedId); + }; + + FeedBusinessLayer.prototype.markRead = function(feedId) { + var feed, item, newestItemId, _i, _len, _ref; + feed = this._feedModel.getById(feedId); + newestItemId = this._newestItem.getId(); + if (angular.isDefined(feed) && newestItemId !== 0) { + feed.unreadCount = 0; + _ref = this._itemModel.getAll(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + item = _ref[_i]; + if (item.feedId === feed.id) { + item.setRead(); + } + } + return this._persistence.setFeedRead(feedId, newestItemId); + } + }; + + FeedBusinessLayer.prototype.getNumberOfFeeds = function() { + return this._feedModel.size(); + }; + + FeedBusinessLayer.prototype.noFeeds = function() { + return this.getNumberOfFeeds() === 0; + }; + + FeedBusinessLayer.prototype.isVisible = function(feedId) { + if (this.isActive(feedId) || this._showAll.getShowAll()) { + return true; + } else { + return this._feedModel.getFeedUnreadCount(feedId) > 0; + } + }; + + FeedBusinessLayer.prototype.move = function(feedId, folderId) { + var feed; + feed = this._feedModel.getById(feedId); + if (angular.isDefined(feed) && feed.folderId !== folderId) { + this._feedModel.update({ + id: feedId, + folderId: folderId, + url: feed.url + }); + return this._persistence.moveFeed(feedId, folderId); + } + }; + + FeedBusinessLayer.prototype.setShowAll = function(showAll) { + var callback, + _this = this; + this._showAll.setShowAll(showAll); + callback = function() { + _this._itemModel.clear(); + _this._newLoading.increase(); + return _this._persistence.getItems(_this._activeFeed.getType(), _this._activeFeed.getId(), 0, function() { + return _this._newLoading.decrease(); + }); + }; + if (showAll) { + return this._persistence.userSettingsReadShow(callback); + } else { + return this._persistence.userSettingsReadHide(callback); + } + }; + + FeedBusinessLayer.prototype.isShowAll = function() { + return this._showAll.getShowAll(); + }; + + FeedBusinessLayer.prototype.getAll = function() { + return this._feedModel.getAll(); + }; + + FeedBusinessLayer.prototype.getFeedLink = function(feedId) { + var feed; + feed = this._feedModel.getById(feedId); + if (angular.isDefined(feed)) { + return feed.link; + } + }; + + FeedBusinessLayer.prototype.create = function(url, parentId, onSuccess, onFailure) { + var feed, success, + _this = this; + if (parentId == null) { + parentId = 0; + } + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + onFailure || (onFailure = function() {}); + parentId = parseInt(parentId, 10); + if (angular.isUndefined(url) || url.trim() === '') { + throw new Error('Url must not be empty'); + } + url = url.trim(); + if (url.indexOf('http') !== 0) { + url = 'http://' + url; + } + if (this._feedModel.getByUrl(url)) { + throw new _ExistsError('Exists already'); + } + feed = { + title: url, + url: url, + folderId: parentId, + unreadCount: 0, + faviconLink: 'url(' + this._utils.imagePath('core', 'loading.gif') + ')' + }; + this._feedModel.add(feed); + success = function(response) { + if (response.status === 'error') { + feed.error = response.msg; + return onFailure(); + } else { + return onSuccess(response.data); + } + }; + return this._persistence.createFeed(url, parentId, success); + }; + + FeedBusinessLayer.prototype.markErrorRead = function(url) { + return this._feedModel.removeByUrl(url); + }; + + FeedBusinessLayer.prototype.importGoogleReader = function(json) { + var feed, onSuccess, url, + _this = this; + url = 'http://owncloud/googlereader'; + if (angular.isUndefined(this._feedModel.getByUrl(url))) { + feed = { + title: 'Google Reader', + url: url, + folderId: 0, + unreadCount: 0, + faviconLink: 'url(' + this._utils.imagePath('core', 'loading.gif') + ')' + }; + this._feedModel.add(feed); + } + onSuccess = function(response) { + var id; + id = response.data.feeds[0].id; + return _this.load(id); + }; + return this._persistence.importGoogleReader(json, onSuccess); + }; + + return FeedBusinessLayer; + + })(_BusinessLayer); + return new FeedBusinessLayer(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType, ItemModel, NewLoading, Utils, $rootScope, NewestItem); + } + ]); + +}).call(this); |