From b30e3ce1804126e9a002e44b497bfc00f02aa0f9 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 28 Dec 2014 19:50:42 -0800 Subject: [PATCH] GUAC-963: Update status dialog according to client state. --- .../client/controllers/clientController.js | 120 +++++++++--------- .../webapp/app/client/types/ManagedClient.js | 2 +- .../src/main/webapp/translations/en_US.json | 14 +- 3 files changed, 70 insertions(+), 66 deletions(-) diff --git a/guacamole/src/main/webapp/app/client/controllers/clientController.js b/guacamole/src/main/webapp/app/client/controllers/clientController.js index ed853fdca..56d310b6d 100644 --- a/guacamole/src/main/webapp/app/client/controllers/clientController.js +++ b/guacamole/src/main/webapp/app/client/controllers/clientController.js @@ -27,8 +27,8 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams function clientController($scope, $routeParams, $injector) { // Required types - var ClientProperties = $injector.get('ClientProperties'); - var ScrollState = $injector.get('ScrollState'); + var ManagedClientState = $injector.get('ManagedClientState'); + var ScrollState = $injector.get('ScrollState'); // Required services var connectionGroupService = $injector.get('connectionGroupService'); @@ -391,83 +391,79 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams delete keysCurrentlyPressed[keysym]; }); - // Show status dialog when client status changes - $scope.$on('guacClientStateChange', function clientStateChangeListener(event, client, status) { + // Show status dialog when connection status changes + $scope.$watch('client.clientState.connectionState', function clientStateChanged(connectionState) { - // Show new status if not yet connected - if (status !== "connected") { + // Hide status if no known state + if (!connectionState) { + $scope.showStatus(false); + return; + } + + // Get any associated status code + var status = $scope.client.clientState.statusCode; + + // Connecting + if (connectionState === ManagedClientState.ConnectionState.CONNECTING + || connectionState === ManagedClientState.ConnectionState.WAITING) { $scope.showStatus({ title: "CLIENT.DIALOG_HEADER_CONNECTING", - text: "CLIENT.TEXT_CLIENT_STATUS_" + status.toUpperCase() + text: "CLIENT.TEXT_CLIENT_STATUS_" + connectionState.toUpperCase() }); } - // Hide status upon connecting - else - $scope.showStatus(false); + // Client error + else if (connectionState === ManagedClientState.ConnectionState.CLIENT_ERROR) { - }); + // Determine translation name of error + var errorName = (status in CLIENT_ERRORS) ? status.toString(16).toUpperCase() : "DEFAULT"; - // Show status dialog when client errors occur - $scope.$on('guacClientError', function clientErrorListener(event, client, status) { + // Determine whether the reconnect countdown applies + var countdown = (status in CLIENT_AUTO_RECONNECT) ? RECONNECT_COUNTDOWN : null; - // Determine translation name of error - var errorName = (status in CLIENT_ERRORS) ? status.toString(16).toUpperCase() : "DEFAULT"; + // Show error status + $scope.showStatus({ + className: "error", + title: "CLIENT.DIALOG_HEADER_CONNECTION_ERROR", + text: "CLIENT.ERROR_CLIENT_" + errorName, + countdown: countdown, + actions: [ RECONNECT_ACTION ] + }); - // Determine whether the reconnect countdown applies - var countdown = (status in CLIENT_AUTO_RECONNECT) ? RECONNECT_COUNTDOWN : null; + } - // Override any existing status - $scope.showStatus(false); + // Tunnel error + else if (connectionState === ManagedClientState.ConnectionState.TUNNEL_ERROR) { - // Show error status - $scope.showStatus({ - className: "error", - title: "CLIENT.DIALOG_HEADER_CONNECTION_ERROR", - text: "CLIENT.ERROR_CLIENT_" + errorName, - countdown: countdown, - actions: [ RECONNECT_ACTION ] - }); + // Determine translation name of error + var errorName = (status in TUNNEL_ERRORS) ? status.toString(16).toUpperCase() : "DEFAULT"; - }); + // Determine whether the reconnect countdown applies + var countdown = (status in TUNNEL_AUTO_RECONNECT) ? RECONNECT_COUNTDOWN : null; - // Show status dialog when tunnel status changes - $scope.$on('guacTunnelStateChange', function tunnelStateChangeListener(event, tunnel, status) { + // Show error status + $scope.showStatus({ + className: "error", + title: "CLIENT.DIALOG_HEADER_CONNECTION_ERROR", + text: "CLIENT.ERROR_TUNNEL_" + errorName, + countdown: countdown, + actions: [ RECONNECT_ACTION ] + }); - // Show new status only if disconnected - if (status === "closed") { - - // Disconnect - $scope.id = null; + } + // Disconnected + else if (connectionState === ManagedClientState.ConnectionState.DISCONNECTED) { $scope.showStatus({ title: "CLIENT.DIALOG_HEADER_DISCONNECTED", - text: "CLIENT.TEXT_TUNNEL_STATUS_" + status.toUpperCase() + text: "CLIENT.TEXT_CLIENT_STATUS_" + connectionState.toUpperCase(), + actions: [ RECONNECT_ACTION ] }); } - }); - - // Show status dialog when tunnel errors occur - $scope.$on('guacTunnelError', function tunnelErrorListener(event, tunnel, status) { - - // Determine translation name of error - var errorName = (status in TUNNEL_ERRORS) ? status.toString(16).toUpperCase() : "DEFAULT"; - - // Determine whether the reconnect countdown applies - var countdown = (status in TUNNEL_AUTO_RECONNECT) ? RECONNECT_COUNTDOWN : null; - - // Override any existing status - $scope.showStatus(false); - - // Show error status - $scope.showStatus({ - className: "error", - title: "CLIENT.DIALOG_HEADER_CONNECTION_ERROR", - text: "CLIENT.ERROR_TUNNEL_" + errorName, - countdown: countdown, - actions: [ RECONNECT_ACTION ] - }); + // Hide status for all other states + else + $scope.showStatus(false); }); @@ -710,4 +706,12 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams }); }); + // Clean up when view destroyed + $scope.$on('$destroy', function clientViewDestroyed() { + + // Hide any status dialog + $scope.showStatus(false); + + }); + }]); diff --git a/guacamole/src/main/webapp/app/client/types/ManagedClient.js b/guacamole/src/main/webapp/app/client/types/ManagedClient.js index ce2d92e5b..3510ae18a 100644 --- a/guacamole/src/main/webapp/app/client/types/ManagedClient.js +++ b/guacamole/src/main/webapp/app/client/types/ManagedClient.js @@ -288,7 +288,7 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector', // Connected case 3: ManagedClientState.setConnectionState(managedClient.clientState, - ManagedClientState.ConnectionState.DISCONNECTED); + ManagedClientState.ConnectionState.CONNECTED); break; // Connecting, disconnecting, and disconnected are all diff --git a/guacamole/src/main/webapp/translations/en_US.json b/guacamole/src/main/webapp/translations/en_US.json index fa30634a4..cb259dbd3 100644 --- a/guacamole/src/main/webapp/translations/en_US.json +++ b/guacamole/src/main/webapp/translations/en_US.json @@ -82,13 +82,13 @@ "SECTION_HEADER_DISPLAY" : "Display", "SECTION_HEADER_MOUSE_MODE" : "Mouse emulation mode", - "TEXT_ZOOM_AUTO_FIT" : "Automatically fit to browser window", - "TEXT_CLIENT_STATUS_IDLE" : "Idle.", - "TEXT_CLIENT_STATUS_CONNECTING" : "Connecting to Guacamole...", - "TEXT_CLIENT_STATUS_WAITING" : "Connected to Guacamole. Waiting for response...", - "TEXT_TUNNEL_STATUS_CLOSED" : "You have been disconnected. Reload the page to reconnect.", - "TEXT_RECONNECT_COUNTDOWN" : "Reconnecting in {REMAINING} {REMAINING, plural, one{second} other{seconds}}...", - "TEXT_FILE_TRANSFER_PROGRESS" : "{PROGRESS} {UNIT, select, b{B} kb{KB} mb{MB} gb{GB} other{}}", + "TEXT_ZOOM_AUTO_FIT" : "Automatically fit to browser window", + "TEXT_CLIENT_STATUS_IDLE" : "Idle.", + "TEXT_CLIENT_STATUS_CONNECTING" : "Connecting to Guacamole...", + "TEXT_CLIENT_STATUS_DISCONNECTED" : "You have been disconnected.", + "TEXT_CLIENT_STATUS_WAITING" : "Connected to Guacamole. Waiting for response...", + "TEXT_RECONNECT_COUNTDOWN" : "Reconnecting in {REMAINING} {REMAINING, plural, one{second} other{seconds}}...", + "TEXT_FILE_TRANSFER_PROGRESS" : "{PROGRESS} {UNIT, select, b{B} kb{KB} mb{MB} gb{GB} other{}}", "URL_OSK_LAYOUT" : "layouts/en-us-qwerty.xml"