From ae6b5fc8bbc67822308c5aaf038bb2456c6d21f4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 26 Apr 2018 22:28:18 -0700 Subject: [PATCH] GUACAMOLE-526: Move handling of request error notification to guacNotification, resolving circular dependency. --- .../controllers/manageConnectionController.js | 4 ++-- .../manageConnectionGroupController.js | 4 ++-- .../manageSharingProfileController.js | 4 ++-- .../controllers/manageUserController.js | 6 ++--- .../app/notification/notificationModule.js | 1 + .../notification/services/guacNotification.js | 23 +++++++++---------- .../src/main/webapp/app/rest/restModule.js | 3 +-- .../app/rest/services/requestService.js | 18 ++------------- .../directives/guacSettingsPreferences.js | 2 +- .../directives/guacSettingsSessions.js | 2 +- 10 files changed, 26 insertions(+), 41 deletions(-) diff --git a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js index 66e2aebdc..2bbd999f5 100644 --- a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js +++ b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js @@ -379,7 +379,7 @@ angular.module('manage').controller('manageConnectionController', ['$scope', '$i connectionService.saveConnection($scope.selectedDataSource, $scope.connection) .then(function savedConnection() { $location.url('/settings/' + encodeURIComponent($scope.selectedDataSource) + '/connections'); - }, requestService.SHOW_NOTIFICATION); + }, guacNotification.SHOW_REQUEST_ERROR); }; @@ -419,7 +419,7 @@ angular.module('manage').controller('manageConnectionController', ['$scope', '$i connectionService.deleteConnection($scope.selectedDataSource, $scope.connection) .then(function deletedConnection() { $location.path('/settings/' + encodeURIComponent($scope.selectedDataSource) + '/connections'); - }, requestService.SHOW_NOTIFICATION); + }, guacNotification.SHOW_REQUEST_ERROR); }; diff --git a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionGroupController.js b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionGroupController.js index cab4b18f5..de29aff12 100644 --- a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionGroupController.js +++ b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionGroupController.js @@ -221,7 +221,7 @@ angular.module('manage').controller('manageConnectionGroupController', ['$scope' connectionGroupService.saveConnectionGroup($scope.selectedDataSource, $scope.connectionGroup) .then(function savedConnectionGroup() { $location.path('/settings/' + encodeURIComponent($scope.selectedDataSource) + '/connections'); - }, requestService.SHOW_NOTIFICATION); + }, guacNotification.SHOW_REQUEST_ERROR); }; @@ -261,7 +261,7 @@ angular.module('manage').controller('manageConnectionGroupController', ['$scope' connectionGroupService.deleteConnectionGroup($scope.selectedDataSource, $scope.connectionGroup) .then(function deletedConnectionGroup() { $location.path('/settings/' + encodeURIComponent($scope.selectedDataSource) + '/connections'); - }, requestService.SHOW_NOTIFICATION); + }, guacNotification.SHOW_REQUEST_ERROR); }; diff --git a/guacamole/src/main/webapp/app/manage/controllers/manageSharingProfileController.js b/guacamole/src/main/webapp/app/manage/controllers/manageSharingProfileController.js index 886f54c22..5f2d6bd67 100644 --- a/guacamole/src/main/webapp/app/manage/controllers/manageSharingProfileController.js +++ b/guacamole/src/main/webapp/app/manage/controllers/manageSharingProfileController.js @@ -342,7 +342,7 @@ angular.module('manage').controller('manageSharingProfileController', ['$scope', sharingProfileService.saveSharingProfile($scope.selectedDataSource, $scope.sharingProfile) .then(function savedSharingProfile() { $location.url('/settings/' + encodeURIComponent($scope.selectedDataSource) + '/connections'); - }, requestService.SHOW_NOTIFICATION); + }, guacNotification.SHOW_REQUEST_ERROR); }; @@ -370,7 +370,7 @@ angular.module('manage').controller('manageSharingProfileController', ['$scope', sharingProfileService.deleteSharingProfile($scope.selectedDataSource, $scope.sharingProfile) .then(function deletedSharingProfile() { $location.path('/settings/' + encodeURIComponent($scope.selectedDataSource) + '/connections'); - }, requestService.SHOW_NOTIFICATION); + }, guacNotification.SHOW_REQUEST_ERROR); }; diff --git a/guacamole/src/main/webapp/app/manage/controllers/manageUserController.js b/guacamole/src/main/webapp/app/manage/controllers/manageUserController.js index d0b6be429..eae141b26 100644 --- a/guacamole/src/main/webapp/app/manage/controllers/manageUserController.js +++ b/guacamole/src/main/webapp/app/manage/controllers/manageUserController.js @@ -1141,9 +1141,9 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto permissionService.patchPermissions(selectedDataSource, $scope.user.username, permissionsAdded, permissionsRemoved) .then(function patchedUserPermissions() { $location.url('/settings/users'); - }, requestService.SHOW_NOTIFICATION); + }, guacNotification.SHOW_REQUEST_ERROR); - }, requestService.SHOW_NOTIFICATION); + }, guacNotification.SHOW_REQUEST_ERROR); }; @@ -1183,7 +1183,7 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto userService.deleteUser(selectedDataSource, $scope.user) .then(function deletedUser() { $location.path('/settings/users'); - }, requestService.SHOW_NOTIFICATION); + }, guacNotification.SHOW_REQUEST_ERROR); }; diff --git a/guacamole/src/main/webapp/app/notification/notificationModule.js b/guacamole/src/main/webapp/app/notification/notificationModule.js index 9a4eb0c15..15a2a4628 100644 --- a/guacamole/src/main/webapp/app/notification/notificationModule.js +++ b/guacamole/src/main/webapp/app/notification/notificationModule.js @@ -21,5 +21,6 @@ * The module for code used to display arbitrary notifications. */ angular.module('notification', [ + 'rest', 'storage' ]); diff --git a/guacamole/src/main/webapp/app/notification/services/guacNotification.js b/guacamole/src/main/webapp/app/notification/services/guacNotification.js index a1b8d1016..b52f42146 100644 --- a/guacamole/src/main/webapp/app/notification/services/guacNotification.js +++ b/guacamole/src/main/webapp/app/notification/services/guacNotification.js @@ -25,6 +25,7 @@ angular.module('notification').factory('guacNotification', ['$injector', // Required services var $rootScope = $injector.get('$rootScope'); + var requestService = $injector.get('requestService'); var sessionStorageFactory = $injector.get('sessionStorageFactory'); var service = {}; @@ -93,26 +94,24 @@ angular.module('notification').factory('guacNotification', ['$injector', }; /** - * Shows the given REST error response as a modal status. If a status - * notification is already currently shown, this function will have no - * effect. + * Promise error callback which displays a modal notification for all + * rejections due to REST errors. The message displayed to the user within + * the notification is provided by the contents of the @link{Error} object + * within the REST response. All other rejections, such as those due to + * JavaScript errors, are logged to the browser console without displaying + * any notification. * - * @param {Error} error - * The error object returned from the failed REST request. - * - * @example - * - * someService.updateObject(object) - * ['catch'](guacNotification.showRequestError); + * @constant + * @type Function */ - service.showRequestError = function showRequestError(error) { + service.SHOW_REQUEST_ERROR = requestService.createErrorCallback(function showRequestError(error) { service.showStatus({ className : 'error', title : 'APP.DIALOG_HEADER_ERROR', text : error.translatableMessage, actions : [ service.ACKNOWLEDGE_ACTION ] }); - }; + }); // Hide status upon navigation $rootScope.$on('$routeChangeSuccess', function() { diff --git a/guacamole/src/main/webapp/app/rest/restModule.js b/guacamole/src/main/webapp/app/rest/restModule.js index 6672507dc..f409e9545 100644 --- a/guacamole/src/main/webapp/app/rest/restModule.js +++ b/guacamole/src/main/webapp/app/rest/restModule.js @@ -22,6 +22,5 @@ * Guacamole web application. */ angular.module('rest', [ - 'auth', - 'notification' + 'auth' ]); diff --git a/guacamole/src/main/webapp/app/rest/services/requestService.js b/guacamole/src/main/webapp/app/rest/services/requestService.js index a27ccc3bb..9aef12486 100644 --- a/guacamole/src/main/webapp/app/rest/services/requestService.js +++ b/guacamole/src/main/webapp/app/rest/services/requestService.js @@ -25,9 +25,8 @@ angular.module('rest').factory('requestService', ['$injector', function requestService($injector) { // Required services - var $http = $injector.get('$http'); - var $log = $injector.get('$log'); - var guacNotification = $injector.get('guacNotification'); + var $http = $injector.get('$http'); + var $log = $injector.get('$log'); // Required types var Error = $injector.get('Error'); @@ -116,19 +115,6 @@ angular.module('rest').factory('requestService', ['$injector', $log.warn(error.type, error.message || error.translatableMessage); }); - /** - * Promise error callback which displays a modal notification for all - * rejections due to REST errors. The message displayed to the user within - * the notification is provided by the contents of the @link{Error} object - * within the REST response. All other rejections, such as those due to - * JavaScript errors, are logged to the browser console without displaying - * any notification. - * - * @constant - * @type Function - */ - service.SHOW_NOTIFICATION = service.createErrorCallback(guacNotification.showRequestError); - return service; }]); diff --git a/guacamole/src/main/webapp/app/settings/directives/guacSettingsPreferences.js b/guacamole/src/main/webapp/app/settings/directives/guacSettingsPreferences.js index 6cfd440d2..dfad564e8 100644 --- a/guacamole/src/main/webapp/app/settings/directives/guacSettingsPreferences.js +++ b/guacamole/src/main/webapp/app/settings/directives/guacSettingsPreferences.js @@ -165,7 +165,7 @@ angular.module('settings').directive('guacSettingsPreferences', [function guacSe }, actions : [ ACKNOWLEDGE_ACTION ] }); - }, requestService.SHOW_NOTIFICATION); + }, guacNotification.SHOW_REQUEST_ERROR); }; diff --git a/guacamole/src/main/webapp/app/settings/directives/guacSettingsSessions.js b/guacamole/src/main/webapp/app/settings/directives/guacSettingsSessions.js index 8563d52a5..67776f0ab 100644 --- a/guacamole/src/main/webapp/app/settings/directives/guacSettingsSessions.js +++ b/guacamole/src/main/webapp/app/settings/directives/guacSettingsSessions.js @@ -316,7 +316,7 @@ angular.module('settings').directive('guacSettingsSessions', [function guacSetti // Clear selection allSelectedWrappers = {}; - }, requestService.SHOW_NOTIFICATION); + }, guacNotification.SHOW_REQUEST_ERROR); };