GUACAMOLE-926: Switch to standard notification style.

This commit is contained in:
James Muehlner
2023-03-09 19:14:13 +00:00
parent eadc1779a0
commit 7bf192fd73
4 changed files with 30 additions and 76 deletions

View File

@@ -35,6 +35,7 @@ angular.module('import').controller('importConnectionsController', ['$scope', '$
const $timeout = $injector.get('$timeout'); const $timeout = $injector.get('$timeout');
const connectionParseService = $injector.get('connectionParseService'); const connectionParseService = $injector.get('connectionParseService');
const connectionService = $injector.get('connectionService'); const connectionService = $injector.get('connectionService');
const guacNotification = $injector.get('guacNotification');
const permissionService = $injector.get('permissionService'); const permissionService = $injector.get('permissionService');
const userService = $injector.get('userService'); const userService = $injector.get('userService');
const userGroupService = $injector.get('userGroupService'); const userGroupService = $injector.get('userGroupService');
@@ -45,14 +46,7 @@ angular.module('import').controller('importConnectionsController', ['$scope', '$
const PermissionSet = $injector.get('PermissionSet'); const PermissionSet = $injector.get('PermissionSet');
const User = $injector.get('User'); const User = $injector.get('User');
const UserGroup = $injector.get('UserGroup'); const UserGroup = $injector.get('UserGroup');
/**
* Any error that may have occured during import file parsing.
*
* @type {ParseError}
*/
$scope.error = null;
/** /**
* The result of parsing the current upload, if successful. * The result of parsing the current upload, if successful.
* *
@@ -116,7 +110,6 @@ angular.module('import').controller('importConnectionsController', ['$scope', '$
$scope.aborted = false; $scope.aborted = false;
$scope.dataReady = false; $scope.dataReady = false;
$scope.processing = false; $scope.processing = false;
$scope.error = null;
$scope.fileData = null; $scope.fileData = null;
$scope.mimeType = null; $scope.mimeType = null;
$scope.fileReader = null; $scope.fileReader = null;
@@ -404,7 +397,7 @@ angular.module('import').controller('importConnectionsController', ['$scope', '$
} }
/** /**
* Set any caught error message to the scope for display. * Display the provided error to the user in a dismissable dialog.
* *
* @argument {ParseError} error * @argument {ParseError} error
* The error to display. * The error to display.
@@ -415,15 +408,24 @@ angular.module('import').controller('importConnectionsController', ['$scope', '$
// all upload state to allow for a fresh retry // all upload state to allow for a fresh retry
resetUploadState(); resetUploadState();
// Set the error for display guacNotification.showStatus({
$scope.error = error; className : 'error',
title : 'IMPORT.DIALOG_HEADER_ERROR',
// Use the translation key if available
text : {
key: error.key || error.message,
variables: error.variables
},
// Add a button to hide the error
actions : [{
name : 'IMPORT.BUTTON_CLEAR',
callback : () => guacNotification.showStatus(false)
}]
})
}; };
/**
* Clear the current displayed error.
*/
$scope.clearError = () => delete $scope.error;
/** /**
* Process the uploaded import file, importing the connections, granting * Process the uploaded import file, importing the connections, granting
@@ -455,16 +457,14 @@ angular.module('import').controller('importConnectionsController', ['$scope', '$
else if (mimeType.endsWith("yaml")) else if (mimeType.endsWith("yaml"))
processDataCallback = connectionParseService.parseYAML; processDataCallback = connectionParseService.parseYAML;
// We don't expect this to happen - the file upload directive should // The file type was validated before being uploaded - this should
// have already have filtered out any invalid file types // never happen
else { else
handleError(new ParseError({ processDataCallback = () => {
message: 'Invalid file type: ' + mimeType, throw new ParseError({
key: 'IMPORT.INVALID_FILE_TYPE', message: "Unexpected invalid file type: " + mimeType
variables: { TYPE: mimeType } });
})); };
return;
}
// Make the call to process the data into a series of patches // Make the call to process the data into a series of patches
processDataCallback(data) processDataCallback(data)
@@ -501,9 +501,6 @@ angular.module('import').controller('importConnectionsController', ['$scope', '$
*/ */
$scope.cancel = function() { $scope.cancel = function() {
// Clear any error message
$scope.clearError();
// If the upload is in progress, stop it now; the FileReader will // If the upload is in progress, stop it now; the FileReader will
// reset the upload state when it stops // reset the upload state when it stops
if ($scope.fileReader) { if ($scope.fileReader) {
@@ -542,9 +539,6 @@ angular.module('import').controller('importConnectionsController', ['$scope', '$
*/ */
const handleFile = file => { const handleFile = file => {
// Clear any error from a previous attempted file upload
$scope.clearError();
// The MIME type of the provided file // The MIME type of the provided file
const mimeType = file.type; const mimeType = file.type;
@@ -556,7 +550,7 @@ angular.module('import').controller('importConnectionsController', ['$scope', '$
// If the provided file is not one of the supported types, // If the provided file is not one of the supported types,
// display an error and abort processing // display an error and abort processing
handleError(new ParseError({ handleError(new ParseError({
message: "Invalid file type: " + type, message: "Invalid file type: " + mimeType,
key: 'IMPORT.ERROR_INVALID_FILE_TYPE', key: 'IMPORT.ERROR_INVALID_FILE_TYPE',
variables: { TYPE: mimeType } variables: { TYPE: mimeType }
})); }));
@@ -564,9 +558,6 @@ angular.module('import').controller('importConnectionsController', ['$scope', '$
} }
$scope.fileName = file.name; $scope.fileName = file.name;
// Clear any error message from the previous upload attempt
$scope.clearError();
// Initialize upload state // Initialize upload state
$scope.aborted = false; $scope.aborted = false;

View File

@@ -17,10 +17,6 @@
* under the License. * under the License.
*/ */
.import .parseError {
color: red;
}
.import .import-buttons { .import .import-buttons {
margin-top: 10px; margin-top: 10px;
@@ -30,7 +26,6 @@
} }
.import .errors table { .import .errors table {
width: 100%; width: 100%;
} }
@@ -68,7 +63,6 @@
.file-upload-container .clear { .file-upload-container .clear {
margin: 0; margin: 0;
padding:
} }
.file-upload-container .upload-header { .file-upload-container .upload-header {
@@ -154,16 +148,3 @@
cursor: pointer; cursor: pointer;
} }
.import .parseError {
display: flex;
justify-content: center;
padding: 0.75em;
margin-bottom: 10px;
gap: 3em;
}
.import .parseError .clear {
cursor: pointer;
}

View File

@@ -5,23 +5,6 @@
<guac-user-menu></guac-user-menu> <guac-user-menu></guac-user-menu>
</div> </div>
<div ng-show="error" class="parseError notification error">
<!-- The translatable error message, if one is set -->
<span
class="message" ng-show="error.key"
translate="{{error.key}}" translate-values="{{error.variables}}"
></span>
<!-- The base message, if no translatable message is available -->
<span class="message" ng-show="!error.key && error.message">
{{error.message}}
</span>
<span class="clear" ng-click="clearError()"> {{'IMPORT.BUTTON_CLEAR_ERROR' | translate}} </span>
</div>
<div ng-show="fileName" class="file-upload-container file-selected"> <div ng-show="fileName" class="file-upload-container file-selected">
<div class="file-name"> {{fileName}} </div> <div class="file-name"> {{fileName}} </div>
<button class="danger clear" ng-click="cancel()"> <button class="danger clear" ng-click="cancel()">

View File

@@ -188,10 +188,9 @@
"BUTTON_CANCEL": "Cancel", "BUTTON_CANCEL": "Cancel",
"BUTTON_CLEAR" : "Clear", "BUTTON_CLEAR" : "Clear",
"BUTTON_CLEAR_ERROR": "✖",
"BUTTON_IMPORT": "Import Connections", "BUTTON_IMPORT": "Import Connections",
"ERROR_HEADER": "Error", "DIALOG_HEADER_ERROR" : "@:APP.DIALOG_HEADER_ERROR",
"FIELD_PLACEHOLDER_FILTER" : "@:APP.FIELD_PLACEHOLDER_FILTER", "FIELD_PLACEHOLDER_FILTER" : "@:APP.FIELD_PLACEHOLDER_FILTER",