summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-11-20 10:58:58 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2014-11-20 10:58:58 +0100
commit193bd948d7e628f1b0544f9b7b0304cdd1067a4a (patch)
tree0d7a7442977a4ac4c573a3d496a14fdc4393826b /js
parenta2054d20b7b9616b7cb4cbf8b66bfb7d4c520246 (diff)
fix multiple bugs
Diffstat (limited to 'js')
-rw-r--r--js/app/Config.js106
-rw-r--r--js/app/Run.js6
-rw-r--r--js/build/app.js160
-rw-r--r--js/build/app.min.js2
-rw-r--r--js/controller/ContentController.js26
-rw-r--r--js/service/ItemResource.js6
-rw-r--r--js/service/SettingsResource.js12
-rw-r--r--js/tests/unit/controller/ContentControllerSpec.js32
-rw-r--r--js/tests/unit/service/SettingsResourceSpec.js2
9 files changed, 226 insertions, 126 deletions
diff --git a/js/app/Config.js b/js/app/Config.js
index 76b0bdafb..415fd9d3b 100644
--- a/js/app/Config.js
+++ b/js/app/Config.js
@@ -47,29 +47,71 @@ app.config(function ($routeProvider, $provide, $httpProvider) {
$httpProvider.interceptors.push('CSRFInterceptor');
// routing
- var getResolve = function (type) {
+ var getItemResolve = function (type) {
return {
// request to items also returns feeds
data: /* @ngInject */ function (
- $http, $route, $q, BASE_URL, ITEM_BATCH_SIZE) {
+ $http, $route, $q, BASE_URL, ITEM_BATCH_SIZE, SettingsResource) {
- var parameters = {
- type: type,
- limit: ITEM_BATCH_SIZE
- };
+ var showAll = SettingsResource.get('showAll');
+ var oldestFirst = SettingsResource.get('oldestFirst');
- if ($route.current.params.id !== undefined) {
- parameters.id = $route.current.params.id;
+ var deferred = $q.defer();
+
+ // if those two values are null it means we did not receive
+ // the settings request from the server so dont query the server
+ if (showAll === null || oldestFirst === null) {
+ deferred.resolve({});
+ } else {
+ var parameters = {
+ type: type,
+ limit: ITEM_BATCH_SIZE,
+ showAll: showAll,
+ oldestFirst: oldestFirst
+ };
+
+ if ($route.current.params.id !== undefined) {
+ parameters.id = $route.current.params.id;
+ }
+
+
+ $http({
+ url: BASE_URL + '/items',
+ method: 'GET',
+ params: parameters
+ }).success(function (data) {
+ deferred.resolve(data);
+ });
}
+ return deferred.promise;
+ }
+ };
+ };
+
+ var getExploreResolve = function () {
+ return {
+ sites: /* @ngInject */ function (
+ $http, $q, BASE_URL, Publisher, SettingsResource) {
var deferred = $q.defer();
- $http({
- url: BASE_URL + '/items',
- method: 'GET',
- params: parameters
- }).success(function (data) {
- deferred.resolve(data);
+ $http.get(BASE_URL + '/settings').then(function (data) {
+ Publisher.publishAll(data);
+
+ var url = SettingsResource.get('exploreUrl');
+ var language = SettingsResource.get('language');
+ return $http({
+ url: url,
+ method: 'GET',
+ params: {
+ lang: language
+ }
+ });
+
+ }).then(function (data) {
+ deferred.resolve(data.data);
+ }).catch(function () {
+ deferred.reject();
});
return deferred.promise;
@@ -81,56 +123,30 @@ app.config(function ($routeProvider, $provide, $httpProvider) {
.when('/items', {
controller: 'ContentController as Content',
templateUrl: 'content.html',
- resolve: getResolve(feedType.SUBSCRIPTIONS),
+ resolve: getItemResolve(feedType.SUBSCRIPTIONS),
type: feedType.SUBSCRIPTIONS
})
.when('/items/starred', {
controller: 'ContentController as Content',
templateUrl: 'content.html',
- resolve: getResolve(feedType.STARRED),
+ resolve: getItemResolve(feedType.STARRED),
type: feedType.STARRED
})
.when('/items/feeds/:id', {
controller: 'ContentController as Content',
templateUrl: 'content.html',
- resolve: getResolve(feedType.FEED),
+ resolve: getItemResolve(feedType.FEED),
type: feedType.FEED
})
.when('/items/folders/:id', {
controller: 'ContentController as Content',
templateUrl: 'content.html',
- resolve: getResolve(feedType.FOLDER),
+ resolve: getItemResolve(feedType.FOLDER),
type: feedType.FOLDER
}).when('/explore', {
controller: 'ExploreController as Explore',
templateUrl: 'explore.html',
- resolve: {
- sites: /* @ngInject */ function (
- $http, $q, BASE_URL, Publisher, SettingsResource) {
- var deferred = $q.defer();
-
- $http.get(BASE_URL + '/settings').then(function (data) {
- Publisher.publishAll(data);
-
- var url = SettingsResource.get('exploreUrl');
- var language = SettingsResource.get('language');
- return $http({
- url: url,
- method: 'GET',
- params: {
- lang: language
- }
- });
-
- }).then(function (data) {
- deferred.resolve(data.data);
- }).catch(function () {
- deferred.reject();
- });
-
- return deferred.promise;
- }
- },
+ resolve: getExploreResolve(),
type: feedType.EXPLORE
}).when('/shortcuts', {
templateUrl: 'shortcuts.html',
diff --git a/js/app/Run.js b/js/app/Run.js
index b05df1930..2d9815fdf 100644
--- a/js/app/Run.js
+++ b/js/app/Run.js
@@ -7,7 +7,7 @@
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2014
*/
-app.run(function ($rootScope, $location, $http, $q, $interval, Loading,
+app.run(function ($rootScope, $location, $http, $q, $interval, $route, Loading,
ItemResource, FeedResource, FolderResource, SettingsResource,
Publisher, BASE_URL, FEED_TYPE, REFRESH_RATE) {
'use strict';
@@ -67,13 +67,14 @@ app.run(function ($rootScope, $location, $http, $q, $interval, Loading,
});
var feedDeferred = $q.defer();
- var folders, feeds;
+ var feeds;
$http.get(BASE_URL + '/feeds').success(function (data) {
feeds = data;
feedDeferred.resolve();
});
var folderDeferred = $q.defer();
+ var folders;
$http.get(BASE_URL + '/folders').success(function (data) {
folders = data;
folderDeferred.resolve();
@@ -102,6 +103,7 @@ app.run(function ($rootScope, $location, $http, $q, $interval, Loading,
]
)
.then(function () {
+ $route.reload();
Loading.setLoading('global', false);
});
diff --git a/js/build/app.js b/js/build/app.js
index e33d4ef63..8686ff40d 100644
--- a/js/build/app.js
+++ b/js/build/app.js
@@ -45,29 +45,71 @@ app.config(["$routeProvider", "$provide", "$httpProvider", function ($routeProvi
$httpProvider.interceptors.push('CSRFInterceptor');
// routing
- var getResolve = function (type) {
+ var getItemResolve = function (type) {
return {
// request to items also returns feeds
- data: /* @ngInject */ ["$http", "$route", "$q", "BASE_URL", "ITEM_BATCH_SIZE", function (
- $http, $route, $q, BASE_URL, ITEM_BATCH_SIZE) {
+ data: /* @ngInject */ ["$http", "$route", "$q", "BASE_URL", "ITEM_BATCH_SIZE", "SettingsResource", function (
+ $http, $route, $q, BASE_URL, ITEM_BATCH_SIZE, SettingsResource) {
- var parameters = {
- type: type,
- limit: ITEM_BATCH_SIZE
- };
+ var showAll = SettingsResource.get('showAll');
+ var oldestFirst = SettingsResource.get('oldestFirst');
+
+ var deferred = $q.defer();
- if ($route.current.params.id !== undefined) {
- parameters.id = $route.current.params.id;
+ // if those two values are null it means we did not receive
+ // the settings request from the server so dont query the server
+ if (showAll === null || oldestFirst === null) {
+ deferred.resolve({});
+ } else {
+ var parameters = {
+ type: type,
+ limit: ITEM_BATCH_SIZE,
+ showAll: showAll,
+ oldestFirst: oldestFirst
+ };
+
+ if ($route.current.params.id !== undefined) {
+ parameters.id = $route.current.params.id;
+ }
+
+
+ $http({
+ url: BASE_URL + '/items',
+ method: 'GET',
+ params: parameters
+ }).success(function (data) {
+ deferred.resolve(data);
+ });
}
+ return deferred.promise;
+ }]
+ };
+ };
+
+ var getExploreResolve = function () {
+ return {
+ sites: /* @ngInject */ ["$http", "$q", "BASE_URL", "Publisher", "SettingsResource", function (
+ $http, $q, BASE_URL, Publisher, SettingsResource) {
var deferred = $q.defer();
- $http({
- url: BASE_URL + '/items',
- method: 'GET',
- params: parameters
- }).success(function (data) {
- deferred.resolve(data);
+ $http.get(BASE_URL + '/settings').then(function (data) {
+ Publisher.publishAll(data);
+
+ var url = SettingsResource.get('exploreUrl');
+ var language = SettingsResource.get('language');
+ return $http({
+ url: url,
+ method: 'GET',
+ params: {
+ lang: language
+ }
+ });
+
+ }).then(function (data) {
+ deferred.resolve(data.data);
+ }).catch(function () {
+ deferred.reject();
});
return deferred.promise;
@@ -79,56 +121,30 @@ app.config(["$routeProvider", "$provide", "$httpProvider", function ($routeProvi
.when('/items', {
controller: 'ContentController as Content',
templateUrl: 'content.html',
- resolve: getResolve(feedType.SUBSCRIPTIONS),
+ resolve: getItemResolve(feedType.SUBSCRIPTIONS),
type: feedType.SUBSCRIPTIONS
})
.when('/items/starred', {
controller: 'ContentController as Content',
templateUrl: 'content.html',
- resolve: getResolve(feedType.STARRED),
+ resolve: getItemResolve(feedType.STARRED),
type: feedType.STARRED
})
.when('/items/feeds/:id', {
controller: 'ContentController as Content',
templateUrl: 'content.html',
- resolve: getResolve(feedType.FEED),
+ resolve: getItemResolve(feedType.FEED),
type: feedType.FEED
})
.when('/items/folders/:id', {
controller: 'ContentController as Content',
templateUrl: 'content.html',
- resolve: getResolve(feedType.FOLDER),
+ resolve: getItemResolve(feedType.FOLDER),
type: feedType.FOLDER
}).when('/explore', {
controller: 'ExploreController as Explore',
templateUrl: 'explore.html',
- resolve: {
- sites: /* @ngInject */ ["$http", "$q", "BASE_URL", "Publisher", "SettingsResource", function (
- $http, $q, BASE_URL, Publisher, SettingsResource) {
- var deferred = $q.defer();
-
- $http.get(BASE_URL + '/settings').then(function (data) {
- Publisher.publishAll(data);
-
- var url = SettingsResource.get('exploreUrl');
- var language = SettingsResource.get('language');
- return $http({
- url: url,
- method: 'GET',
- params: {
- lang: language
- }
- });
-
- }).then(function (data) {
- deferred.resolve(data.data);
- }).catch(function () {
- deferred.reject();
- });
-
- return deferred.promise;
- }]
- },
+ resolve: getExploreResolve(),
type: feedType.EXPLORE
}).when('/shortcuts', {
templateUrl: 'shortcuts.html',
@@ -138,7 +154,7 @@ app.config(["$routeProvider", "$provide", "$httpProvider", function ($routeProvi
}]);
-app.run(["$rootScope", "$location", "$http", "$q", "$interval", "Loading", "ItemResource", "FeedResource", "FolderResource", "SettingsResource", "Publisher", "BASE_URL", "FEED_TYPE", "REFRESH_RATE", function ($rootScope, $location, $http, $q, $interval, Loading,
+app.run(["$rootScope", "$location", "$http", "$q", "$interval", "$route", "Loading", "ItemResource", "FeedResource", "FolderResource", "SettingsResource", "Publisher", "BASE_URL", "FEED_TYPE", "REFRESH_RATE", function ($rootScope, $location, $http, $q, $interval, $route, Loading,
ItemResource, FeedResource, FolderResource, SettingsResource,
Publisher, BASE_URL, FEED_TYPE, REFRESH_RATE) {
'use strict';
@@ -198,13 +214,14 @@ app.run(["$rootScope", "$location", "$http", "$q", "$interval", "Loading", "Item
});
var feedDeferred = $q.defer();
- var folders, feeds;
+ var feeds;
$http.get(BASE_URL + '/feeds').success(function (data) {
feeds = data;
feedDeferred.resolve();
});
var folderDeferred = $q.defer();
+ var folders;
$http.get(BASE_URL + '/folders').success(function (data) {
folders = data;
folderDeferred.resolve();
@@ -233,6 +250,7 @@ app.run(["$rootScope", "$location", "$http", "$q", "$interval", "Loading", "Item
]
)
.then(function () {
+ $route.reload();
Loading.setLoading('global', false);
});
@@ -273,11 +291,10 @@ app.controller('AppController',
}]);
app.controller('ContentController',
-["Publisher", "FeedResource", "ItemResource", "SettingsResource", "data", "$route", "$routeParams", "FEED_TYPE", function (Publisher, FeedResource, ItemResource, SettingsResource, data,
- $route, $routeParams, FEED_TYPE) {
+["Publisher", "FeedResource", "ItemResource", "SettingsResource", "data", "$route", "$routeParams", "FEED_TYPE", "ITEM_AUTO_PAGE_SIZE", "Loading", function (Publisher, FeedResource, ItemResource, SettingsResource, data,
+ $route, $routeParams, FEED_TYPE, ITEM_AUTO_PAGE_SIZE, Loading) {
'use strict';
- // dont cache items across multiple route changes
ItemResource.clear();
// distribute data to models based on key
@@ -285,7 +302,14 @@ app.controller('ContentController',
this.isAutoPagingEnabled = true;
- this.isNothingMoreToAutoPage = false;
+
+ // the interface should show a hint if there are not enough items sent so
+ // it's assumed that theres nothing to autpage
+ if (ItemResource.size() >= ITEM_AUTO_PAGE_SIZE) {
+ this.isNothingMoreToAutoPage = false;
+ } else {
+ this.isNothingMoreToAutoPage = true;
+ }
this.getItems = function () {
return ItemResource.getAll();
@@ -372,6 +396,10 @@ app.controller('ContentController',
};
this.autoPage = function () {
+ if (this.isNothingMoreToAutoPage) {
+ return;
+ }
+
// in case a subsequent autopage request comes in wait until
// the current one finished and execute a request immediately afterwards
if (!this.isAutoPagingEnabled) {
@@ -385,12 +413,16 @@ app.controller('ContentController',
var type = $route.current.$$route.type;
var id = $routeParams.id;
var oldestFirst = SettingsResource.get('oldestFirst');
+ var showAll = SettingsResource.get('showAll');
var self = this;
- ItemResource.autoPage(type, id, oldestFirst).success(function (data) {
+ Loading.setLoading('autopaging', true);
+
+ ItemResource.autoPage(type, id, oldestFirst, showAll)
+ .success(function (data) {
Publisher.publishAll(data);
- if (data.items.length > 0) {
+ if (data.items.length >= ITEM_AUTO_PAGE_SIZE) {
self.isAutoPagingEnabled = true;
} else {
self.isNothingMoreToAutoPage = true;
@@ -401,6 +433,8 @@ app.controller('ContentController',
}
}).error(function () {
self.isAutoPagingEnabled = true;
+ }).finally(function () {
+ Loading.setLoading('autopaging', false);
});
};
@@ -1425,7 +1459,8 @@ app.factory('ItemResource', ["Resource", "$http", "BASE_URL", "ITEM_BATCH_SIZE",
};
- ItemResource.prototype.autoPage = function (type, id, oldestFirst) {
+ ItemResource.prototype.autoPage = function (type, id, oldestFirst,
+ showAll) {
var offset;
if (oldestFirst) {
@@ -1442,7 +1477,8 @@ app.factory('ItemResource', ["Resource", "$http", "BASE_URL", "ITEM_BATCH_SIZE",
id: id,
offset: offset,
limit: this.batchSize,
- oldestFirst: oldestFirst
+ oldestFirst: oldestFirst,
+ showAll: showAll
}
});
};
@@ -1762,9 +1798,9 @@ app.service('SettingsResource', ["$http", "BASE_URL", function ($http, BASE_URL)
this.settings = {
language: 'en',
- showAll: false,
+ showAll: null,
compact: false,
- oldestFirst: false,
+ oldestFirst: null,
preventReadOnScroll: false,
exploreUrl: ''
};
@@ -1800,7 +1836,13 @@ app.service('SettingsResource', ["$http", "BASE_URL", function ($http, BASE_URL)
return $http({
url: BASE_URL + '/settings',
method: 'PUT',
- data: this.settings
+ data: {
+ language: this.settings.language,
+ showAll: this.settings.showAll,
+ compact: this.settings.compact,
+ oldestFirst: this.settings.oldestFirst,
+ preventReadOnScroll: this.settings.preventReadOnScroll
+ }
});
};
diff --git a/js/build/app.min.js b/js/build/app.min.js
index ccccd6c53..633fe9636 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,EXPLORE:5};b.constant("REFRESH_RATE",60),b.constant("ITEM_BATCH_SIZE",40),b.constant("ITEM_AUTO_PAGE_SIZE",20),b.constant("BASE_URL",e.generateUrl("/apps/news")),b.constant("FEED_TYPE",d),b.constant("MARK_READ_TIMEOUT",.5),b.constant("SCROLL_TIMEOUT",.1),b.factory("CSRFInterceptor",["$q","BASE_URL","$window",function(a,b,c){return{request:function(d){var e=c.location.href.split(c.location.pathname)[0];return(0===d.url.indexOf(b)||0===d.url.indexOf(e))&&(d.headers.requesttoken=f),d||a.when(d)}}}]),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}).when("/explore",{controller:"ExploreController as Explore",templateUrl:"explore.html",resolve:{sites:["$http","$q","BASE_URL","Publisher","SettingsResource",function(a,b,c,d,e){var f=b.defer();return a.get(c+"/settings").then(function(b){d.publishAll(b);var c=e.get("exploreUrl"),f=e.get("language");return a({url:c,method:"GET",params:{lang:f}})}).then(function(a){f.resolve(a.data)}).catch(function(){f.reject()}),f.promise}]},type:d.EXPLORE}).when("/shortcuts",{templateUrl:"shortcuts.html",type:-1})}]),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;case m.EXPLORE:c="/explore";break;default:c="/items"}/^\/items(\/(starred|explore|feeds\/\d+|folders\/\d+))?\/?$/.test(q)||b.path(c),p.resolve()});var r,s,t=d.defer();c.get(l+"/feeds").success(function(a){s=a,t.resolve()});var u=d.defer();c.get(l+"/folders").success(function(a){r=a,u.resolve()}),d.all([t.promise,u.promise]).then(function(){k.publishAll(s),k.publishAll(r),0===s.feeds.length&&0===r.folders.length&&b.path("/explore")}),d.all([o.promise,p.promise,t.promise,u.promise]).then(function(){f.setLoading("global",!1)}),e(function(){c.get(l+"/feeds").success(function(a){k.publishAll(a)}),c.get(l+"/folders").success(function(a){k.publishAll(a)})},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","FEED_TYPE",function(a,b,c,d,e,f,h,i){c.clear(),a.publishAll(e),this.isAutoPagingEnabled=!0,this.isNothingMoreToAutoPage=!1,this.getItems=function(){return c.getAll()},this.toggleStar=function(a){c.toggleStar(a)},this.toggleItem=function(a){this.isCompactView()&&(a.show=!a.show)},this.isShowAll=function(){return d.get("showAll")},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))}),d.length>0&&(b.markItemsOfFeedsRead(e),c.markItemsRead(d))},this.isFeed=function(){return f.current.$$route.type===i.FEED},this.autoPage=function(){if(!this.isAutoPagingEnabled)return void(this.autoPageAgain=!0);this.isAutoPagingEnabled=!1,this.autoPageAgain=!1;var b=f.current.$$route.type,e=h.id,g=d.get("oldestFirst"),i=this;c.autoPage(b,e,g).success(function(b){a.publishAll(b),b.items.length>0?i.isAutoPagingEnabled=!0:i.isNothingMoreToAutoPage=!0,i.isAutoPagingEnabled&&i.autoPageAgain&&i.autoPage()}).error(function(){i.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""},this.refresh=function(){f.reload()}}]),h.controller("ExploreController",["sites","$rootScope",function(a,b){this.sites=a,console.log(a),this.subscribeTo=function(a){b.$broadcast("addFeed",a)}}]),h.controller("NavigationController",["$route","FEED_TYPE","FeedResource","FolderResource","ItemResource","SettingsResource","Publisher","$rootScope","$location","$q",function(a,b,c,d,e,f,h,i,j,k){this.feedError="",this.showNewFolder=!1,this.renamingFolder=!1,this.addingFeed=!1,this.addingFolder=!1,this.folderError="",this.renameError="",this.feed={};var l=function(){return parseInt(a.current.params.id,10)};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){var b=c.getById(a);return b!==g?b.unreadCount:0},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(l());if(f!==g&&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.isExploreActive=function(){return a.current&&a.current.$$route.type===b.EXPLORE},this.isFolderActive=function(c){return a.current&&a.current.$$route.type===b.FOLDER&&l()===c},this.isFeedActive=function(c){return a.current&&a.current.$$route.type===b.FEED&&l()===c},this.folderNameExists=function(a){return a=a||"",d.get(a.trim())!==g},this.feedUrlExists=function(a){return a=a||"",a=a.trim(),c.get(a)!==g||c.get("http://"+a)!==g},this.createFeed=function(a){var b=this;this.showNewFolder=!1,this.addingFeed=!0;var e=a.newFolder,f=a.existingFolder||{id:0};e===g||""===e?(f.getsFeed=!0,c.create(a.url,f.id,g).then(function(a){h.publishAll(a),j.path("/items/feeds/"+a.feeds[0].id+"/")}).finally(function(){f.getsFeed=g,a.url="",b.addingFeed=!1})):d.create(e).then(function(c){h.publishAll(c),a.existingFolder=d.get(c.folders[0].name),a.newFolder=g,b.createFeed(a)})},this.createFolder=function(a){var b=this;this.addingFolder=!0,d.create(a.name).then(function(a){h.publishAll(a)}).finally(function(){b.addingFolder=!1,a.name=""})},this.moveFeed=function(b,d){var e=!1,f=c.getById(b);f.folderId!==d&&((this.isFolderActive(f.folderId)||this.isFolderActive(d))&&(e=!0),c.move(b,d),e&&a.reload())},this.renameFeed=function(a){c.rename(a.id,a.title),a.editing=!1},this.renameFolder=function(a,b){a.renameError="",this.renamingFolder=!0;var c=this;a.name===b?(a.renameError="",a.editing=!1,this.renamingFolder=!1):d.rename(a.name,b).then(function(){a.renameError="",a.editing=!1},function(b){a.