diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-09-11 20:26:04 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-09-11 20:26:04 +0200 |
commit | f3091d84e14537a42334e66ea6588cf2b83f9ab6 (patch) | |
tree | 943151aa564177e956d5dc1b2fff12845e48c4c0 | |
parent | f50dba835fa58f9ba979a9038ffd185ab8fe3b96 (diff) |
various work on creating feeds, folders and showing folders
-rw-r--r-- | js/build/app.js | 131 | ||||
-rw-r--r-- | js/build/app.min.js | 2 | ||||
-rw-r--r-- | js/controller/NavigationController.js | 54 | ||||
-rw-r--r-- | js/service/FeedResource.js | 33 | ||||
-rw-r--r-- | js/service/FolderResource.js | 42 | ||||
-rw-r--r-- | js/tests/unit/controller/NavigationControllerSpec.js | 160 | ||||
-rw-r--r-- | js/tests/unit/service/FeedResourceSpec.js | 40 | ||||
-rw-r--r-- | js/tests/unit/service/FolderResourceSpec.js | 25 | ||||
-rw-r--r-- | js/tests/unit/stubs/OC.js | 4 | ||||
-rw-r--r-- | templates/part.navigation.addfeed.php | 4 | ||||
-rw-r--r-- | templates/part.navigation.feed.php | 14 | ||||
-rw-r--r-- | templates/part.navigation.folder.php | 92 |
12 files changed, 430 insertions, 171 deletions
diff --git a/js/build/app.js b/js/build/app.js index 75c0a9f87..9fe66bf6f 100644 --- a/js/build/app.js +++ b/js/build/app.js @@ -331,8 +331,8 @@ app.controller('ContentController', }]); app.controller('NavigationController', -["$route", "FEED_TYPE", "FeedResource", "FolderResource", "ItemResource", "SettingsResource", function ($route, FEED_TYPE, FeedResource, FolderResource, ItemResource, - SettingsResource) { +["$route", "FEED_TYPE", "FeedResource", "FolderResource", "ItemResource", "SettingsResource", "Publisher", function ($route, FEED_TYPE, FeedResource, FolderResource, ItemResource, + SettingsResource, Publisher) { 'use strict'; this.feedError = ''; @@ -435,32 +435,58 @@ app.controller('NavigationController', }; this.folderNameExists = function (folderName) { - return FolderResource.get(folderName) !== undefined; + folderName = folderName || ''; + return FolderResource.get(folderName.toUpperCase()) !== undefined; }; - // TBD - this.isAddingFolder = function () { - return true; + this.createFeed = function (feed) { + this.newFolder = false; + + var self = this; + + // we dont need to create a new folder + if (feed.folder === undefined) { + FeedResource.create(feed.url, feed.folderId, undefined) + .then(function (data) { + Publisher.publishAll(data); + }); + } else { + // create folder first and then the feed + FolderResource.create(feed.folder).then(function (data) { + Publisher.publishAll(data); + + self.createFeed({ + url: feed.url, + folderId: data.name + }); + + feed.folderId = data.name; + feed.folder = ''; + }); + } + + feed.url = ''; }; this.createFolder = function (folder) { - console.log(folder.name); + FolderResource.create(folder.name).then(function (data) { + Publisher.publishAll(data); + }); folder.name = ''; }; - this.createFeed = function (feed) { - this.newFolder = false; - console.log(feed.url + feed.folder); - feed.url = ''; + this.moveFeed = function (feedId, folderId) { + FeedResource.move(feedId, folderId); }; + // TBD this.renameFeed = function (feed) { feed.editing = false; // todo remote stuff }; - this.renameFolder = function () { - console.log('TBD'); + this.renameFolder = function (folder) { + console.log(folder); }; this.deleteFeed = function (feed) { @@ -481,8 +507,8 @@ app.controller('NavigationController', console.log(folderName); }; - this.moveFeed = function (feedId, folderId) { - console.log(feedId + folderId); + this.removeFolder = function (folder) { + console.log('remove ' + folder); }; }]); @@ -546,16 +572,17 @@ app.filter('unreadCountFormatter', function () { return unreadCount; }; }); -app.factory('FeedResource', ["Resource", "$http", "BASE_URL", function (Resource, $http, BASE_URL) { +app.factory('FeedResource', ["Resource", "$http", "BASE_URL", "$q", function (Resource, $http, BASE_URL, $q) { 'use strict'; - var FeedResource = function ($http, BASE_URL) { + var FeedResource = function ($http, BASE_URL, $q) { Resource.call(this, $http, BASE_URL, 'url'); this.ids = {}; this.unreadCount = 0; this.folderUnreadCount = {}; this.folderIds = {}; this.deleted = null; + this.$q = $q; }; FeedResource.prototype = Object.create(Resource.prototype); @@ -702,8 +729,8 @@ app.factory('FeedResource', ["Resource", "$http", "BASE_URL", function (Resource }; - FeedResource.prototype.move = function (url, folderId) { - var feed = this.get(url); + FeedResource.prototype.move = function (feedId, folderId) { + var feed = this.getById(feedId); feed.folderId = folderId; this.updateFolderCache(); @@ -724,11 +751,12 @@ app.factory('FeedResource', ["Resource", "$http", "BASE_URL", function (Resource title = title.toUpperCase(); } + // FIXME: use OC.generateUrl() var feed = { url: url, - folderId: folderId, + folderId: folderId || 0, title: title, - faviconLink: '../css/loading.gif' + faviconLink: OC.generateUrl('/apps/news/css/loading.gif') }; if (!this.get(url)) { @@ -737,17 +765,24 @@ app.factory('FeedResource', ["Resource", "$http", "BASE_URL", function (Resource this.updateFolderCache(); - console.log(feed); + var deferred = this.$q.defer(); - return this.http({ + this.http({ method: 'POST', url: this.BASE_URL + '/feeds', data: { - url: url, - parentFolderId: folderId, - title: title + url: feed.url, + parentFolderId: feed.folderId, + title: feed.title } + }).success(function (data) { + deferred.resolve(data); + }).error(function (data) { + feed.faviconLink = ''; + feed.error = data.message; }); + + return deferred.promise; }; @@ -765,14 +800,15 @@ app.factory('FeedResource', ["Resource", "$http", "BASE_URL", function (Resource }; - return new FeedResource($http, BASE_URL); + return new FeedResource($http, BASE_URL, $q); }]); -app.factory('FolderResource', ["Resource", "$http", "BASE_URL", function (Resource, $http, BASE_URL) { +app.factory('FolderResource', ["Resource", "$http", "BASE_URL", "$q", function (Resource, $http, BASE_URL, $q) { 'use strict'; - var FolderResource = function ($http, BASE_URL) { + var FolderResource = function ($http, BASE_URL, $q) { Resource.call(this, $http, BASE_URL, 'name'); this.deleted = null; + this.$q = $q; }; FolderResource.prototype = Object.create(Resource.prototype); @@ -806,15 +842,13 @@ app.factory('FolderResource', ["Resource", "$http", "BASE_URL", function (Resour toFolderName = toFolderName.toUpperCase(); var folder = this.get(folderName); - // still do http request if folder exists but dont change the name - // to have one point of failure - if (!this.get(toFolderName)) { - folder.name = toFolderName; + folder.name = toFolderName; - delete this.hashMap[folderName]; - this.hashMap[toFolderName] = folder; - } + delete this.hashMap[folderName]; + this.hashMap[toFolderName] = folder; + // FIXME: check for errors + // FIXME: transfer feeds return this.http({ url: this.BASE_URL + '/folders/' + folder.id + '/rename', method: 'POST', @@ -828,27 +862,32 @@ app.factory('FolderResource', ["Resource", "$http", "BASE_URL", function (Resour FolderResource.prototype.create = function (folderName) { folderName = folderName.toUpperCase(); - // still do http request if folder exists but dont change the name - // to have one point of failure - if (!this.get(folderName)) { - var folder = { - name: folderName - }; + var folder = { + name: folderName + }; - this.add(folder); - } + this.add(folder); - return this.http({ + var deferred = this.$q.defer(); + + this.http({ url: this.BASE_URL + '/folders', method: 'POST', data: { folderName: folderName } + }).success(function (data) { + deferred.resolve(data); + }).error(function (data) { + folder.error = data.message; }); + + return deferred.promise; }; FolderResource.prototype.undoDelete = function () { + // TODO: check for errors if (this.deleted) { this.add(this.deleted); @@ -859,7 +898,7 @@ app.factory('FolderResource', ["Resource", "$http", "BASE_URL", function (Resour }; - return new FolderResource($http, BASE_URL); + return new FolderResource($http, BASE_URL, $q); }]); app.factory('ItemResource', ["Resource", "$http", "BASE_URL", "ITEM_BATCH_SIZE", function (Resource, $http, BASE_URL, ITEM_BATCH_SIZE) { diff --git a/js/build/app.min.js b/js/build/app.min.js index 82adb48b4..e36bb21b0 100644 --- a/js/build/app.min.js +++ b/js/build/app.min.js @@ -1 +1 @@ -!function(a,b,c,d,e,f,g){"use strict";var h=c.module("News",["ngRoute","ngSanitize","ngAnimate"]);h.config(["$routeProvider","$provide","$httpProvider",function(a,b,c){var d={FEED:0,FOLDER:1,STARRED:2,SUBSCRIPTIONS:3,SHARED:4};b.constant("REFRESH_RATE",60),b.constant("ITEM_BATCH_SIZE",50),b.constant("BASE_URL",e.generateUrl("/apps/news")),b.constant("FEED_TYPE",d),b.factory("CSRFInterceptor",["$q","BASE_URL",function(a,b){return{request:function(c){return 0===c.url.indexOf(b)&&(c.headers.requesttoken=f),c||a.when(c)}}}]),c.interceptors.push("CSRFInterceptor");var h=function(a){return{data:["$http","$route","$q","BASE_URL","ITEM_BATCH_SIZE",function(b,c,d,e,f){var h={type:a,limit:f};c.current.params.id!==g&&(h.id=c.current.params.id);var i=d.defer();return b({url:e+"/items",method:"GET",params:h}).success(function(a){i.resolve(a)}),i.promise}]}};a.when("/items",{controller:"ContentController as Content",templateUrl:"content.html",resolve:h(d.SUBSCRIPTIONS),type:d.SUBSCRIPTIONS}).when("/items/starred",{controller:"ContentController as Content",templateUrl:"content.html",resolve:h(d.STARRED),type:d.STARRED}).when("/items/feeds/:id",{controller:"ContentController as Content",templateUrl:"content.html",resolve:h(d.FEED),type:d.FEED}).when("/items/folders/:id",{controller:"ContentController as Content",templateUrl:"content.html",resolve:h(d.FOLDER),type:d.FOLDER})}]),h.run(["$rootScope","$location","$http","$q","$interval","Loading","ItemResource","FeedResource","FolderResource","SettingsResource","Publisher","BASE_URL","FEED_TYPE","REFRESH_RATE",function(a,b,c,d,e,f,g,h,i,j,k,l,m,n){f.setLoading("global",!0),k.subscribe(g).toChannels(["items","newestItemId","starred"]),k.subscribe(i).toChannels(["folders"]),k.subscribe(h).toChannels(["feeds"]),k.subscribe(j).toChannels(["settings"]);var o=d.defer();c.get(l+"/settings").success(function(a){k.publishAll(a),o.resolve()});var p=d.defer(),q=b.path();c.get(l+"/feeds/active").success(function(a){var c;switch(a.activeFeed.type){case m.FEED:c="/items/feeds/"+a.activeFeed.id;break;case m.FOLDER:c="/items/folders/"+a.activeFeed.id;break;case m.STARRED:c="/items/starred";break;default:c="/items"}/^\/items(\/(starred|feeds\/\d+|folders\/\d+))?\/?$/.test(q)||b.path(c),p.resolve()});var r=d.defer();c.get(l+"/folders").success(function(a){k.publishAll(a),r.resolve()});var s=d.defer();c.get(l+"/feeds").success(function(a){k.publishAll(a),s.resolve()}),d.all([o.promise,p.promise,s.promise,r.promise]).then(function(){f.setLoading("global",!1)}),e(function(){c.get(l+"/feeds"),c.get(l+"/folders")},1e3*n),a.$on("$routeChangeStart",function(){f.setLoading("content",!0)}),a.$on("$routeChangeSuccess",function(){f.setLoading("content",!1)}),a.$on("$routeChangeError",function(){b.path("/items")})}]),h.controller("AppController",["Loading","FeedResource","FolderResource",function(a,b,c){this.loading=a,this.isFirstRun=function(){return 0===b.size()&&0===c.size()}}]),h.controller("ContentController",["Publisher","FeedResource","ItemResource","SettingsResource","data","$route","$routeParams",function(a,b,c,d,e,f,h){c.clear(),a.publishAll(e),this.isAutoPagingEnabled=!0,this.getItems=function(){return c.getAll()},this.toggleStar=function(a){c.toggleStar(a)},this.toggleItem=function(a){this.isCompactView()&&(a.show=!a.show)},this.markRead=function(a){var d=c.get(a);d.keepUnread||d.unread!==!0||(c.markItemRead(a),b.markItemOfFeedRead(d.feedId))},this.getFeed=function(a){return b.getById(a)},this.toggleKeepUnread=function(a){var d=c.get(a);d.unread||(b.markItemOfFeedUnread(d.feedId),c.markItemRead(a,!1)),d.keepUnread=!d.keepUnread},this.orderBy=function(){return d.get("oldestFirst")?"-id":"id"},this.isCompactView=function(){return d.get("compact")},this.autoPagingEnabled=function(){return this.isAutoPagingEnabled},this.markReadEnabled=function(){return!d.get("preventReadOnScroll")},this.scrollRead=function(a){var d=[],e=[];a.forEach(function(a){var b=c.get(a);b.keepUnread||(d.push(a),e.push(b.feedId))}),b.markItemsOfFeedsRead(e),c.markItemsRead(d)},this.autoPage=function(){this.isAutoPagingEnabled=!1;var b=f.current.$$route.type,d=h.id,e=this;c.autoPage(b,d).success(function(b){a.publishAll(b),b.items.length>0&&(e.isAutoPagingEnabled=!0)}).error(function(){e.isAutoPagingEnabled=!0})},this.getRelativeDate=function(a){if(a!==g&&""!==a){var b=d.get("language"),c=moment.unix(a).locale(b).fromNow()+"";return c}return""}}]),h.controller("NavigationController",["$route","FEED_TYPE","FeedResource","FolderResource","ItemResource","SettingsResource",function(a,b,c,d,e,f){this.feedError="",this.folderError="",this.getFeeds=function(){return c.getAll()},this.getFolders=function(){return d.getAll()},this.markFolderRead=function(a){c.markFolderRead(a),c.getByFolderId(a).forEach(function(a){e.markFeedRead(a.id)})},this.markFeedRead=function(a){e.markFeedRead(a),c.markFeedRead(a)},this.markRead=function(){e.markRead(),c.markRead()},this.isShowAll=function(){return f.get("showAll")},this.getFeedsOfFolder=function(a){return c.getByFolderId(a)},this.getUnreadCount=function(){return c.getUnreadCount()},this.getFeedUnreadCount=function(a){return c.getById(a).unreadCount},this.getFolderUnreadCount=function(a){return c.getFolderUnreadCount(a)},this.getStarredCount=function(){return e.getStarredCount()},this.toggleFolder=function(a){d.toggleOpen(a)},this.hasFeeds=function(a){return c.getFolderUnreadCount(a)!==g},this.subFeedActive=function(d){var e=a.current.$$route.type;if(e===b.FEED){var f=c.getById(a.current.params.id);if(f.folderId===d)return!0}return!1},this.isSubscriptionsActive=function(){return a.current&&a.current.$$route.type===b.SUBSCRIPTIONS},this.isStarredActive=function(){return a.current&&a.current.$$route.type===b.STARRED},this.isFolderActive=function(c){var d=parseInt(a.current.params.id,10);return a.current&&a.current.$$route.type===b.FOLDER&&d===c},this.isFeedActive=function(c){var d=parseInt(a.current.params.id,10);return a.current&&a.current.$$route.type===b.FEED&&d===c},this.folderNameExists=function(a){return d.get(a)!==g},this.isAddingFolder=function(){return!0},this.createFolder=function(a){console.log(a.name),a.name=""},this.createFeed=function(a){this.newFolder=!1,console.log(a.url+a.folder),a.url=""},this.renameFeed=function(a){a.editing=!1},this.renameFolder=function(){console.log("TBD")},this.deleteFeed=function(a){a.deleted=!0},this.undeleteFeed=function(a){a.deleted=!1},this.removeFeed=function(a){console.log("remove "+a)},this.deleteFolder=function(a){console.log(a)},this.moveFeed=function(a,b){console.log(a+b)}}]),h.controller("SettingsController",["$route","SettingsResource","FeedResource",function(a,b,c){this.importing=!1,this.opmlImportError=!1,this.articleImportError=!1;var d=function(c,d){b.set(c,d),["showAll","oldestFirst"].indexOf(c)>=0&&a.reload()};this.toggleSetting=function(a){d(a,!this.getSetting(a))},this.getSetting=function(a){return b.get(a)},this.feedSize=function(){return c.size()},this.importOpml=function(a){console.log(a)},this.importArticles=function(a){console.log(a)}}]),h.filter("trustUrl",["$sce",function(a){return function(b){return a.trustAsResourceUrl(b)}}]),h.filter("unreadCountFormatter",function(){return function(a){return a>999?"999+":a}}),h.factory("FeedResource",["Resource","$http","BASE_URL",function(a,b,c){var d=function(b,c){a.call(this,b,c,"url"),this.ids={},this.unreadCount=0,this.folderUnreadCount={},this.folderIds={},this.deleted=null};return d.prototype=Object.create(a.prototype),d.prototype.receive=function(b){a.prototype.receive.call(this,b),this.updateUnreadCache(),this.updateFolderCache()},d.prototype.updateUnreadCache=function(){this.unreadCount=0,this.folderUnreadCount={};var a=this;this.values.forEach(function(b){b.unreadCount&&(a.unreadCount+=b.unreadCount),b.folderId!==g&&(a.folderUnreadCount[b.folderId]=a.folderUnreadCount[b.folderId]||0,a.folderUnreadCount[b.folderId]+=b.unreadCount)})},d.prototype.updateFolderCache=function(){this.folderIds={};var a=this;this.values.forEach(function(b){a.folderIds[b.folderId]=a.folderIds[b.folderId]||[],a.folderIds[b.folderId].push(b)})},d.prototype.add=function(b){a.prototype.add.call(this,b),b.id!==g&&(this.ids[b.id]=this.hashMap[b.url])},d.prototype.delete=function(b){var c=this.get(b);return this.deleted=c,delete this.ids[c.id],a.prototype.delete.call(this,b),this.updateUnreadCache(),this.updateFolderCache(),this.http.delete(this.BASE_URL+"/feeds/"+c.id)},d.prototype.markRead=function(){this.values.forEach(function(a){a.unreadCount=0}),this.unreadCount=0,this.folderUnreadCount={}},d.prototype.markFeedRead=function(a){this.ids[a].unreadCount=0,this.updateUnreadCache()},d.prototype.markFolderRead=function(a){this.values.forEach(function(b){b.folderId===a&&(b.unreadCount=0)}),this.updateUnreadCache()},d.prototype.markItemOfFeedRead=function(a){this.ids[a].unreadCount-=1,this.updateUnreadCache()},d.prototype.markItemsOfFeedsRead=function(a){var b=this;a.forEach(function(a){b.ids[a].unreadCount-=1}),this.updateUnreadCache()},d.prototype.markItemOfFeedUnread=function(a){this.ids[a].unreadCount+=1,this.updateUnreadCache()},d.prototype.getUnreadCount=function(){return this.unreadCount},d.prototype.getFolderUnreadCount=function(a){return this.folderUnreadCount[a]},d.prototype.getByFolderId=function(a){return this.folderIds[a]||[]},d.prototype.getById=function(a){return this.ids[a]},d.prototype.rename=function(a,b){var c=this.get(a);return c.title=b,this.http({method:"POST",url:this.BASE_URL+"/feeds/"+c.id+"/rename",data:{feedTitle:b}})},d.prototype.move=function(a,b){var c=this.get(a);return c.folderId=b,this.updateFolderCache(),this.http({method:"POST",url:this.BASE_URL+"/feeds/"+c.id+"/move",data:{parentFolderId:b}})},d.prototype.create=function(a,b,c){c&&(c=c.toUpperCase());var d={url:a,folderId:b,title:c,faviconLink:"../css/loading.gif"};return this.get(a)||this.add(d),this.updateFolderCache(),console.log(d),this.http({method:"POST",url:this.BASE_URL+"/feeds",data:{url:a,parentFolderId:b,title:c}})},d.prototype.undoDelete=function(){return this.deleted?(this.add(this.deleted),this.http.post(this.BASE_URL+"/feeds/"+this.deleted.id+"/restore")):(this.updateFolderCache(),void this.updateUnreadCache())},new d(b,c)}]),h.factory("FolderResource",["Resource","$http","BASE_URL",function(a,b,c){var d=function(b,c){a.call(this,b,c,"name"),this.deleted=null};return d.prototype=Object.create(a.prototype),d.prototype.delete=function(b){var c=this.get(b);return this.deleted=c,a.prototype.delete.call(this,b),this.http.delete(this.BASE_URL+"/folders/"+c.id)},d.prototype.toggleOpen=function(a){var b=this.get(a);return b.opened=!b.opened,this.http({url:this.BASE_URL+"/folders/"+b.id+"/open",method:"POST",data:{folderId:b.id,open:b.opened}})},d.prototype.rename=function(a,b){b=b.toUpperCase();var c=this.get(a);return this.get(b)||(c.name=b,delete this.hashMap[a],this.hashMap[b]=c),this.http({url:this.BASE_URL+"/folders/"+c.id+"/rename",method:"POST",data:{folderName:b}})},d.prototype.create=function(a){if(a=a.toUpperCase(),!this.get(a)){var b={name:a};this.add(b)}return this.http({url:this.BASE_URL+"/folders",method:"POST",data:{folderName:a}})},d.prototype.undoDelete=function(){return this.deleted?(this.add(this.deleted),this.http.post(this.BASE_URL+"/folders/"+this.deleted.id+"/restore")):void 0},new d(b,c)}]),h.factory("ItemResource",["Resource","$http","BASE_URL","ITEM_BATCH_SIZE",function(a,b,c,d){var e=function(b,c,d){a.call(this,b,c),this.starredCount=0,this.batchSize=d};return e.prototype=Object.create(a.prototype),e.prototype.receive=function(b,c){switch(c){case"newestItemId":this.newestItemId=b;break;case"starred":this.starredCount=b;break;default:a.prototype.receive.call(this,b,c)}},e.prototype.getNewestItemId=function(){return this.newestItemId},e.prototype.getStarredCount=function(){return this.starredCount},e.prototype.star=function(a,b){b===g&&(b=!0);var c=this.get(a),d=this.BASE_URL+"/items/"+c.feedId+"/"+c.guidHash+"/star";return c.starred=b,b?this.starredCount+=1:this.starredCount-=1,this.http({url:d,method:"POST",data:{isStarred:b}})},e.prototype.toggleStar=function(a){this.get(a).starred?this.star(a,!1):this.star(a,!0)},e.prototype.markItemRead=function(a,b){return b===g&&(b=!0),this.get(a).unread=!b,this.http({url:this.BASE_URL+"/items/"+a+"/read",method:"POST",data:{isRead:b}})},e.prototype.markItemsRead=function(a){var b=this;return a.forEach(function(a){b.get(a).unread=!1}),this.http({url:this.BASE_URL+"/items/read/multiple",method:"POST",data:{itemIds:a}})},e.prototype.markFeedRead=function(a,b){b===g&&(b=!0);var c=this.values.filter(function(b){return b.feedId===a});return c.forEach(function(a){a.unread=!b}),this.http.post(this.BASE_URL+"/feeds/"+a+"/read")},e.prototype.markRead=function(){return this.values.forEach(function(a){a.unread=!1}),this.http.post(this.BASE_URL+"/items/read")},e.prototype.autoPage=function(a,b){return this.http({url:this.BASE_URL+"/items",method:"GET",params:{type:a,id:b,offset:this.size(),limit:this.batchSize}})},new e(b,c,d)}]),h.service("Loading",function(){this.loading={global:!1,content:!1,autopaging:!1},this.setLoading=function(a,b){this.loading[a]=b},this.isLoading=function(a){return this.loading[a]}}),h.service("Publisher",function(){this.channels={},this.subscribe=function(a){var b=this;return{toChannels:function(c){c.forEach(function(c){b.channels[c]=b.channels[c]||[],b.channels[c].push(a)})}}},this.publishAll=function(a){var b=this;Object.keys(a).forEach(function(c){var d=b.channels[c];d!==g&&d.forEach(function(b){b.receive(a[c],c)})})}}),h.factory("Resource",function(){var a=function(a,b,c){this.id=c||"id",this.values=[],this.hashMap={},this.http=a,this.BASE_URL=b};return a.prototype.receive=function(a){var b=this;a.forEach(function(a){b.add(a)})},a.prototype.add=function(a){var b=this.hashMap[a[this.id]];b===g?(this.values.push(a),this.hashMap[a[this.id]]=a):Object.keys(a).forEach(function(c){b[c]=a[c]})},a.prototype.size=function(){return this.values.length},a.prototype.get=function(a){return this.hashMap[a]},a.prototype.delete=function(a){var b=this,c=this.values.findIndex(function(c){return c[b.id]===a});c!==g&&this.values.splice(c,1),this.hashMap[a]!==g&&delete this.hashMap[a]},a.prototype.clear=function(){for(this.hashMap={};this.values.length>0;)this.values.pop()},a.prototype.getAll=function(){return this.values},a}),h.service("SettingsResource",["$http","BASE_URL",function(a,b){this.settings={language:"en",showAll:!1,compact:!1,oldestFirst:!1,preventReadOnScroll:!1},this.defaultLanguageCode="en",this.supportedLanguageCodes=["ar-ma","ar","bg","ca","cs","cv","da","de","el","en-ca","en-gb","eo","es","et","eu","fi","fr-ca","fr","gl","he","hi","hu","id","is","it","ja","ka","ko","lv","ms-my","nb","ne","nl","pl","pt-br","pt","ro","ru","sk","sl","sv","th","tr","tzm-la","tzm","uk","zh-cn","zh-tw"],this.receive=function(a){var b=this;Object.keys(a).forEach(function(c){var d=a[c];"language"===c&&(d=b.processLanguageCode(d)),b.settings[c]=d})},this.get=function(a){return this.settings[a]},this.set=function(c,d){return this.settings[c]=d,a({url:b+"/settings",method:"PUT",data:this.settings})},this.processLanguageCode=function(a){return a=a.replace("_","-").toLowerCase(),this.supportedLanguageCodes.indexOf(a)<0&&(a=a.split("-")[0]),this.supportedLanguageCodes.indexOf(a)<0&&(a=this.defaultLanguageCode),a}}]),function(a,b,c){var d=function(a){return!(a.is("input")||a.is("select")||a.is("textarea")||a.is("checkbox"))},e=function(a){return!(a.shiftKey||a.altKey||a.ctrlKey||a.metaKey)},f=function(a,b){b.scrollTop(a.offset().top-b.offset().top+b.scrollTop())},g=function(a){var b=a.find(".item");b.each(function(b,d){return d=c(d),d.position().top>1?(f(a,d),!1):void 0}),a.scrollTop(a.prop("scrollHeight"))},h=function(a){var b=a.find(".item");b.each(function(b,d){if(d=c(d),d.position().top>=0){var e=d.prev();return e.length>0&&f(a,e),!1}}),b.length>0&&f(a,b.last())},i=function(a){var b=a.find(".item");b.each(function(a,b){return b=c(b),b.height()+b.position().top>30?b:void 0})},j=function(a){var b=i(a);b.find(".keep-unread").trigger("click")},k=function(a){var b=i(a);b.find(".star").trigger("click")},l=function(a){var b=i(a);b.find(".title").trigger("click")},m=function(b){var c=i(b).find(".title a");c.trigger("click"),a.open(c.attr("href"),"_blank")};c(b).keyup(function(a){if(d(c(":focus"))&&e(a)){var b=a.keyCode,f=c("#app-content");[74,78,33].indexOf(b)>=0?(a.preventDefault(),g(f)):[75,80,37].indexOf(b)>=0?(a.preventDefault(),h(f)):[85].indexOf(b)>=0?(a.preventDefault(),j(f)):[69].indexOf(b)>=0?(a.preventDefault(),l(f)):[73,83,76].indexOf(b)>=0?(a.preventDefault(),k(f)):[72].indexOf(b)>=0?(a.preventDefault(),k(f),g(f)):[79].indexOf(b)>=0&&(a.preventDefault(),m(f))}})}(a,b,d),h.run(["$document","$rootScope",function(a,b){a.click(function(a){b.$broadcast("documentClicked",a)})}]),h.directive("appNavigationEntryUtils",function(){return{restrict:"C",link:function(a,b){var c=b.siblings(".app-navigation-entry-menu"),e=d(b).find(".app-navigation-entry-utils-menu-button button");e.click(function(){c.toggleClass("open")}),a.$on("documentClicked",function(a,b){b.target!==e[0]&&c.removeClass("open")})}}}),h.directive("newsAudio",function(){return{restrict:"E",scope:{src:"@",type:"@"},transclude:!0,template:'<audio controls="controls" preload="none" ng-hide="cantPlay()"><source ng-src="{{ src|trustUrl }}"></audio><a ng-href="{{ src|trustUrl }}" class="button" ng-show="cantPlay()" ng-transclude></a>',link:function(a,b){var c=b.children().children("source")[0],d=!1;c.addEventListener("error",function(){a.$apply(function(){d=!0})}),a.cantPlay=function(){return d}}}}),h.directive("newsAutoFocus",function(){return function(a,b,c){c.newsAutofocus?d(c.newsAutofocus).focus():b.focus()}}),h.directive("newsBindHtmlUnsafe",function(){return function(a,b,c){a.$watch(c.newsBindHtmlUnsafe,function(){b.html(a.$eval(c.newsBindHtmlUnsafe))})}}),h.directive("newsDraggable",function(){return function(a,b,d){var e=a.$eval(d.newsDraggable);c.isDefined(e)?b.draggable(e):b.draggable()}}),h.directive("newsDroppable",["$rootScope",function(a){return function(b,c,e){var f={accept:".feed",hoverClass:"drag-and-drop",greedy:!0,drop:function(f,g){d(".drag-and-drop").removeClass("drag-and-drop");var h={folderId:parseInt(c.data("id"),10),feedId:parseInt(d(g.draggable).data("id"),10)};a.$broadcast("moveFeedToFolder",h),b.$apply(e.droppable)}};c.droppable(f)}}]),h.directive("newsFocus",["$timeout","$interpolate",function(a,b){return function(c,e,f){e.click(function(){var e=d(b(f.newsFocus)(c));a(function(){e.focus()},500)})}}]),h.directive("newsReadFile",function(){return function(a,b,c){b.change(function(){var d=b[0].files[0],e=new FileReader;e.onload=function(d){b[0].value=0,a.$fileContent=d.target.result,a.$apply(c.newsReadFile)},e.readAsText(d)})}}),h.directive("newsScroll",["$timeout",function(a){var b=function(a,b,c,e){if(a)for(var f=0,g=c.find(".item"),h=g.length-1;h>=0;h-=1){var i=d(g[h]);if(f>=b)break;if(i.position().top<0){e.$apply(e.newsScrollAutoPage);break}f+=1}},c=function(a,b,c){if(a){var e=[],f=b.find(".item:not(.read)");f.each(function(a,b){var c=d(b);return c.position().top<=-50?void e.push(parseInt(c.data("id"),10)):!1}),c.itemIds=e,c.$apply(c.newsScrollMarkRead)}};return{restrict:"A",scope:{newsScrollAutoPage:"&",newsScrollMarkRead:"&",newsScrollEnabledMarkRead:"=",newsScrollEnabledAutoPage:"=",newsScrollMarkReadTimeout:"@",newsScrollTimeout:"@",newsScrollAutoPageWhenLeft:"@"},link:function(d,e){var f=!0,g=d.newsScrollTimeout||1,h=d.newsScrollMarkReadTimeout||1,i=d.newsScrollAutoPageWhenLeft||50,j=function(){f&&(f=!1,a(function(){f=!0},1e3*g),b(d.newsScrollEnabledAutoPage,i,e,d),a(function(){c(d.newsScrollEnabledMarkRead,e,d)},1e3*h))};e.on("scroll",j),d.$on("$destroy",function(){e.off("scroll",j)})}}}]),h.directive("newsStopPropagation",function(){return{restrict:"A",link:function(a,b){b.bind("click",function(a){a.stopPropagation()})}}}),h.directive("newsTimeout",["$timeout",function(a){return{restrict:"A",scope:{newsTimeout:"&"},link:function(b){var c=7,d=a(b.newsTimeout,1e3*c);b.$on("$destroy",function(){a.cancel(d)})}}}]),h.directive("newsTitleUnreadCount",["$window",function(a){var b=a.document.title;return{restrict:"E",scope:{unreadCount:"@"},link:function(c,d,e){e.$observe("unreadCount",function(c){var d=b.split("-");"0"!==c&&(a.document.title=d[0]+"("+c+") - "+d[1])})}}}]),h.directive("newsTriggerClick",function(){return function(a,b,c){b.click(function(){d(c.newsTriggerClick).trigger("click")})}})}(window,document,angular,jQuery,OC,oc_requesttoken);
\ No newline at end of file +!function(a,b,c,d,e,f,g){"use strict";var h=c.module("News",["ngRoute","ngSanitize","ngAnimate"]);h.config(["$routeProvider","$provide","$httpProvider",function(a,b,c){var d={FEED:0,FOLDER:1,STARRED:2,SUBSCRIPTIONS:3,SHARED:4};b.constant("REFRESH_RATE",60),b.constant("ITEM_BATCH_SIZE",50),b.constant("BASE_URL",e.generateUrl("/apps/news")),b.constant("FEED_TYPE",d),b.factory("CSRFInterceptor",["$q","BASE_URL",function(a,b){return{request:function(c){return 0===c.url.indexOf(b)&&(c.headers.requesttoken=f),c||a.when(c)}}}]),c.interceptors.push("CSRFInterceptor");var h=function(a){return{data:["$http","$route","$q","BASE_URL","ITEM_BATCH_SIZE",function(b,c,d,e,f){var h={type:a,limit:f};c.current.params.id!==g&&(h.id=c.current.params.id);var i=d.defer();return b({url:e+"/items",method:"GET",params:h}).success(function(a){i.resolve(a)}),i.promise}]}};a.when("/items",{controller:"ContentController as Content",templateUrl:"content.html",resolve:h(d.SUBSCRIPTIONS),type:d.SUBSCRIPTIONS}).when("/items/starred",{controller:"ContentController as Content",templateUrl:"content.html",resolve:h(d.STARRED),type:d.STARRED}).when("/items/feeds/:id",{controller:"ContentController as Content",templateUrl:"content.html",resolve:h(d.FEED),type:d.FEED}).when("/items/folders/:id",{controller:"ContentController as Content",templateUrl:"content.html",resolve:h(d.FOLDER),type:d.FOLDER})}]),h.run(["$rootScope","$location","$http","$q","$interval","Loading","ItemResource","FeedResource","FolderResource","SettingsResource","Publisher","BASE_URL","FEED_TYPE","REFRESH_RATE",function(a,b,c,d,e,f,g,h,i,j,k,l,m,n){f.setLoading("global",!0),k.subscribe(g).toChannels(["items","newestItemId","starred"]),k.subscribe(i).toChannels(["folders"]),k.subscribe(h).toChannels(["feeds"]),k.subscribe(j).toChannels(["settings"]);var o=d.defer();c.get(l+"/settings").success(function(a){k.publishAll(a),o.resolve()});var p=d.defer(),q=b.path();c.get(l+"/feeds/active").success(function(a){var c;switch(a.activeFeed.type){case m.FEED:c="/items/feeds/"+a.activeFeed.id;break;case m.FOLDER:c="/items/folders/"+a.activeFeed.id;break;case m.STARRED:c="/items/starred";break;default:c="/items"}/^\/items(\/(starred|feeds\/\d+|folders\/\d+))?\/?$/.test(q)||b.path(c),p.resolve()});var r=d.defer();c.get(l+"/folders").success(function(a){k.publishAll(a),r.resolve()});var s=d.defer();c.get(l+"/feeds").success(function(a){k.publishAll(a),s.resolve()}),d.all([o.promise,p.promise,s.promise,r.promise]).then(function(){f.setLoading("global",!1)}),e(function(){c.get(l+"/feeds"),c.get(l+"/folders")},1e3*n),a.$on("$routeChangeStart",function(){f.setLoading("content",!0)}),a.$on("$routeChangeSuccess",function(){f.setLoading("content",!1)}),a.$on("$routeChangeError",function(){b.path("/items")})}]),h.controller("AppController",["Loading","FeedResource","FolderResource",function(a,b,c){this.loading=a,this.isFirstRun=function(){return 0===b.size()&&0===c.size()}}]),h.controller("ContentController",["Publisher","FeedResource","ItemResource","SettingsResource","data","$route","$routeParams",function(a,b,c,d,e,f,h){c.clear(),a.publishAll(e),this.isAutoPagingEnabled=!0,this.getItems=function(){return c.getAll()},this.toggleStar=function(a){c.toggleStar(a)},this.toggleItem=function(a){this.isCompactView()&&(a.show=!a.show)},this.markRead=function(a){var d=c.get(a);d.keepUnread||d.unread!==!0||(c.markItemRead(a),b.markItemOfFeedRead(d.feedId))},this.getFeed=function(a){return b.getById(a)},this.toggleKeepUnread=function(a){var d=c.get(a);d.unread||(b.markItemOfFeedUnread(d.feedId),c.markItemRead(a,!1)),d.keepUnread=!d.keepUnread},this.orderBy=function(){return d.get("oldestFirst")?"-id":"id"},this.isCompactView=function(){return d.get("compact")},this.autoPagingEnabled=function(){return this.isAutoPagingEnabled},this.markReadEnabled=function(){return!d.get("preventReadOnScroll")},this.scrollRead=function(a){var d=[],e=[];a.forEach(function(a){var b=c.get(a);b.keepUnread||(d.push(a),e.push(b.feedId))}),b.markItemsOfFeedsRead(e),c.markItemsRead(d)},this.autoPage=function(){this.isAutoPagingEnabled=!1;var b=f.current.$$route.type,d=h.id,e=this;c.autoPage(b,d).success(function(b){a.publishAll(b),b.items.length>0&&(e.isAutoPagingEnabled=!0)}).error(function(){e.isAutoPagingEnabled=!0})},this.getRelativeDate=function(a){if(a!==g&&""!==a){var b=d.get("language"),c=moment.unix(a).locale(b).fromNow()+"";return c}return""}}]),h.controller("NavigationController",["$route","FEED_TYPE","FeedResource","FolderResource","ItemResource","SettingsResource","Publisher",function(a,b,c,d,e,f,h){this.feedError="",this.folderError="",this.getFeeds=function(){return c.getAll()},this.getFolders=function(){return d.getAll()},this.markFolderRead=function(a){c.markFolderRead(a),c.getByFolderId(a).forEach(function(a){e.markFeedRead(a.id)})},this.markFeedRead=function(a){e.markFeedRead(a),c.markFeedRead(a)},this.markRead=function(){e.markRead(),c.markRead()},this.isShowAll=function(){return f.get("showAll")},this.getFeedsOfFolder=function(a){return c.getByFolderId(a)},this.getUnreadCount=function(){return c.getUnreadCount()},this.getFeedUnreadCount=function(a){return c.getById(a).unreadCount},this.getFolderUnreadCount=function(a){return c.getFolderUnreadCount(a)},this.getStarredCount=function(){return e.getStarredCount()},this.toggleFolder=function(a){d.toggleOpen(a)},this.hasFeeds=function(a){return c.getFolderUnreadCount(a)!==g},this.subFeedActive=function(d){var e=a.current.$$route.type;if(e===b.FEED){var f=c.getById(a.current.params.id);if(f.folderId===d)return!0}return!1},this.isSubscriptionsActive=function(){return a.current&&a.current.$$route.type===b.SUBSCRIPTIONS},this.isStarredActive=function(){return a.current&&a.current.$$route.type===b.STARRED},this.isFolderActive=function(c){var d=parseInt(a.current.params.id,10);return a.current&&a.current.$$route.type===b.FOLDER&&d===c},this.isFeedActive=function(c){var d=parseInt(a.current.params.id,10);return a.current&&a.current.$$route.type===b.FEED&&d===c},this.folderNameExists=function(a){return a=a||"",d.get(a.toUpperCase())!==g},this.createFeed=function(a){this.newFolder=!1;var b=this;a.folder===g?c.create(a.url,a.folderId,g).then(function(a){h.publishAll(a)}):d.create(a.folder).then(function(c){h.publishAll(c),b.createFeed({url:a.url,folderId:c.name}),a.folderId=c.name,a.folder=""}),a.url=""},this.createFolder=function(a){d.create(a.name).then(function(a){h.publishAll(a)}),a.name=""},this.moveFeed=function(a,b){c.move(a,b)},this.renameFeed=function(a){a.editing=!1},this.renameFolder=function(a){console.log(a)},this.deleteFeed=function(a){a.deleted=!0},this.undeleteFeed=function(a){a.deleted=!1},this.removeFeed=function(a){console.log("remove "+a)},this.deleteFolder=function(a){console.log(a)},this.removeFolder=function(a){console.log("remove "+a)}}]),h.controller("SettingsController",["$route","SettingsResource","FeedResource",function(a,b,c){this.importing=!1,this.opmlImportError=!1,this.articleImportError=!1;var d=function(c,d){b.set(c,d),["showAll","oldestFirst"].indexOf(c)>=0&&a.reload()};this.toggleSetting=function(a){d(a,!this.getSetting(a))},this.getSetting=function(a){return b.get(a)},this.feedSize=function(){return c.size()},this.importOpml=function(a){console.log(a)},this.importArticles=function(a){console.log(a)}}]),h.filter("trustUrl",["$sce",function(a){return function(b){return a.trustAsResourceUrl(b)}}]),h.filter("unreadCountFormatter",function(){return function(a){return a>999?"999+":a}}),h.factory("FeedResource",["Resource","$http","BASE_URL","$q",function(a,b,c,d){var f=function(b,c,d){a.call(this,b,c,"url"),this.ids={},this.unreadCount=0,this.folderUnreadCount={},this.folderIds={},this.deleted=null,this.$q=d};return f.prototype=Object.create(a.prototype),f.prototype.receive=function(b){a.prototype.receive.call(this,b),this.updateUnreadCache(),this.updateFolderCache()},f.prototype.updateUnreadCache=function(){this.unreadCount=0,this.folderUnreadCount={};var a=this;this.values.forEach(function(b){b.unreadCount&&(a.unreadCount+=b.unreadCount),b.folderId!==g&&(a.folderUnreadCount[b.folderId]=a.folderUnreadCount[b.folderId]||0,a.folderUnreadCount[b.folderId]+=b.unreadCount)})},f.prototype.updateFolderCache=function(){this.folderIds={};var a=this;this.values.forEach(function(b){a.folderIds[b.folderId]=a.folderIds[b.folderId]||[],a.folderIds[b.folderId].push(b)})},f.prototype.add=function(b){a.prototype.add.call(this,b),b.id!==g&&(this.ids[b.id]=this.hashMap[b.url])},f.prototype.delete=function(b){var c=this.get(b);return this.deleted=c,delete this.ids[c.id],a.prototype.delete.call(this,b),this.updateUnreadCache(),this.updateFolderCache(),this.http.delete(this.BASE_URL+"/feeds/"+c.id)},f.prototype.markRead=function(){this.values.forEach(function(a){a.unreadCount=0}),this.unreadCount=0,this.folderUnreadCount={}},f.prototype.markFeedRead=function(a){this.ids[a].unreadCount=0,this.updateUnreadCache()},f.prototype.markFolderRead=function(a){this.values.forEach(function(b){b.folderId===a&&(b.unreadCount=0)}),this.updateUnreadCache()},f.prototype.markItemOfFeedRead=function(a){this.ids[a].unreadCount-=1,this.updateUnreadCache()},f.prototype.markItemsOfFeedsRead=function(a){var b=this;a.forEach(function(a){b.ids[a].unreadCount-=1}),this.updateUnreadCache()},f.prototype.markItemOfFeedUnread=function(a){this.ids[a].unreadCount+=1,this.updateUnreadCache()},f.prototype.getUnreadCount=function(){return this.unreadCount},f.prototype.getFolderUnreadCount=function(a){return this.folderUnreadCount[a]},f.prototype.getByFolderId=function(a){return this.folderIds[a]||[]},f.prototype.getById=function(a){return this.ids[a]},f.prototype.rename=function(a,b){var c=this.get(a);return c.title=b,this.http({method:"POST",url:this.BASE_URL+"/feeds/"+c.id+"/rename",data:{feedTitle:b}})},f.prototype.move=function(a,b){var c=this.getById(a);return c.folderId=b,this.updateFolderCache(),this.http({method:"POST",url:this.BASE_URL+"/feeds/"+c.id+"/move",data:{parentFolderId:b}})},f.prototype.create=function(a,b,c){c&&(c=c.toUpperCase());var d={url:a,folderId:b||0,title:c,faviconLink:e.generateUrl("/apps/news/css/loading.gif")};this.get(a)||this.add(d),this.updateFolderCache();var f=this.$q.defer();return this.http({method:"POST",url:this.BASE_URL+"/feeds",data:{url:d.url,parentFolderId:d.folderId,title:d.title}}).success(function(a){f.resolve(a)}).error(function(a){d.faviconLink="",d.error=a.message}),f.promise},f.prototype.undoDelete=function(){return this.deleted?(this.add(this.deleted),this.http.post(this.BASE_URL+"/feeds/"+this.deleted.id+"/restore")):(this.updateFolderCache(),void this.updateUnreadCache())},new f(b,c,d)}]),h.factory("FolderResource",["Resource","$http","BASE_URL","$q",function(a,b,c,d){var e=function(b,c,d){a.call(this,b,c,"name"),this.deleted=null,this.$q=d};return e.prototype=Object.create(a.prototype),e.prototype.delete=function(b){var c=this.get(b);return this.deleted=c,a.prototype.delete.call(this,b),this.http.delete(this.BASE_URL+"/folders/"+c.id)},e.prototype.toggleOpen=function(a){var b=this.get(a);return b.opened=!b.opened,this.http({url:this.BASE_URL+"/folders/"+b.id+"/open",method:"POST",data:{folderId:b.id,open:b.opened}})},e.prototype.rename=function(a,b){b=b.toUpperCase();var c=this.get(a);return c.name=b,delete this.hashMap[a],this.hashMap[b]=c,this.http({url:this.BASE_URL+"/folders/"+c.id+"/rename",method:"POST",data:{folderName:b}})},e.prototype.create=function(a){a=a.toUpperCase();var b={name:a};this.add(b);var c=t |