From bfd3cbc2049db07647582e36835488f3e60111dc Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 1 Jun 2021 17:39:50 -0700 Subject: [PATCH] GUACAMOLE-724: Do not reload client controller if only updating which client(s) are visible. Reloading the client controller would reset UI state, including whether the Guacamole menu is currently shown. --- .../client/controllers/clientController.js | 42 +++++++++++-------- .../src/app/index/config/indexRouteConfig.js | 1 + 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/guacamole/src/main/frontend/src/app/client/controllers/clientController.js b/guacamole/src/main/frontend/src/app/client/controllers/clientController.js index c19aa594e..e107cef5b 100644 --- a/guacamole/src/main/frontend/src/app/client/controllers/clientController.js +++ b/guacamole/src/main/frontend/src/app/client/controllers/clientController.js @@ -156,18 +156,7 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams * * @type ManagedClient[] */ - $scope.clients = (function getClients() { - - var clients = []; - - var ids = $routeParams.id.split(/[ +]/); - ids.forEach(function addClient(id) { - clients.push(guacClientManager.getManagedClient(id)); - }); - - return clients; - - })(); + $scope.clients = []; /** * All active clients which are not any current client ($scope.clients). @@ -175,17 +164,34 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams * * @type Object. */ - $scope.otherClients = (function getOtherClients(clients) { + $scope.otherClients = {}; - var otherClients = angular.extend({}, clients); + /** + * Reloads the contents of $scope.clients and $scope.otherClients to + * reflect the client IDs currently listed in the URL. + */ + var updateAttachedClients = function updateAttachedClients() { - $scope.clients.forEach(function removeActiveCLient(client) { - delete otherClients[client.id]; + var ids = $routeParams.id.split(/[ +]/); + + $scope.clients = []; + $scope.otherClients = angular.extend({}, guacClientManager.getManagedClients()); + + // Separate active clients by whether they should be displayed within + // the current view + ids.forEach(function groupClients(id) { + $scope.clients.push(guacClientManager.getManagedClient(id)); + delete $scope.otherClients[id]; }); - return otherClients; + }; - })(guacClientManager.getManagedClients()); + // Init sets of clients based on current URL ... + updateAttachedClients(); + + // ... and re-initialize those sets if the URL has changed without + // reloading the route + $scope.$on('$routeUpdate', updateAttachedClients); /** * The root connection groups of the connection hierarchy that should be diff --git a/guacamole/src/main/frontend/src/app/index/config/indexRouteConfig.js b/guacamole/src/main/frontend/src/app/index/config/indexRouteConfig.js index 684114514..322f7eaba 100644 --- a/guacamole/src/main/frontend/src/app/index/config/indexRouteConfig.js +++ b/guacamole/src/main/frontend/src/app/index/config/indexRouteConfig.js @@ -185,6 +185,7 @@ angular.module('index').config(['$routeProvider', '$locationProvider', bodyClassName : 'client', templateUrl : 'app/client/templates/client.html', controller : 'clientController', + reloadOnUrl : false, resolve : { updateCurrentToken: updateCurrentToken } })