From 6a4e56e7274d85bcbd0e2dcde7a61d8f7a4397ec Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sun, 24 Feb 2019 11:40:29 +0100 Subject: Cleanup JS and prolong error notification --- js/.jshintrc | 2 +- js/app/App.js | 8 +- js/app/Config.js | 48 ++--- js/app/Run.js | 82 ++++---- js/controller/AppController.js | 3 +- js/controller/ContentController.js | 358 +++++++++++++++++----------------- js/controller/ExploreController.js | 95 +++++---- js/controller/NavigationController.js | 13 +- js/controller/SettingsController.js | 130 ++++++------ js/service/FeedResource.js | 8 +- js/service/ItemResource.js | 81 ++++---- js/service/OPMLImporter.js | 3 +- js/service/OPMLParser.js | 5 +- js/service/Resource.js | 2 +- templates/part.content.warnings.php | 4 +- 15 files changed, 408 insertions(+), 434 deletions(-) diff --git a/js/.jshintrc b/js/.jshintrc index 0d5e8b544..92f22ce7c 100644 --- a/js/.jshintrc +++ b/js/.jshintrc @@ -19,7 +19,7 @@ "strict": true, "maxparams": false, "maxdepth": 3, - "maxlen": 80, + "maxlen": 120, "browser": true, "devel": true, "jquery": true, diff --git a/js/app/App.js b/js/app/App.js index 4c1e553de..9e4ee5621 100644 --- a/js/app/App.js +++ b/js/app/App.js @@ -9,10 +9,10 @@ */ $('#content.app-news') - .attr('ng-app', 'News') - .attr('ng-cloak', '') - .attr('ng-strict-di', '') - .attr('ng-controller', 'AppController as App'); + .attr('ng-app', 'News') + .attr('ng-cloak', '') + .attr('ng-strict-di', '') + .attr('ng-controller', 'AppController as App'); /* jshint unused: false */ var app = angular.module('News', ['ngRoute', 'ngSanitize', 'ngAnimate']); diff --git a/js/app/Config.js b/js/app/Config.js index c094c799d..3b808063d 100644 --- a/js/app/Config.js +++ b/js/app/Config.js @@ -7,8 +7,7 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -app.config( - function ($routeProvider, $provide, $httpProvider, $locationProvider) { +app.config(function ($routeProvider, $provide, $httpProvider, $locationProvider) { 'use strict'; var feedType = { @@ -58,26 +57,31 @@ app.config( 403: t('news', 'Request forbidden. Are you an admin?'), 412: t('news', 'Token expired or app not enabled! Reload the page!'), 500: t('news', 'Internal server error! Please check your ' + - 'data/nextcloud.log file for additional ' + - 'information!'), + 'data/nextcloud.log file for additional ' + + 'information!'), 503: t('news', 'Request failed, Nextcloud is in currently ' + - 'in maintenance mode!') + 'in maintenance mode!') }; $provide.factory('ConnectionErrorInterceptor', function ($q, $timeout) { var timer; return { responseError: function (response) { // status 0 is a network error - if (response.status in errorMessages) { - if (timer) { - $timeout.cancel(timer); - } - OC.Notification.hide(); + function sendNotification() { OC.Notification.showHtml(errorMessages[response.status]); timer = $timeout(function () { OC.Notification.hide(); }, 5000); } + if (response.status in errorMessages) { + if (timer) { + timer.then(function (){ + sendNotification(); + }); + } else { + sendNotification(); + } + } return $q.reject(response); } }; @@ -90,8 +94,8 @@ app.config( return { // request to items also returns feeds data: /* @ngInject */ function ( - $http, $route, $q, $location, BASE_URL, ITEM_BATCH_SIZE, FEED_TYPE, - SettingsResource, FeedResource) { + $http, $route, $q, $location, BASE_URL, ITEM_BATCH_SIZE, FEED_TYPE, + SettingsResource, FeedResource) { var showAll = SettingsResource.get('showAll'); var oldestFirst = SettingsResource.get('oldestFirst'); @@ -129,7 +133,7 @@ app.config( } return $http({ - url: BASE_URL + '/items', + url: BASE_URL + '/items', method: 'GET', params: parameters }).then(function (response) { @@ -143,7 +147,7 @@ app.config( var getExploreResolve = function () { return { sites: /* @ngInject */ function ( - $http, $q, BASE_URL, $location, Publisher, SettingsResource) { + $http, $q, BASE_URL, $location, Publisher, SettingsResource) { // always use the code from the url var language = $location.search().lang; if (!language) { @@ -198,13 +202,13 @@ app.config( resolve: getItemResolve(feedType.FOLDER), type: feedType.FOLDER }).when('/explore', { - controller: 'ExploreController as Explore', - templateUrl: 'explore.html', - resolve: getExploreResolve(), - type: feedType.EXPLORE - }).when('/shortcuts', { - templateUrl: 'shortcuts.html', - type: -1 - }); + controller: 'ExploreController as Explore', + templateUrl: 'explore.html', + resolve: getExploreResolve(), + type: feedType.EXPLORE + }).when('/shortcuts', { + templateUrl: 'shortcuts.html', + type: -1 + }); }); diff --git a/js/app/Run.js b/js/app/Run.js index eb4ec76fd..0500faa35 100644 --- a/js/app/Run.js +++ b/js/app/Run.js @@ -7,9 +7,8 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -app.run(function ($rootScope, $location, $http, $q, $interval, $route, Loading, - ItemResource, FeedResource, FolderResource, SettingsResource, - Publisher, BASE_URL, FEED_TYPE, REFRESH_RATE) { +app.run(function ($rootScope, $location, $http, $q, $interval, $route, Loading, ItemResource, FeedResource, + FolderResource, SettingsResource, Publisher, BASE_URL, FEED_TYPE, REFRESH_RATE) { 'use strict'; // show Loading screen @@ -18,53 +17,50 @@ app.run(function ($rootScope, $location, $http, $q, $interval, $route, Loading, // listen to keys in returned queries to automatically distribute the // incoming values to models Publisher.subscribe(ItemResource).toChannels(['items', 'newestItemId', - 'starred']); + 'starred']); Publisher.subscribe(FolderResource).toChannels(['folders']); Publisher.subscribe(FeedResource).toChannels(['feeds']); Publisher.subscribe(SettingsResource).toChannels(['settings']); // load feeds, settings and last read feed - var settingsPromise = $http.get(BASE_URL + '/settings').then( - function (response) { - Publisher.publishAll(response.data); - return response.data; + var settingsPromise = $http.get(BASE_URL + '/settings').then(function (response) { + Publisher.publishAll(response.data); + return response.data; }); var path = $location.path(); var activeFeedPromise = $http.get(BASE_URL + '/feeds/active') .then(function (response) { - var url; - - switch (response.data.activeFeed.type) { - - case FEED_TYPE.FEED: - url = '/items/feeds/' + response.data.activeFeed.id; - break; - - case FEED_TYPE.FOLDER: - url = '/items/folders/' + response.data.activeFeed.id; - break; - - case FEED_TYPE.STARRED: - url = '/items/starred'; - break; - - case FEED_TYPE.EXPLORE: - url = '/explore'; - break; - - default: - url = '/items'; - } + var url; + switch (response.data.activeFeed.type) { + case FEED_TYPE.FEED: + url = '/items/feeds/' + response.data.activeFeed.id; + break; + + case FEED_TYPE.FOLDER: + url = '/items/folders/' + response.data.activeFeed.id; + break; + + case FEED_TYPE.STARRED: + url = '/items/starred'; + break; + + case FEED_TYPE.EXPLORE: + url = '/explore'; + break; + + default: + url = '/items'; + } + + // only redirect if url is empty or faulty + if (!/^\/items(\/(starred|explore|feeds\/\d+|folders\/\d+))?\/?$/ + .test(path)) { + $location.path(url); + } - // only redirect if url is empty or faulty - if (!/^\/items(\/(starred|explore|feeds\/\d+|folders\/\d+))?\/?$/ - .test(path)) { - $location.path(url); - } - - return response.data; - }); + return response.data; + }); var feeds; var feedPromise = $http.get(BASE_URL + '/feeds').then(function (response) { @@ -74,10 +70,10 @@ app.run(function ($rootScope, $location, $http, $q, $interval, $route, Loading, var folders; var folderPromise = $http.get(BASE_URL + '/folders') - .then(function (response) { - folders = response.data; - return folders; - }); + .then(function (response) { + folders = response.data; + return folders; + }); $q.all([ feedPromise, diff --git a/js/controller/AppController.js b/js/controller/AppController.js index 310b326e0..e962bd66a 100644 --- a/js/controller/AppController.js +++ b/js/controller/AppController.js @@ -7,8 +7,7 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -app.controller('AppController', -function (Loading, FeedResource, FolderResource) { +app.controller('AppController', function (Loading, FeedResource, FolderResource) { 'use strict'; this.loading = Loading; diff --git a/js/controller/ContentController.js b/js/controller/ContentController.js index 51f8eca69..74c475f4c 100644 --- a/js/controller/ContentController.js +++ b/js/controller/ContentController.js @@ -7,221 +7,213 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -app.controller('ContentController', - function (Publisher, FeedResource, ItemResource, SettingsResource, data, - $route, $routeParams, $location, FEED_TYPE, ITEM_AUTO_PAGE_SIZE, - Loading, $filter) { - 'use strict'; +app.controller('ContentController', function (Publisher, FeedResource, ItemResource, SettingsResource, data, $route, + $routeParams, $location, FEED_TYPE, ITEM_AUTO_PAGE_SIZE, Loading, + $filter) { + 'use strict'; + + var self = this; + ItemResource.clear(); + + // distribute data to models based on key + Publisher.publishAll(data); + + this.getFirstItem = function () { + var orderFilter = $filter('orderBy'); + var orderedItems = orderFilter(this.getItems(), this.orderBy()); + var firstItem = orderedItems[0]; + if (firstItem === undefined) { + return undefined; + } else { + return firstItem.id; + } + }; - var self = this; - ItemResource.clear(); - // distribute data to models based on key - Publisher.publishAll(data); + this.isAutoPagingEnabled = true; + // the interface should show a hint if there are not enough items sent + // it's assumed that theres nothing to autpage - this.getFirstItem = function () { - var orderFilter = $filter('orderBy'); - var orderedItems = orderFilter(this.getItems(), this.orderBy()); - var firstItem = orderedItems[0]; - if (firstItem === undefined) { - return undefined; - } else { - return firstItem.id; - } - }; + this.isNothingMoreToAutoPage = ItemResource.size() < ITEM_AUTO_PAGE_SIZE; + this.getItems = function () { + return ItemResource.getAll(); + }; - this.isAutoPagingEnabled = true; - // the interface should show a hint if there are not enough items sent - // it's assumed that theres nothing to autpage + this.isItemActive = function (id) { + return this.activeItem === id; + }; - if (ItemResource.size() >= ITEM_AUTO_PAGE_SIZE) { - this.isNothingMoreToAutoPage = false; - } else { - this.isNothingMoreToAutoPage = true; + this.setItemActive = function (id) { + this.activeItem = id; + }; + + this.toggleStar = function (itemId) { + ItemResource.toggleStar(itemId); + }; + + this.toggleItem = function (item) { + // TODO: unittest + if (this.isCompactView()) { + item.show = !item.show; } + }; - this.getItems = function () { - return ItemResource.getAll(); - }; + this.isShowAll = function () { + return SettingsResource.get('showAll'); + }; - this.isItemActive = function (id) { - return this.activeItem === id; - }; + this.markRead = function (itemId) { + var item = ItemResource.get(itemId); - this.setItemActive = function (id) { - this.activeItem = id; - }; + if (!item.keepUnread && item.unread === true) { + ItemResource.markItemRead(itemId); + FeedResource.markItemOfFeedRead(item.feedId); + } + }; - this.toggleStar = function (itemId) { - ItemResource.toggleStar(itemId); - }; + this.getFeed = function (feedId) { + return FeedResource.getById(feedId); + }; - this.toggleItem = function (item) { - // TODO: unittest - if (this.isCompactView()) { - item.show = !item.show; - } - }; + this.toggleKeepUnread = function (itemId) { + var item = ItemResource.get(itemId); + if (!item.unread) { + FeedResource.markItemOfFeedUnread(item.feedId); + ItemResource.markItemRead(itemId, false); + } - this.isShowAll = function () { - return SettingsResource.get('showAll'); - }; + item.keepUnread = !item.keepUnread; + }; - this.markRead = function (itemId) { - var item = ItemResource.get(itemId); + var getOrdering = function () { + var ordering = SettingsResource.get('oldestFirst'); - if (!item.keepUnread && item.unread === true) { - ItemResource.markItemRead(itemId); - FeedResource.markItemOfFeedRead(item.feedId); + if (self.isFeed()) { + var feed = FeedResource.getById($routeParams.id); + if (feed && feed.ordering === 1) { + ordering = true; + } else if (feed && feed.ordering === 2) { + ordering = false; } - }; + } + + return ordering; + }; + + this.orderBy = function () { + if (getOrdering()) { + return 'id'; + } else { + return '-id'; + } + }; + + this.isCompactView = function () { + return SettingsResource.get('compact'); + }; + + this.isCompactExpand = function () { + return SettingsResource.get('compactExpand'); + }; + + this.autoPagingEnabled = function () { + return this.isAutoPagingEnabled; + }; - this.getFeed = function (feedId) { - return FeedResource.getById(feedId); - }; + this.markReadEnabled = function () { + return !SettingsResource.get('preventReadOnScroll'); + }; - this.toggleKeepUnread = function (itemId) { + this.scrollRead = function (itemIds) { + var ids = []; + var feedIds = []; + + itemIds.forEach(function (itemId) { var item = ItemResource.get(itemId); - if (!item.unread) { - FeedResource.markItemOfFeedUnread(item.feedId); - ItemResource.markItemRead(itemId, false); + if (!item.keepUnread) { + ids.push(itemId); + feedIds.push(item.feedId); } + }); - item.keepUnread = !item.keepUnread; - }; + if (ids.length > 0) { + FeedResource.markItemsOfFeedsRead(feedIds); + ItemResource.markItemsRead(ids); + } + }; - var getOrdering = function () { - var ordering = SettingsResource.get('oldestFirst'); + this.isFeed = function () { + return $route.current.$$route.type === FEED_TYPE.FEED; + }; - if (self.isFeed()) { - var feed = FeedResource.getById($routeParams.id); - if (feed && feed.ordering === 1) { - ordering = true; - } else if (feed && feed.ordering === 2) { - ordering = false; - } - } + this.autoPage = function () { + if (this.isNothingMoreToAutoPage) { + return; + } - return ordering; - }; + // in case a subsequent autopage request comes in wait until + // the current one finished and execute a request immediately + // afterwards + if (!this.isAutoPagingEnabled) { + this.autoPageAgain = true; + return; + } - this.orderBy = function () { - if (getOrdering()) { - return 'id'; - } else { - return '-id'; - } - }; - - this.isCompactView = function () { - return SettingsResource.get('compact'); - }; - - this.isCompactExpand = function () { - return SettingsResource.get('compactExpand'); - }; - - this.autoPagingEnabled = function () { - return this.isAutoPagingEnabled; - }; - - this.markReadEnabled = function () { - return !SettingsResource.get('preventReadOnScroll'); - }; - - this.scrollRead = function (itemIds) { - var ids = []; - var feedIds = []; - - itemIds.forEach(function (itemId) { - var item = ItemResource.get(itemId); - if (!item.keepUnread) { - ids.push(itemId); - feedIds.push(item.feedId); - } - }); - - if (ids.length > 0) { - FeedResource.markItemsOfFeedsRead(feedIds); - ItemResource.markItemsRead(ids); - } - }; + this.isAutoPagingEnabled = false; + this.autoPageAgain = false; - this.isFeed = function () { - return $route.current.$$route.type === FEED_TYPE.FEED; - }; + var type = $route.current.$$route.type; + var id = $routeParams.id; + var oldestFirst = getOrdering(); + var showAll = SettingsResource.get('showAll'); + var self = this; + var search = $location.search().search; - this.autoPage = function () { - if (this.isNothingMoreToAutoPage) { - return; - } + Loading.setLoading('autopaging', true); - // in case a subsequent autopage request comes in wait until - // the current one finished and execute a request immediately - // afterwards - if (!this.isAutoPagingEnabled) { - this.autoPageAgain = true; - return; - } + ItemResource.autoPage(type, id, oldestFirst, showAll, search).then(function (response) { + Publisher.publishAll(response.data); - this.isAutoPagingEnabled = false; - this.autoPageAgain = false; - - var type = $route.current.$$route.type; - var id = $routeParams.id; - var oldestFirst = getOrdering(); - var showAll = SettingsResource.get('showAll'); - var self = this; - var search = $location.search().search; - - Loading.setLoading('autopaging', true); - - ItemResource.autoPage(type, id, oldestFirst, showAll, search) - .then(function (response) { - Publisher.publishAll(response.data); - - if (response.data.items.length >= ITEM_AUTO_PAGE_SIZE) { - self.isAutoPagingEnabled = true; - } else { - self.isNothingMoreToAutoPage = true; - } - - if (self.isAutoPagingEnabled && self.autoPageAgain) { - self.autoPage(); - } - return response.data; - }, function () { + if (response.data.items.length >= ITEM_AUTO_PAGE_SIZE) { self.isAutoPagingEnabled = true; - }).finally(function () { - Loading.setLoading('autopaging', false); - }); - }; - - this.getRelativeDate = function (timestamp) { - if (timestamp !== undefined && timestamp !== '') { - var languageCode = SettingsResource.get('language'); - var date = - moment.unix(timestamp).locale(languageCode).fromNow() + ''; - return date; } else { - return ''; + self.isNothingMoreToAutoPage = true; } - }; - - this.refresh = function () { - $route.reload(); - }; - this.getMediaType = function (type) { - if (type && type.indexOf('audio') === 0) { - return 'audio'; - } else if (type && type.indexOf('video') === 0) { - return 'video'; - } else { - return undefined; + if (self.isAutoPagingEnabled && self.autoPageAgain) { + self.autoPage(); } - }; + return response.data; + }, function () { + self.isAutoPagingEnabled = true; + }).finally(function () { + Loading.setLoading('autopaging', false); + }); + }; + + this.getRelativeDate = function (timestamp) { + if (timestamp !== undefined && timestamp !== '') { + var languageCode = SettingsResource.get('language'); + return moment.unix(timestamp).locale(languageCode).fromNow() + ''; + } else { + return ''; + } + }; + + this.refresh = function () { + $route.reload(); + }; + + this.getMediaType = function (type) { + if (type && type.indexOf('audio') === 0) { + return 'audio'; + } else if (type && type.indexOf('video') === 0) { + return 'video'; + } else { + return undefined; + } + }; - this.activeItem = this.getFirstItem(); - }); \ No newline at end of file + this.activeItem = this.getFirstItem(); +}); \ No newline at end of file diff --git a/js/controller/ExploreController.js b/js/controller/ExploreController.js index 08c1ee251..6d34efb40 100644 --- a/js/controller/ExploreController.js +++ b/js/controller/ExploreController.js @@ -7,52 +7,51 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -app.controller('ExploreController', -function (sites, $rootScope, FeedResource, SettingsResource, $location) { - 'use strict'; - - this.sites = sites; - // join all sites - this.feeds = Object.keys(sites).map(function (key) { - return [key, sites[key]]; - }).reduce(function (xs, x) { - var category = x[0]; - var feedList = x[1]; - feedList.forEach(function (feed) { - feed.category = category; - }); - return xs.concat(feedList); - }, []); - - this.feedExists = function (location) { - return FeedResource.getByLocation(location) !== undefined; - }; - - this.subscribeTo = function (location) { - $rootScope.$broadcast('addFeed', location); - }; - - this.isCategoryShown = function (data) { - return data.filter(function (element) { - return FeedResource.getByLocation(element.feed) === undefined; - }).length > 0; - }; - - this.getSupportedLanguageCodes = function () { - return SettingsResource.getSupportedLanguageCodes(); - }; - - this.getCurrentLanguageCode = function () { - var language = $location.search().lang; - if (!language) { - language = SettingsResource.get('language'); - } - return language; - }; - - this.showLanguage = function (languageCode) { - $location.url('/explore/?lang=' + languageCode); - }; - - this.selectedLanguageCode = this.getCurrentLanguageCode(); +app.controller('ExploreController', function (sites, $rootScope, FeedResource, SettingsResource, $location) { + 'use strict'; + + this.sites = sites; + // join all sites + this.feeds = Object.keys(sites).map(function (key) { + return [key, sites[key]]; + }).reduce(function (xs, x) { + var category = x[0]; + var feedList = x[1]; + feedList.forEach(function (feed) { + feed.category = category; + }); + return xs.concat(feedList); + }, []); + + this.feedExists = function (location) { + return FeedResource.getByLocation(location) !== undefined; + }; + + this.subscribeTo = function (location) { + $rootScope.$broadcast('addFeed', location); + }; + + this.isCategoryShown = function (data) { + return data.filter(function (element) { + return FeedResource.getByLocation(element.feed) === undefined; + }).length > 0; + }; + + this.getSupportedLanguageCodes = function () { + return SettingsResource.getSupportedLanguageCodes(); + }; + + this.getCurrentLanguageCode = function () { + var language = $location.search().lang; + if (!language) { + language = SettingsResource.get('language'); + } + return language; + }; + + this.showLanguage = function (languageCode) { + $location.url('/explore/?lang=' + languageCode); + }; + + this.selectedLanguageCode = this.getCurrentLanguageCode(); }); diff --git a/js/controller/NavigationController.js b/js/controller/NavigationController.js index 812c2b2bd..e79202574 100644 --- a/js/controller/NavigationController.js +++ b/js/controller/NavigationController.js @@ -7,9 +7,8 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -app.controller('NavigationController', -function ($route, FEED_TYPE, FeedResource, FolderResource, ItemResource, - SettingsResource, Publisher, $rootScope, $location, $q) { +app.controller('NavigationController', function ($route, FEED_TYPE, FeedResource, FolderResource, ItemResource, + SettingsResource, Publisher, $rootScope, $location, $q) { 'use strict'; this.feedError = ''; @@ -84,7 +83,7 @@ function ($route, FEED_TYPE, FeedResource, FolderResource, ItemResource, return this.getFeedUnreadCount(feedId) > 0; }; - this.getFolderUnreadCount= function (folderId) { + this.getFolderUnreadCount = function (folderId) { return FeedResource.getFolderUnreadCount(folderId); }; @@ -175,15 +174,11 @@ function ($route, FEED_TYPE, FeedResource, FolderResource, ItemResource, // is closed or has no unread articles existingFolder.getsFeed = true; - FeedResource.create(feed.url, existingFolder.id, undefined, - feed.user, feed.password) - .then(function (data) { - + FeedResource.create(feed.url, existingFolder.id, undefined, feed.user, feed.password).then(function (data) { Publisher.publishAll(data); // set folder as default $location.path('/items/feeds/' + data.feeds[0].id + '/'); - }).finally(function () { existingFolder.getsFeed = undefined; feed.url = ''; diff --git a/js/controller/SettingsController.js b/js/controller/SettingsController.js index c20f801c8..2f8a1107c 100644 --- a/js/controller/SettingsController.js +++ b/js/controller/SettingsController.js @@ -7,84 +7,80 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -app.controller('SettingsController', - function ($route, $q, SettingsResource, ItemResource, OPMLParser, - OPMLImporter, Publisher) { - 'use strict'; - this.isOPMLImporting = false; - this.isArticlesImporting = false; - this.opmlImportError = false; - this.articleImportError = false; - this.opmlImportEmptyError = false; - var self = this; - - var set = function (key, value) { - SettingsResource.set(key, value); +app.controller('SettingsController', function ($route, $q, SettingsResource, ItemResource, OPMLParser, OPMLImporter, + Publisher) { + 'use strict'; + this.isOPMLImporting = false; + this.isArticlesImporting = false; + this.opmlImportError = false; + this.articleImportError = false; + this.opmlImportEmptyError = false; + var self = this; - if (['showAll', 'oldestFirst', 'compact'].indexOf(key) >= 0) { - $route.reload(); - } - }; + var set = function (key, value) { + SettingsResource.set(key, value); - this.toggleSetting = function (key) { - set(key, !this.getSetting(key)); - }; + if (['showAll', 'oldestFirst', 'compact'].indexOf(key) >= 0) { + $route.reload(); + } + }; - this.getSetting = function (key) { - return SettingsResource.get(key); - }; + this.toggleSetting = function (key) { + set(key, !this.getSetting(key)); + }; - this.importOPML = function (content) { - self.opmlImportError = false; - self.opmlImportEmptyError = false; - self.articleImportError = false; + this.getSetting = function (key) { + return SettingsResource.get(key); + }; - try { - this.isOPMLImporting = false; - var parsedContent = OPMLParser.parse(content); + this.importOPML = function (fileContent) { + self.opmlImportError = false; + self.opmlImportEmptyError = false; + self.articleImportError = false; - var jobSize = 5; + try { + this.isOPMLImporting = false; + var parsedContent = OPMLParser.parse(fileContent); - if (parsedContent.folders.length === 0 && - parsedContent.feeds.length === 0) { - self.opmlImportEmptyError = true; - } else { - OPMLImporter.importFolders(parsedContent) - .then(function (feedQueue) { - return OPMLImporter.importFeedQueue(feedQueue, - jobSize); - }).finally(function () { - self.isOPMLImporting = false; - }); - } + var jobSize = 5; - } catch (error) { - this.opmlImportError = true; - console.error(error); - this.isOPMLImporting = false; + if (parsedContent.folders.length === 0 && + parsedContent.feeds.length === 0) { + self.opmlImportEmptyError = true; + } else { + OPMLImporter.importFolders(parsedContent).then(function (feedQueue) { + return OPMLImporter.importFeedQueue(feedQueue, jobSize); + }).finally(function () { + self.isOPMLImporting = false; + }); } - }; - this.importArticles = function (content) { - this.opmlImportError = false; - this.articleImportError = false; + } catch (error) { + this.opmlImportError = true; + console.error(error); + this.isOPMLImporting = false; + } + }; - try { - this.isArticlesImporting = true; - var articles = JSON.parse(content); + this.importArticles = function (content) { + this.opmlImportError = false; + this.articleImportError = false; - var self = this; - ItemResource.importArticles(articles).then(function (data) { - Publisher.publishAll(data); - }).finally(function () { - self.isArticlesImporting = false; - }); + try { + this.isArticlesImporting = true; + var articles = JSON.parse(content); - } catch (error) { - console.error(error); - this.articleImportError = true; - this.isArticlesImporting = false; - } - }; + var self = this; + ItemResource.importArticles(articles).then(function (data) { + Publisher.publishAll(data); + }).finally(function () { + self.isArticlesImporting = false; + }); - }); \ No newline at end of file + } catch (error) { + console.error(error); + this.articleImportError = true; + this.isArticlesImporting = false; + } + }; +}); diff --git a/js/service/FeedResource.js b/js/service/FeedResource.js index bb1f30f3f..0ae7d2ad4 100644 --- a/js/service/FeedResource.js +++ b/js/service/FeedResource.js @@ -163,8 +163,7 @@ app.factory('FeedResource', function (Resource, $http, BASE_URL, $q) { }; - FeedResource.prototype.create = function (url, folderId, title, user, - password) { + FeedResource.prototype.create = function (url, folderId, title, user, password) { url = url.trim(); if (!url.startsWith('http')) { url = 'https://' + url; @@ -203,8 +202,7 @@ app.factory('FeedResource', function (Resource, $http, BASE_URL, $q) { }; - FeedResource.prototype.reversiblyDelete = function (id, updateCache, - isFolder) { + FeedResource.prototype.reversiblyDelete = function (id, updateCache, isFolder) { var feed = this.getById(id); // if a folder is deleted it does not have to trigger the delete @@ -329,7 +327,7 @@ app.factory('FeedResource', function (Resource, $http, BASE_URL, $q) { var feed = this.getById(feedId); if (feed) { - Object.keys(diff).forEach(function(key) { + Object.keys(diff).forEach(function (key) { feed[key] = diff[key]; }); var url = this.BASE_URL + '/feeds/' + feedId; diff --git a/js/service/ItemResource.js b/js/service/ItemResource.js index 159216797..fcfd2f28d 100644 --- a/js/service/ItemResource.js +++ b/js/service/ItemResource.js @@ -7,8 +7,7 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -app.factory('ItemResource', function (Resource, $http, BASE_URL, - ITEM_BATCH_SIZE) { +app.factory('ItemResource', function (Resource, $http, BASE_URL, ITEM_BATCH_SIZE) { 'use strict'; var ItemResource = function ($http, BASE_URL, ITEM_BATCH_SIZE) { @@ -29,42 +28,41 @@ app.factory('ItemResource', function (Resource, $http, BASE_URL, ItemResource.prototype.receive = function (value, channel) { switch (channel) { - - case 'newestItemId': - this.newestItemId = value; - break; - - case 'starred': - this.starredCount = value; - break; - - default: - var self = this; - var importValues = []; - value.forEach(function (item) { - // initialize lowest and highest id - if (self.lowestId === 0) { - self.lowestId = item.id; - } - if (self.highestId === 0) { - self.highestId = item.id; - } - - if (item.id > self.highestId) { - self.highestId = item.id; - } - if (item.id < self.lowestId) { - self.lowestId = item.id; - } - - // filter out duplicates - if (self.fingerprints[item.fingerprint] === undefined) { - self.fingerprints[item.fingerprint] = true; - importValues.push(item); - } - }); - - Resource.prototype.receive.call(this, importValues, channel); + case 'newestItemId': + this.newestItemId = value; + break; + + case 'starred': + this.starredCount = value; + break; + + default: + var self = this; + var importValues = []; + value.forEach(function (item) { + // initialize lowest and highest id + if (self.lowestId === 0) { + self.lowestId = item.id; + } + if (self.highestId === 0) { + self.highestId = item.id; + } + + if (item.id > self.highestId) { + self.highestId = item.id; + } + if (item.id < self.lowestId) { + self.lowestId = item.id; + } + + // filter out duplicates + if (self.fingerprints[item.fingerprint] === undefined) { + self.fingerprints[item.fingerprint] = true; + importValues.push(item); + } + }); + + Resource.prototype.receive.call(this, importValues, channel); } }; @@ -135,7 +133,7 @@ app.factory('ItemResource', function (Resource, $http, BASE_URL, ItemResource.prototype.markItemsRead = function (itemIds) { var self = this; - itemIds.forEach(function(itemId) { + itemIds.forEach(function (itemId) { self.get(itemId).unread = false; }); @@ -183,8 +181,7 @@ app.factory('ItemResource', function (Resource, $http, BASE_URL, }; - ItemResource.prototype.autoPage = function (type, id, oldestFirst, - showAll, search) { + ItemResource.prototype.autoPage = function (type, id, oldestFirst, showAll, search) { var offset; if (oldestFirst) { @@ -216,7 +213,7 @@ app.factory('ItemResource', function (Resource, $http, BASE_URL, data: { json: json } - }).then(function(response) { + }).then(function (response) { return response.data; }); }; diff --git a/js/service/OPMLImporter.js b/js/service/OPMLImporter.js index 92c3c0bfb..b2b52bc4c 100644 --- a/js/service/OPMLImporter.js +++ b/js/service/OPMLImporter.js @@ -7,8 +7,7 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -app.service('OPMLImporter', function (FeedResource, FolderResource, Publisher, - $q) { +app.service('OPMLImporter', function (FeedResource, FolderResource, Publisher, $q) { 'use strict'; var startFeedJob = function (queue) { var deferred = $q.defer(); diff --git a/js/service/OPMLParser.js b/js/service/OPMLParser.js index 4de08c42f..6752e1d1e 100644 --- a/js/service/OPMLParser.js +++ b/js/service/OPMLParser.js @@ -43,7 +43,6 @@ app.service('OPMLParser', function () { if (entry.type === 'feed') { root.feeds.push(entry); } else { - // only first level should append folders if (firstLevel) { recursivelyParse(outline.children('outline'), entry, false); @@ -57,8 +56,8 @@ app.service('OPMLParser', function () { return root; }; - this.parse = function (xml) { - xml = $.parseXML(xml); + this.parse = function (fileContent) { + var xml = $.parseXML(fileContent); var firstLevel = $(xml).find('body > outline'); var root = { diff --git a/js/service/Resource.js b/js/service/Resource.js index 70bf5b43c..b5be87cb7 100644 --- a/js/service/Resource.js +++ b/js/service/Resource.js @@ -55,7 +55,7 @@ app.factory('Resource', function () { Resource.prototype.delete = function (id) { // find index of object that should be deleted var self = this; - var deleteAtIndex = this.values.findIndex(function(element) { + var deleteAtIndex = this.values.findIndex(function (element) { return element[self.id] === id; }); diff --git a/templates/part.content.warnings.php b/templates/part.content.warnings.php index 899b1d13e..cdfc2f6da 100644 --- a/templates/part.content.warnings.php +++ b/templates/part.content.warnings.php @@ -3,7 +3,7 @@

t('Ajax or webcron mode detected! Your feeds will not be updated!')); ?>