From 33219e2211b9a91c0436902771eb83e1e9f5964b Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 7 Feb 2013 12:16:47 +0100 Subject: fixed grunt compile errors in .4 --- js/app.js | 2807 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 1392 insertions(+), 1415 deletions(-) (limited to 'js') diff --git a/js/app.js b/js/app.js index fe4b04f5f..7308db3df 100644 --- a/js/app.js +++ b/js/app.js @@ -9,16 +9,15 @@ * */ -(function(angular, $, OC, oc_requesttoken){ - - /* # ownCloud # # @author Bernhard Posselt # Copyright (c) 2012 - Bernhard Posselt # -# This file is licensed under the Affero General Public License version 3 or later. +# This file is licensed under the Affero General Public License version 3 or +# later. +# # See the COPYING-README file # */ @@ -53,7 +52,59 @@ # @author Bernhard Posselt # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. + # This file is licensed under the Affero General Public License version 3 or + # later. + # + # See the COPYING-README file + # + */ + + + /* + # Used for properly distributing received model data from the server + */ + + + angular.module('OC').factory('_Publisher', function() { + var Publisher; + Publisher = (function() { + + function Publisher() { + this.subscriptions = {}; + } + + Publisher.prototype.subscribeModelTo = function(model, name) { + var _base; + (_base = this.subscriptions)[name] || (_base[name] = []); + return this.subscriptions[name].push(model); + }; + + Publisher.prototype.publishDataTo = function(data, name) { + var subscriber, _i, _len, _ref, _results; + _ref = this.subscriptions[name] || []; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + subscriber = _ref[_i]; + _results.push(subscriber.handle(data)); + } + return _results; + }; + + return Publisher; + + })(); + return Publisher; + }); + + /* + # ownCloud + # + # @author Bernhard Posselt + # Copyright (c) 2012 - Bernhard Posselt + # + # This file is licensed under the Affero General Public License version 3 or + # later. + # # See the COPYING-README file # */ @@ -165,165 +216,9 @@ # @author Bernhard Posselt # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # - */ - - - angular.module('OC').factory('_Model', function() { - var Model; - Model = (function() { - - function Model() { - this.foreignKeys = {}; - this.data = []; - this.ids = {}; - } - - Model.prototype.handle = function(data) { - var item, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results; - if (data['create'] !== void 0) { - _ref = data['create']; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - item = _ref[_i]; - this.create(item); - } - } - if (data['update'] !== void 0) { - _ref1 = data['update']; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - item = _ref1[_j]; - this.update(item); - } - } - if (data['delete'] !== void 0) { - _ref2 = data['delete']; - _results = []; - for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { - item = _ref2[_k]; - _results.push(this["delete"](item)); - } - return _results; - } - }; - - Model.prototype.hasForeignKey = function(name) { - return this.foreignKeys[name] = {}; - }; - - Model.prototype.create = function(data) { - var id, ids, name, _base, _ref, _results; - if (this.ids[data.id] !== void 0) { - return this.update(data); - } else { - this.data.push(data); - this.ids[data.id] = data; - _ref = this.foreignKeys; - _results = []; - for (name in _ref) { - ids = _ref[name]; - id = data[name]; - (_base = this.foreignKeys[name])[id] || (_base[id] = []); - _results.push(this.foreignKeys[name][id].push(data)); - } - return _results; - } - }; - - Model.prototype.update = function(item) { - var currentItem, key, value, _results; - currentItem = this.ids[item.id]; - _results = []; - for (key in item) { - value = item[key]; - if (this.foreignKeys[key] !== void 0) { - if (value !== currentItem[key]) { - this._updateForeignKeyCache(key, currentItem, item); - } - } - if (key !== 'id') { - _results.push(currentItem[key] = value); - } else { - _results.push(void 0); - } - } - return _results; - }; - - Model.prototype["delete"] = function(item) { - if (this.getById(item.id) !== void 0) { - return this.removeById(item.id); - } - }; - - Model.prototype._updateForeignKeyCache = function(name, currentItem, toItem) { - var foreignKeyItems, fromValue, toValue; - fromValue = currentItem[name]; - toValue = toItem[name]; - foreignKeyItems = this.foreignKeys[name][fromValue]; - this._removeForeignKeyCacheItem(foreignKeyItems, currentItem); - return this.foreignKeys[name][toValue].push(item); - }; - - Model.prototype._removeForeignKeyCacheItem = function(foreignKeyItems, item) { - var fkItem, index, _i, _len, _results; - _results = []; - for (index = _i = 0, _len = foreignKeyItems.length; _i < _len; index = ++_i) { - fkItem = foreignKeyItems[index]; - if (fkItem.id === id) { - _results.push(this.foreignKeys[key][item[key]].splice(index, 1)); - } else { - _results.push(void 0); - } - } - return _results; - }; - - Model.prototype.removeById = function(id) { - var foreignKeyItems, ids, index, item, key, _i, _len, _ref, _ref1; - item = this.getById(id); - _ref = this.foreignKeys; - for (key in _ref) { - ids = _ref[key]; - foreignKeyItems = ids[item[key]]; - this._removeForeignKeyCacheItem(foreignKeyItems, item); - } - _ref1 = this.data; - for (index = _i = 0, _len = _ref1.length; _i < _len; index = ++_i) { - item = _ref1[index]; - if (item.id === id) { - this.data.splice(index, 1); - } - } - return delete this.ids[id]; - }; - - Model.prototype.getById = function(id) { - return this.ids[id]; - }; - - Model.prototype.getAll = function() { - return this.data; - }; - - Model.prototype.getAllOfForeignKeyWithId = function(foreignKeyName, foreignKeyId) { - return this.foreignKeys[foreignKeyName][foreignKeyId]; - }; - - return Model; - - })(); - return Model; - }); - - /* - # ownCloud - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt + # This file is licensed under the Affero General Public License version 3 or + # later. # - # This file is licensed under the Affero General Public License version 3 or later. # See the COPYING-README file # */ @@ -338,64 +233,20 @@ return OC.Router; }); - /* - # ownCloud - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt - # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # - */ - - - /* - # Used for properly distributing received model data from the server - */ - - - angular.module('OC').factory('_Publisher', function() { - var Publisher; - Publisher = (function() { - - function Publisher() { - this.subscriptions = {}; - } - - Publisher.prototype.subscribeModelTo = function(model, name) { - var _base; - (_base = this.subscriptions)[name] || (_base[name] = []); - return this.subscriptions[name].push(model); - }; - - Publisher.prototype.publishDataTo = function(data, name) { - var subscriber, _i, _len, _ref, _results; - _ref = this.subscriptions[name] || []; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - subscriber = _ref[_i]; - _results.push(subscriber.handle(data)); - } - return _results; - }; - - return Publisher; - - })(); - return Publisher; - }); - }).call(this); /* -# ownCloud - News app +# ownCloud news app # +# @author Alessandro Cosentino # @author Bernhard Posselt +# Copyright (c) 2012 - Alessandro Cosentino # Copyright (c) 2012 - Bernhard Posselt # -# This file is licensed under the Affero General Public License version 3 or later. +# This file is licensed under the Affero General Public License version 3 or +# later. +# # See the COPYING-README file # */ @@ -436,1395 +287,1314 @@ }); /* - # ownCloud - News app + # ownCloud news app # + # @author Alessandro Cosentino # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. + # This file is licensed under the Affero General Public License version 3 or + # later. + # # See the COPYING-README file # */ - angular.module('News').factory('_ShowAll', function() { - var ShowAll; - ShowAll = (function() { + angular.module('News').factory('_ActiveFeed', function() { + var ActiveFeed; + ActiveFeed = (function() { - function ShowAll() { - this.showAll = false; + function ActiveFeed() { + this.id = 0; + this.type = 3; } - ShowAll.prototype.handle = function(data) { - return this.showAll = data; + ActiveFeed.prototype.handle = function(data) { + this.id = data.id; + return this.type = data.type; }; - return ShowAll; + return ActiveFeed; })(); - return ShowAll; + return ActiveFeed; }); /* - # ownCloud - News app + # ownCloud news app # + # @author Alessandro Cosentino # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. + # This file is licensed under the Affero General Public License version 3 or + # later. + # # See the COPYING-README file # */ - angular.module('News').factory('_ItemModel', [ - 'Model', function(Model) { - var ItemModel; - ItemModel = (function(_super) { - - __extends(ItemModel, _super); - - function ItemModel(cache, feedType) { - this.cache = cache; - this.feedType = feedType; - ItemModel.__super__.constructor.call(this); - } + angular.module('News').factory('_Cache', function() { + var Cache; + Cache = (function() { - ItemModel.prototype.clearCache = function() { - this.cache.clear(); - return ItemModel.__super__.clearCache.call(this); - }; + function Cache(feedType, feedModel, folderModel) { + this.feedType = feedType; + this.feedModel = feedModel; + this.folderModel = folderModel; + this.clear(); + } - ItemModel.prototype.add = function(item) { - item = this.bindAdditional(item); - if (ItemModel.__super__.add.call(this, item)) { - return this.cache.add(this.getItemById(item.id)); - } - }; + Cache.prototype.clear = function() { + this.feedCache = []; + this.folderCache = {}; + this.folderCacheLastModified = 0; + this.importantCache = []; + this.highestId = 0; + this.lowestId = 0; + this.highestTimestamp = 0; + this.lowestTimestamp = 0; + this.highestIds = {}; + this.lowestIds = {}; + this.highestTimestamps = {}; + return this.lowestTimestamps = {}; + }; - ItemModel.prototype.bindAdditional = function(item) { - item.getRelativeDate = function() { - return moment.unix(this.date).fromNow(); - }; - item.getAuthorLine = function() { - if (this.author !== null && this.author.trim() !== "") { - return "by " + this.author; - } else { - return ""; - } - }; - return item; - }; - - ItemModel.prototype.removeById = function(itemId) { - var item; - item = this.getItemById(itemId); - if (item !== void 0) { - this.cache.remove(item); - return ItemModel.__super__.removeById.call(this, itemId); - } - }; - - ItemModel.prototype.getHighestId = function(type, id) { - return this.cache.getHighestId(type, id); - }; - - ItemModel.prototype.getHighestTimestamp = function(type, id) { - return this.cache.getHighestTimestamp(type, id); - }; - - ItemModel.prototype.getLowestId = function(type, id) { - return this.cache.getLowestId(type, id); - }; - - ItemModel.prototype.getLowestTimestamp = function(type, id) { - return this.cache.getLowestTimestamp(type, id); - }; - - ItemModel.prototype.getFeedsOfFolderId = function(id) { - return this.cache.getFeedsOfFolderId(id); - }; - - ItemModel.prototype.getItemsByTypeAndId = function(type, id) { - var feedId, items, _i, _len, _ref; - switch (type) { - case this.feedType.Feed: - items = this.cache.getItemsOfFeed(id) || []; - return items; - case this.feedType.Subscriptions: - return this.getItems(); - case this.feedType.Folder: - items = []; - _ref = this.cache.getFeedIdsOfFolder(id); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - feedId = _ref[_i]; - items = items.concat(this.cache.getItemsOfFeed(feedId) || []); - } - return items; - case this.feedType.Starred: - return this.cache.getImportantItems(); - } - }; - - ItemModel.prototype.setImportant = function(itemId, isImportant) { - var item; - item = this.getItemById(itemId); - this.cache.setImportant(item, isImportant); - return item.isImportant = isImportant; - }; - - return ItemModel; - - })(Model); - return ItemModel; - } - ]); - - /* - # ownCloud - News app - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt - # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # - */ - - - angular.module('News').factory('_OPMLParser', function() { - var Feed, Folder, OPMLParser; - Feed = (function() { - - function Feed(name, url) { - this.name = name; - this.url = url; - } - - Feed.prototype.getName = function() { - return this.name; - }; - - Feed.prototype.getUrl = function() { - return this.url; - }; - - Feed.prototype.isFolder = function() { - return false; + Cache.prototype.add = function(item) { + if (!this.feedCache[item.feedId]) { + this.feedCache[item.feedId] = []; + } + this.feedCache[item.feedId].push(item); + if (this.highestTimestamp < item.date) { + this.highestTimestamp = item.date; + } + if (this.lowestTimestamp > item.date) { + this.lowestTimestamp = item.date; + } + if (this.highestId < item.id) { + this.highestId = item.id; + } + if (this.lowestId > item.id) { + this.lowestId = item.id; + } + if (item.isImportant) { + this.importantCache.push(item); + } + if (this.highestTimestamps[item.feedId] === void 0 || item.id > this.highestTimestamps[item.feedId]) { + this.highestTimestamps[item.feedId] = item.date; + } + if (this.lowestTimestamps[item.feedId] === void 0 || item.id > this.lowestTimestamps[item.feedId]) { + this.lowestTimestamps[item.feedId] = item.date; + } + if (this.highestIds[item.feedId] === void 0 || item.id > this.highestIds[item.feedId]) { + this.highestIds[item.feedId] = item.id; + } + if (this.lowestIds[item.feedId] === void 0 || item.id > this.lowestIds[item.feedId]) { + return this.lowestIds[item.feedId] = item.id; + } }; - return Feed; - - })(); - Folder = (function() { - - function Folder(name) { - this.name = name; - this.items = []; - } - - Folder.prototype.add = function(feed) { - return this.items.push(feed); + Cache.prototype.getItemsOfFeed = function(feedId) { + return this.feedCache[feedId]; }; - Folder.prototype.getItems = function() { - return this.items; + Cache.prototype.getFeedIdsOfFolder = function(folderId) { + this.buildFolderCache(folderId); + return this.folderCache[folderId]; }; - Folder.prototype.getName = function() { - return this.name; + Cache.prototype.getImportantItems = function() { + return this.importantCache; }; - Folder.prototype.isFolder = function() { - return true; + Cache.prototype.buildFolderCache = function(id) { + var feed, _i, _len, _ref, _results; + if (this.folderCacheLastModified !== this.feedModel.getLastModified()) { + this.folderCache = {}; + this.folderCacheLastModified = this.feedModel.getLastModified(); + } + if (this.folderCache[id] === void 0) { + this.folderCache[id] = []; + _ref = this.feedModel.getItems(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + feed = _ref[_i]; + if (feed.folderId === id) { + _results.push(this.folderCache[id].push(feed.id)); + } else { + _results.push(void 0); + } + } + return _results; + } }; - return Folder; - - })(); - OPMLParser = (function() { - - function OPMLParser() {} - - OPMLParser.prototype.parseXML = function(xml) { - var $root, $xml, structure; - $xml = $($.parseXML(xml)); - $root = $xml.find('body'); - structure = new Folder('root'); - this._recursivelyParse($root, structure); - return structure; + Cache.prototype.getFeedsOfFolderId = function(id) { + this.buildFolderCache(id); + return this.folderCache[id]; }; - OPMLParser.prototype._recursivelyParse = function($xml, structure) { - var $outline, feed, folder, outline, _i, _len, _ref, _results; - _ref = $xml.children('outline'); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - outline = _ref[_i]; - $outline = $(outline); - if ($outline.attr('type') !== void 0) { - feed = new Feed($outline.attr('text'), $outline.attr('xmlUrl')); - _results.push(structure.add(feed)); - } else { - folder = new Folder($outline.attr('text')); - structure.add(folder); - _results.push(this._recursivelyParse($outline, folder)); + Cache.prototype.removeItemInArray = function(id, array) { + var counter, element, removeItemIndex, _i, _len; + removeItemIndex = null; + counter = 0; + for (_i = 0, _len = array.length; _i < _len; _i++) { + element = array[_i]; + if (element.id === id) { + removeItemIndex = counter; + break; } + counter += 1; + } + if (removeItemIndex !== null) { + return array.splice(removeItemIndex, 1); } - return _results; }; - return OPMLParser; - - })(); - return OPMLParser; - }); - - /* - # ownCloud - News app - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt - # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # - */ - - - angular.module('News').factory('Loading', [ - '_Loading', function(_Loading) { - return new _Loading(); - } - ]); - - angular.module('News').factory('ActiveFeed', [ - '_ActiveFeed', 'Publisher', function(_ActiveFeed, Publisher) { - var model; - model = new _ActiveFeed(); - Publisher.subscribeTo('activeFeed', model); - return model; - } - ]); - - angular.module('News').factory('ShowAll', [ - '_ShowAll', 'Publisher', function(_ShowAll, Publisher) { - var model; - model = new _ShowAll(); - Publisher.subscribeTo('showAll', model); - return model; - } - ]); - - angular.module('News').factory('StarredCount', [ - '_StarredCount', 'Publisher', function(_StarredCount, Publisher) { - var model; - model = new _StarredCount(); - Publisher.subscribeTo('starredCount', model); - return model; - } - ]); - - angular.module('News').factory('FeedModel', [ - '_FeedModel', 'Publisher', function(_FeedModel, Publisher) { - var model; - model = new _FeedModel(); - Publisher.subscribeTo('feeds', model); - return model; - } - ]); - - angular.module('News').factory('FolderModel', [ - '_FolderModel', 'Publisher', function(_FolderModel, Publisher) { - var model; - model = new _FolderModel(); - Publisher.subscribeTo('folders', model); - return model; - } - ]); - - angular.module('News').factory('ItemModel', [ - '_ItemModel', 'Publisher', 'Cache', 'FeedType', function(_ItemModel, Publisher, Cache, FeedType) { - var model; - model = new _ItemModel(Cache, FeedType); - Publisher.subscribeTo('items', model); - return model; - } - ]); - - angular.module('News').factory('Cache', [ - '_Cache', 'FeedType', 'FeedModel', 'FolderModel', function(_Cache, FeedType, FeedModel, FolderModel) { - return new _Cache(FeedType, FeedModel, FolderModel); - } - ]); - - angular.module('News').factory('PersistenceNews', [ - '_PersistenceNews', '$http', '$rootScope', 'Loading', 'Publisher', function(_PersistenceNews, $http, $rootScope, Loading, Publisher) { - return new _PersistenceNews($http, $rootScope, Loading, Publisher); - } - ]); - - angular.module('News').factory('GarbageRegistry', [ - '_GarbageRegistry', 'ItemModel', function(_GarbageRegistry, ItemModel) { - return new _GarbageRegistry(ItemModel); - } - ]); - - angular.module('News').factory('Publisher', [ - '_Publisher', function(_Publisher) { - return new _Publisher(); - } - ]); - - angular.module('News').factory('OPMLParser', [ - '_OPMLParser', function(_OPMLParser) { - return new _OPMLParser(); - } - ]); - - /* - # ownCloud - News app - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt - # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # - */ - - - angular.module('News').factory('_ActiveFeed', function() { - var ActiveFeed; - ActiveFeed = (function() { - - function ActiveFeed() { - this.id = 0; - this.type = 3; - } - - ActiveFeed.prototype.handle = function(data) { - this.id = data.id; - return this.type = data.type; + Cache.prototype.remove = function(item) { + this.removeItemInArray(item.id, this.feedCache[item.feedId]); + return this.removeItemInArray(item.id, this.importantCache); }; - return ActiveFeed; - - })(); - return ActiveFeed; - }); - - /* - # ownCloud - News app - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt - # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # - */ - - - angular.module('News').factory('Persistence', function() { - var Persistence; - return Persistence = (function() { - - function Persistence(appName, $http) { - this.appName = appName; - this.$http = $http; - this.appInitialized = false; - this.shelvedRequests = []; - } - - Persistence.prototype.setInitialized = function(isInitialized) { - if (isInitialized) { - this.executePostRequests(); + Cache.prototype.setImportant = function(item, isImportant) { + if (isImportant) { + return this.importantCache.push(item); + } else { + return this.removeItemInArray(item.id, this.importantCache); } - return this.appInitialized = isInitialized; }; - Persistence.prototype.executePostRequests = function() { - var request, _i, _len, _ref; - _ref = this.shelvedRequests; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - request = _ref[_i]; - this.post(request.route, request.data, request.callback); - console.log(request); + Cache.prototype.getHighestId = function(type, id) { + if (this.isFeed(type)) { + return this.highestIds[id] || 0; + } else { + return this.highestId; } - return this.shelvedRequests = []; }; - Persistence.prototype.isInitialized = function() { - return this.appInitialized; + Cache.prototype.getHighestTimestamp = function(type, id) { + if (this.isFeed(type)) { + return this.highestTimestamps[id] || 0; + } else { + return this.highestTimestamp; + } }; - Persistence.prototype.post = function(route, data, callback, errorCallback, init, contentType) { - var headers, request, url; - if (data == null) { - data = {}; - } - if (init == null) { - init = false; - } - if (contentType == null) { - contentType = 'application/x-www-form-urlencoded'; - } - if (this.isInitialized === false && init === false) { - request = { - route: route, - data: data, - callback: callback - }; - this.shelvedRequests.push(request); - return; - } - if (!callback) { - callback = function() {}; - } - if (!errorCallback) { - errorCallback = function() {}; + Cache.prototype.getLowestId = function(type, id) { + if (this.isFeed(type)) { + return this.lowestIds[id] || 0; + } else { + return this.lowestId; + } + }; + + Cache.prototype.getLowestTimestamp = function(type, id) { + if (this.isFeed(type)) { + return this.lowestTimestamps[id] || 0; + } else { + return this.lowestTimestamp; } - url = OC.Router.generate("news_ajax_" + route); - data = $.param(data); - headers = { - requesttoken: oc_requesttoken, - 'Content-Type': 'application/x-www-form-urlencoded' - }; - return this.$http.post(url, data, { - headers: headers - }).success(function(data, status, headers, config) { - if (data.status === "error") { - return errorCallback(data.msg); - } else { - return callback(data); - } - }).error(function(data, status, headers, config) { - console.warn('Error occured: '); - console.warn(status); - console.warn(headers); - return console.warn(config); - }); }; - return Persistence; + Cache.prototype.isFeed = function(type) { + return type === this.feedType.Feed; + }; + + return Cache; })(); + return Cache; }); /* - # ownCloud - News app + # ownCloud news app # + # @author Alessandro Cosentino # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. + # This file is licensed under the Affero General Public License version 3 or + # later. + # # See the COPYING-README file # */ - angular.module('News').factory('_FolderModel', [ - 'Model', function(Model, $rootScope) { - var FolderModel; - FolderModel = (function(_super) { + angular.module('News').factory('_FeedModel', [ + 'Model', function(Model) { + var FeedModel; + FeedModel = (function(_super) { - __extends(FolderModel, _super); + __extends(FeedModel, _super); - function FolderModel() { - FolderModel.__super__.constructor.call(this); + function FeedModel() { + FeedModel.__super__.constructor.call(this); } - return FolderModel; + FeedModel.prototype.add = function(item) { + return FeedModel.__super__.add.call(this, this.bindAdditional(item)); + }; + + FeedModel.prototype.bindAdditional = function(item) { + if (item.icon === "url()") { + item.icon = 'url(' + OC.imagePath('news', 'rss.svg') + ')'; + } + return item; + }; + + return FeedModel; })(Model); - return FolderModel; + return FeedModel; } ]); /* - # ownCloud - News app + # ownCloud news app # + # @author Alessandro Cosentino # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. + # This file is licensed under the Affero General Public License version 3 or + # later. + # # See the COPYING-README file # */ - angular.module('News').factory('_PersistenceNews', [ - 'Persistence', function(Persistence) { - var PersistenceNews; - PersistenceNews = (function(_super) { - - __extends(PersistenceNews, _super); - - function PersistenceNews($http, $rootScope, loading, publisher) { - this.$rootScope = $rootScope; - this.loading = loading; - this.publisher = publisher; - PersistenceNews.__super__.constructor.call(this, 'news', $http); - } - - PersistenceNews.prototype.updateModels = function(data) { - var type, value, _results; - _results = []; - for (type in data) { - value = data[type]; - _results.push(this.publisher.publish(type, value)); - } - return _results; - }; + angular.module('News').factory('FeedType', function() { + var feedType; + return feedType = { + Feed: 0, + Folder: 1, + Starred: 2, + Subscriptions: 3, + Shared: 4 + }; + }); - PersistenceNews.prototype.loadInitial = function() { - var _this = this; - this.loading.loading += 1; - return OC.Router.registerLoadedCallback(function() { - return _this.post('init', {}, function(json) { - _this.loading.loading -= 1; - _this.updateModels(json.data); - _this.$rootScope.$broadcast('triggerHideRead'); - return _this.setInitialized(true); - }, null, true); - }); - }; + /* + # ownCloud news app + # + # @author Alessandro Cosentino + # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino + # Copyright (c) 2012 - Bernhard Posselt + # + # This file is licensed under the Affero General Public License version 3 or + # later. + # + # See the COPYING-README file + # + */ - PersistenceNews.prototype.loadFeed = function(type, id, latestFeedId, latestTimestamp, limit) { - var data, - _this = this; - if (limit == null) { - limit = 20; - } - data = { - type: type, - id: id, - latestFeedId: latestFeedId, - latestTimestamp: latestTimestamp, - limit: limit - }; - this.loading.loading += 1; - return this.post('loadfeed', data, function(json) { - _this.loading.loading -= 1; - return _this.updateModels(json.data); - }); - }; - PersistenceNews.prototype.createFeed = function(feedUrl, folderId, onSuccess, onError) { - var data, - _this = this; - data = { - feedUrl: feedUrl, - folderId: folderId - }; - return this.post('createfeed', data, function(json) { - onSuccess(json.data); - return _this.updateModels(json.data); - }, onError); - }; + angular.module('News').factory('_FolderModel', [ + 'Model', function(Model, $rootScope) { + var FolderModel; + FolderModel = (function(_super) { - PersistenceNews.prototype.deleteFeed = function(feedId, onSuccess) { - var data; - data = { - feedId: feedId - }; - return this.post('deletefeed', data, onSuccess); - }; + __extends(FolderModel, _super); - PersistenceNews.prototype.moveFeedToFolder = function(feedId, folderId) { - var data; - data = { - feedId: feedId, - folderId: folderId - }; - return this.post('movefeedtofolder', data); - }; + function FolderModel() { + FolderModel.__super__.constructor.call(this); + } - PersistenceNews.prototype.createFolder = function(folderName, onSuccess) { - var data, - _this = this; - data = { - folderName: folderName - }; - return this.post('createfolder', data, function(json) { - onSuccess(json.data); - return _this.updateModels(json.data); - }); - }; + return FolderModel; - PersistenceNews.prototype.deleteFolder = function(folderId) { - var data; - data = { - folderId: folderId - }; - return this.post('deletefolder', data); - }; + })(Model); + return FolderModel; + } + ]); - PersistenceNews.prototype.changeFolderName = function(folderId, newFolderName) { - var data; - data = { - folderId: folderId, - newFolderName: newFolderName - }; - return this.post('folderName', data); - }; + /* + # ownCloud news app + # + # @author Alessandro Cosentino + # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino + # Copyright (c) 2012 - Bernhard Posselt + # + # This file is licensed under the Affero General Public License version 3 or + # later. + # + # See the COPYING-README file + # + */ - PersistenceNews.prototype.showAll = function(isShowAll) { - var data; - data = { - showAll: isShowAll - }; - return this.post('setshowall', data); - }; - PersistenceNews.prototype.markRead = function(itemId, isRead) { - var data, status; - if (isRead) { - status = 'read'; - } else { - status = 'unread'; - } - data = { - itemId: itemId, - status: status - }; - return this.post('setitemstatus', data); - }; + angular.module('News').factory('_GarbageRegistry', function() { + var GarbageRegistry; + GarbageRegistry = (function() { - PersistenceNews.prototype.setImportant = function(itemId, isImportant) { - var data, status; - if (isImportant) { - status = 'important'; - } else { - status = 'unimportant'; - } - data = { - itemId: itemId, - status: status - }; - return this.post('setitemstatus', data); - }; + function GarbageRegistry(itemModel) { + this.itemModel = itemModel; + this.registeredItemIds = {}; + } - PersistenceNews.prototype.collapseFolder = function(folderId, value) { - var data; - data = { - folderId: folderId, - opened: value - }; - return this.post('collapsefolder', data); - }; + GarbageRegistry.prototype.register = function(item) { + var itemId; + itemId = item.id; + return this.registeredItemIds[itemId] = item; + }; - PersistenceNews.prototype.updateFeed = function(feedId) { - var data, - _this = this; - data = { - feedId: feedId - }; - return this.post('updatefeed', data, function(json) { - return _this.updateModels(json.data); - }); - }; + GarbageRegistry.prototype.unregister = function(item) { + var itemId; + itemId = item.id; + return delete this.registeredItemIds[itemId]; + }; - PersistenceNews.prototype.setAllItemsRead = function(feedId, mostRecentItemId) { - var data; - data = { - feedId: feedId, - mostRecentItemId: mostRecentItemId - }; - return this.post('setallitemsread', data); - }; + GarbageRegistry.prototype.clear = function() { + var id, item, _ref; + _ref = this.registeredItemIds; + for (id in _ref) { + item = _ref[id]; + if (!item.keptUnread) { + this.itemModel.removeById(parseInt(id, 10)); + } + item.keptUnread = false; + } + return this.registeredItemIds = {}; + }; - return PersistenceNews; + return GarbageRegistry; - })(Persistence); - return PersistenceNews; - } - ]); + })(); + return GarbageRegistry; + }); /* - # ownCloud - News app + # ownCloud news app # + # @author Alessandro Cosentino # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. + # This file is licensed under the Affero General Public License version 3 or + # later. + # # See the COPYING-README file # */ - angular.module('News').factory('Model', function() { - var Model; - Model = (function() { + angular.module('News').factory('_ItemModel', [ + 'Model', function(Model) { + var ItemModel; + ItemModel = (function(_super) { - function Model() { - this.clearCache(); - } + __extends(ItemModel, _super); - Model.prototype.handle = function(data) { - var item, _i, _len, _results; - _results = []; - for (_i = 0, _len = data.length; _i < _len; _i++) { - item = data[_i]; - _results.push(this.add(item)); + function ItemModel(cache, feedType) { + this.cache = cache; + this.feedType = feedType; + ItemModel.__super__.constructor.call(this); } - return _results; - }; - - Model.prototype.clearCache = function() { - this.items = []; - this.itemIds = {}; - return this.markAccessed(); - }; - Model.prototype.markAccessed = function() { - return this.lastAccessed = new Date().getTime(); - }; + ItemModel.prototype.clearCache = function() { + this.cache.clear(); + return ItemModel.__super__.clearCache.call(this); + }; - Model.prototype.getLastModified = function() { - return this.lastAccessed; - }; + ItemModel.prototype.add = function(item) { + item = this.bindAdditional(item); + if (ItemModel.__super__.add.call(this, item)) { + return this.cache.add(this.getItemById(item.id)); + } + }; - Model.prototype.add = function(item) { - if (this.itemIds[item.id] === void 0) { - this.items.push(item); - this.itemIds[item.id] = item; - this.markAccessed(); - return true; - } else { - this.update(item); - return false; - } - }; + ItemModel.prototype.bindAdditional = function(item) { + item.getRelativeDate = function() { + return moment.unix(this.date).fromNow(); + }; + item.getAuthorLine = function() { + if (this.author !== null && this.author.trim() !== "") { + return "by " + this.author; + } else { + return ""; + } + }; + return item; + }; - Model.prototype.update = function(item) { - var key, updatedItem, value; - updatedItem = this.itemIds[item.id]; - for (key in item) { - value = item[key]; - if (key !== 'id') { - updatedItem[key] = value; + ItemModel.prototype.removeById = function(itemId) { + var item; + item = this.getItemById(itemId); + if (item !== void 0) { + this.cache.remove(item); + return ItemModel.__super__.removeById.call(this, itemId); } - } - return this.markAccessed(); - }; + }; - Model.prototype.removeById = function(id) { - var counter, item, removeItemIndex, _i, _len, _ref; - removeItemIndex = null; - counter = 0; - _ref = this.items; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - item = _ref[_i]; - if (item.id === id) { - removeItemIndex = counter; - break; - } - counter += 1; - } - if (removeItemIndex !== null) { - this.items.splice(removeItemIndex, 1); - delete this.itemIds[id]; - } - return this.markAccessed(); - }; + ItemModel.prototype.getHighestId = function(type, id) { + return this.cache.getHighestId(type, id); + }; - Model.prototype.getItemById = function(id) { - return this.itemIds[id]; - }; + ItemModel.prototype.getHighestTimestamp = function(type, id) { + return this.cache.getHighestTimestamp(type, id); + }; - Model.prototype.getItems = function() { - return this.items; - }; + ItemModel.prototype.getLowestId = function(type, id) { + return this.cache.getLowestId(type, id); + }; - return Model; + ItemModel.prototype.getLowestTimestamp = function(type, id) { + return this.cache.getLowestTimestamp(type, id); + }; - })(); - return Model; - }); + ItemModel.prototype.getFeedsOfFolderId = function(id) { + return this.cache.getFeedsOfFolderId(id); + }; + + ItemModel.prototype.getItemsByTypeAndId = function(type, id) { + var feedId, items, _i, _len, _ref; + switch (type) { + case this.feedType.Feed: + items = this.cache.getItemsOfFeed(id) || []; + return items; + case this.feedType.Subscriptions: + return this.getItems(); + case this.feedType.Folder: + items = []; + _ref = this.cache.getFeedIdsOfFolder(id); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + feedId = _ref[_i]; + items = items.concat(this.cache.getItemsOfFeed(feedId) || []); + } + return items; + case this.feedType.Starred: + return this.cache.getImportantItems(); + } + }; + + ItemModel.prototype.setImportant = function(itemId, isImportant) { + var item; + item = this.getItemById(itemId); + this.cache.setImportant(item, isImportant); + return item.isImportant = isImportant; + }; + + return ItemModel; + + })(Model); + return ItemModel; + } + ]); /* - # ownCloud - News app + # ownCloud news app # + # @author Alessandro Cosentino # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. + # This file is licensed under the Affero General Public License version 3 or + # later. + # # See the COPYING-README file # */ - angular.module('News').factory('_StarredCount', function() { - var StarredCount; - StarredCount = (function() { + angular.module('News').factory('_Loading', function() { + var Loading; + return Loading = (function() { - function StarredCount() { - this.count = 0; + function Loading() { + this.loading = 0; } - StarredCount.prototype.handle = function(data) { - return this.count = data; - }; - - return StarredCount; + return Loading; })(); - return StarredCount; }); /* - # ownCloud - News app + # ownCloud news app # + # @author Alessandro Cosentino # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. + # This file is licensed under the Affero General Public License version 3 or + # later. + # # See the COPYING-README file # */ - - angular.module('News').factory('FeedType', function() { - var feedType; - return feedType = { - Feed: 0, - Folder: 1, - Starred: 2, - Subscriptions: 3, - Shared: 4 - }; - }); - - angular.module('News').factory('_Cache', function() { - var Cache; - Cache = (function() { - - function Cache(feedType, feedModel, folderModel) { - this.feedType = feedType; - this.feedModel = feedModel; - this.folderModel = folderModel; - this.clear(); - } - - Cache.prototype.clear = function() { - this.feedCache = []; - this.folderCache = {}; - this.folderCacheLastModified = 0; - this.importantCache = []; - this.highestId = 0; - this.lowestId = 0; - this.highestTimestamp = 0; - this.lowestTimestamp = 0; - this.highestIds = {}; - this.lowestIds = {}; - this.highestTimestamps = {}; - return this.lowestTimestamps = {}; - }; - - Cache.prototype.add = function(item) { - if (!this.feedCache[item.feedId]) { - this.feedCache[item.feedId] = []; - } - this.feedCache[item.feedId].push(item); - if (this.highestTimestamp < item.date) { - this.highestTimestamp = item.date; - } - if (this.lowestTimestamp > item.date) { - this.lowestTimestamp = item.date; - } - if (this.highestId < item.id) { - this.highestId = item.id; - } - if (this.lowestId > item.id) { - this.lowestId = item.id; - } - if (item.isImportant) { - this.importantCache.push(item); - } - if (this.highestTimestamps[item.feedId] === void 0 || item.id > this.highestTimestamps[item.feedId]) { - this.highestTimestamps[item.feedId] = item.date; - } - if (this.lowestTimestamps[item.feedId] === void 0 || item.id > this.lowestTimestamps[item.feedId]) { - this.lowestTimestamps[item.feedId] = item.date; - } - if (this.highestIds[item.feedId] === void 0 || item.id > this.highestIds[item.feedId]) { - this.highestIds[item.feedId] = item.id; - } - if (this.lowestIds[item.feedId] === void 0 || item.id > this.lowestIds[item.feedId]) { - return this.lowestIds[item.feedId] = item.id; + + angular.module('News').factory('Model', function() { + var Model; + Model = (function() { + + function Model() { + this.clearCache(); + } + + Model.prototype.handle = function(data) { + var item, _i, _len, _results; + _results = []; + for (_i = 0, _len = data.length; _i < _len; _i++) { + item = data[_i]; + _results.push(this.add(item)); } + return _results; }; - Cache.prototype.getItemsOfFeed = function(feedId) { - return this.feedCache[feedId]; + Model.prototype.clearCache = function() { + this.items = []; + this.itemIds = {}; + return this.markAccessed(); }; - Cache.prototype.getFeedIdsOfFolder = function(folderId) { - this.buildFolderCache(folderId); - return this.folderCache[folderId]; + Model.prototype.markAccessed = function() { + return this.lastAccessed = new Date().getTime(); }; - Cache.prototype.getImportantItems = function() { - return this.importantCache; + Model.prototype.getLastModified = function() { + return this.lastAccessed; }; - Cache.prototype.buildFolderCache = function(id) { - var feed, _i, _len, _ref, _results; - if (this.folderCacheLastModified !== this.feedModel.getLastModified()) { - this.folderCache = {}; - this.folderCacheLastModified = this.feedModel.getLastModified(); - } - if (this.folderCache[id] === void 0) { - this.folderCache[id] = []; - _ref = this.feedModel.getItems(); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - feed = _ref[_i]; - if (feed.folderId === id) { - _results.push(this.folderCache[id].push(feed.id)); - } else { - _results.push(void 0); - } - } - return _results; + Model.prototype.add = function(item) { + if (this.itemIds[item.id] === void 0) { + this.items.push(item); + this.itemIds[item.id] = item; + this.markAccessed(); + return true; + } else { + this.update(item); + return false; } }; - Cache.prototype.getFeedsOfFolderId = function(id) { - this.buildFolderCache(id); - return this.folderCache[id]; + Model.prototype.update = function(item) { + var key, updatedItem, value; + updatedItem = this.itemIds[item.id]; + for (key in item) { + value = item[key]; + if (key !== 'id') { + updatedItem[key] = value; + } + } + return this.markAccessed(); }; - Cache.prototype.removeItemInArray = function(id, array) { - var counter, element, removeItemIndex, _i, _len; + Model.prototype.removeById = function(id) { + var counter, item, removeItemIndex, _i, _len, _ref; removeItemIndex = null; counter = 0; - for (_i = 0, _len = array.length; _i < _len; _i++) { - element = array[_i]; - if (element.id === id) { + _ref = this.items; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + item = _ref[_i]; + if (item.id === id) { removeItemIndex = counter; break; } counter += 1; } if (removeItemIndex !== null) { - return array.splice(removeItemIndex, 1); - } - }; - - Cache.prototype.remove = function(item) { - this.removeItemInArray(item.id, this.feedCache[item.feedId]); - return this.removeItemInArray(item.id, this.importantCache); - }; - - Cache.prototype.setImportant = function(item, isImportant) { - if (isImportant) { - return this.importantCache.push(item); - } else { - return this.removeItemInArray(item.id, this.importantCache); - } - }; - - Cache.prototype.getHighestId = function(type, id) { - if (this.isFeed(type)) { - return this.highestIds[id] || 0; - } else { - return this.highestId; - } - }; - - Cache.prototype.getHighestTimestamp = function(type, id) { - if (this.isFeed(type)) { - return this.highestTimestamps[id] || 0; - } else { - return this.highestTimestamp; - } - }; - - Cache.prototype.getLowestId = function(type, id) { - if (this.isFeed(type)) { - return this.lowestIds[id] || 0; - } else { - return this.lowestId; + this.items.splice(removeItemIndex, 1); + delete this.itemIds[id]; } + return this.markAccessed(); }; - Cache.prototype.getLowestTimestamp = function(type, id) { - if (this.isFeed(type)) { - return this.lowestTimestamps[id] || 0; - } else { - return this.lowestTimestamp; - } + Model.prototype.getItemById = function(id) { + return this.itemIds[id]; }; - Cache.prototype.isFeed = function(type) { - return type === this.feedType.Feed; + Model.prototype.getItems = function() { + return this.items; }; - return Cache; + return Model; })(); - return Cache; + return Model; }); /* - # ownCloud - News app + # ownCloud news app # + # @author Alessandro Cosentino # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. + # This file is licensed under the Affero General Public License version 3 or + # later. + # # See the COPYING-README file # */ - angular.module('News').factory('_Publisher', function() { - var Publisher; - Publisher = (function() { + angular.module('News').factory('_OPMLParser', function() { + var Feed, Folder, OPMLParser; + Feed = (function() { - function Publisher() { - this.subscriptions = {}; + function Feed(name, url) { + this.name = name; + this.url = url; } - Publisher.prototype.subscribeTo = function(type, object) { - var _base; - (_base = this.subscriptions)[type] || (_base[type] = []); - return this.subscriptions[type].push(object); + Feed.prototype.getName = function() { + return this.name; }; - Publisher.prototype.publish = function(type, message) { - var subscriber, _i, _len, _ref, _results; - _ref = this.subscriptions[type] || []; + Feed.prototype.getUrl = function() { + return this.url; + }; + + Feed.prototype.isFolder = function() { + return false; + }; + + return Feed; + + })(); + Folder = (function() { + + function Folder(name) { + this.name = name; + this.items = []; + } + + Folder.prototype.add = function(feed) { + return this.items.push(feed); + }; + + Folder.prototype.getItems = function() { + return this.items; + }; + + Folder.prototype.getName = function() { + return this.name; + }; + + Folder.prototype.isFolder = function() { + return true; + }; + + return Folder; + + })(); + OPMLParser = (function() { + + function OPMLParser() {} + + OPMLParser.prototype.parseXML = function(xml) { + var $root, $xml, structure; + $xml = $($.parseXML(xml)); + $root = $xml.find('body'); + structure = new Folder('root'); + this._recursivelyParse($root, structure); + return structure; + }; + + OPMLParser.prototype._recursivelyParse = function($xml, structure) { + var $outline, feed, folder, outline, _i, _len, _ref, _results; + _ref = $xml.children('outline'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { - subscriber = _ref[_i]; - _results.push(subscriber.handle(message)); + outline = _ref[_i]; + $outline = $(outline); + if ($outline.attr('type') !== void 0) { + feed = new Feed($outline.attr('text'), $outline.attr('xmlUrl')); + _results.push(structure.add(feed)); + } else { + folder = new Folder($outline.attr('text')); + structure.add(folder); + _results.push(this._recursivelyParse($outline, folder)); + } } return _results; }; - return Publisher; + return OPMLParser; })(); - return Publisher; + return OPMLParser; }); /* - # ownCloud - News app + # ownCloud news app # + # @author Alessandro Cosentino # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. + # This file is licensed under the Affero General Public License version 3 or + # later. + # # See the COPYING-README file # */ - angular.module('News').factory('_Loading', function() { - var Loading; - return Loading = (function() { + angular.module('News').factory('Persistence', function() { + var Persistence; + return Persistence = (function() { - function Loading() { - this.loading = 0; + function Persistence(appName, $http) { + this.appName = appName; + this.$http = $http; + this.appInitialized = false; + this.shelvedRequests = []; } - return Loading; + Persistence.prototype.setInitialized = function(isInitialized) { + if (isInitialized) { + this.executePostRequests(); + } + return this.appInitialized = isInitialized; + }; + + Persistence.prototype.executePostRequests = function() { + var request, _i, _len, _ref; + _ref = this.shelvedRequests; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + request = _ref[_i]; + this.post(request.route, request.data, request.callback); + console.log(request); + } + return this.shelvedRequests = []; + }; + + Persistence.prototype.isInitialized = function() { + return this.appInitialized; + }; + + Persistence.prototype.post = function(route, data, callback, errorCallback, init, contentType) { + var headers, request, url; + if (data == null) { + data = {}; + } + if (init == null) { + init = false; + } + if (contentType == null) { + contentType = 'application/x-www-form-urlencoded'; + } + if (this.isInitialized === false && init === false) { + request = { + route: route, + data: data, + callback: callback + }; + this.shelvedRequests.push(request); + return; + } + if (!callback) { + callback = function() {}; + } + if (!errorCallback) { + errorCallback = function() {}; + } + url = OC.Router.generate("news_ajax_" + route); + data = $.param(data); + headers = { + requesttoken: oc_requesttoken, + 'Content-Type': 'application/x-www-form-urlencoded' + }; + return this.$http.post(url, data, { + headers: headers + }).success(function(data, status, headers, config) { + if (data.status === "error") { + return errorCallback(data.msg); + } else { + return callback(data); + } + }).error(function(data, status, headers, config) { + console.warn('Error occured: '); + console.warn(status); + console.warn(headers); + return console.warn(config); + }); + }; + + return Persistence; })(); }); /* - # ownCloud - News app + # ownCloud news app # + # @author Alessandro Cosentino # @author Bernhard Posselt + # Copyright (c) 2012 - Alessandro Cosentino # Copyright (c) 2012 - Bernhard Posselt # - # This file is licensed under the Affero General Public License version 3 or later. + # This file is licensed under the Affero General Public License version 3 or + # later. + # # See the COPYING-README file # */ - angular.module('News').factory('_GarbageRegistry', function() { - var GarbageRegistry; - GarbageRegistry = (function() { + angular.module('News').factory('_PersistenceNews', [ + 'Persistence', function(Persistence) { + var PersistenceNews; + PersistenceNews = (function(_super) { - function GarbageRegistry(itemModel) { - this.itemModel = itemModel; - this.registeredItemIds = {}; - } + __extends(PersistenceNews, _super); - GarbageRegistry.prototype.register = function(item) { - var itemId; - itemId = item.id; - return this.registeredItemIds[itemId] = item; - }; + function PersistenceNews($http, $rootScope, loading, publisher) { + this.$rootScope = $rootScope; + this.loading = loading; + this.publisher = publisher; + PersistenceNews.__super__.constructor.call(this, 'news', $http); + } - GarbageRegistry.prototype.unregister = function(item) { - var itemId; - itemId = item.id; - return delete this.registeredItemIds[itemId]; - }; + PersistenceNews.prototype.updateModels = function(data) { + var type, value, _results; + _results = []; + for (type in data) { + value = data[type]; + _results.push(this.publisher.publish(type, value)); + } + return _results; + }; - GarbageRegistry.prototype.clear = function() { - var id, item, _ref; - _ref = this.registeredItemIds; - for (id in _ref) { - item = _ref[id]; - if (!item.keptUnread) { - this.itemModel.removeById(parseInt(id, 10)); + PersistenceNews.prototype.loadInitial = function() { + var _this = this; + this.loading.loading += 1; + return OC.Router.registerLoadedCallback(function() { + return _this.post('init', {}, function(json) { + _this.loading.loading -= 1; + _this.updateModels(json.data); + _this.$rootScope.$broadcast('triggerHideRead'); + return _this.setInitialized(true); + }, null, true); + }); + }; + + PersistenceNews.prototype.loadFeed = function(type, id, latestFeedId, latestTimestamp, limit) { + var data, + _this = this; + if (limit == null) { + limit = 20; } - item.keptUnread = false; - } - return this.registeredItemIds = {}; - }; + data = { + type: type, + id: id, + latestFeedId: latestFeedId, + latestTimestamp: latestTimestamp, + limit: limit + }; + this.loading.loading += 1; + return this.post('loadfeed', data, function(json) { + _this.loading.loading -= 1; + return _this.updateModels(json.data); + }); + }; - return GarbageRegistry; + PersistenceNews.prototype.createFeed = function(feedUrl, folderId, onSuccess, onError) { + var data, + _this = this; + data = { + feedUrl: feedUrl, + folderId: folderId + }; + return this.post('createfeed', data, function(json) { + onSuccess(json.data); + return _this.updateModels(json.data); + },