diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2019-02-24 11:40:29 +0100 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2019-03-05 11:35:14 +0100 |
commit | 6a4e56e7274d85bcbd0e2dcde7a61d8f7a4397ec (patch) | |
tree | 5bafad374708f5542081592456869f6fa1226f86 /js/app | |
parent | 45474dc86232897199382327527c7de80ec99c1c (diff) |
Cleanup JS and prolong error notification
Diffstat (limited to 'js/app')
-rw-r--r-- | js/app/App.js | 8 | ||||
-rw-r--r-- | js/app/Config.js | 48 | ||||
-rw-r--r-- | js/app/Run.js | 82 |
3 files changed, 69 insertions, 69 deletions
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 <dev@bernhard-posselt.com> * @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 <dev@bernhard-posselt.com> * @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, |