GUACAMOLE-724: Ensure focus is assigned to at least one client after changes are made to a group.

This commit is contained in:
Michael Jumper
2021-07-04 20:33:50 -07:00
parent 69ea8488f3
commit 95e77c6985
3 changed files with 26 additions and 5 deletions

View File

@@ -653,8 +653,14 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
* The client to disconnect. * The client to disconnect.
*/ */
$scope.closeClientTile = function closeClientTile(client) { $scope.closeClientTile = function closeClientTile(client) {
$scope.addRemoveClient(client.id, true); $scope.addRemoveClient(client.id, true);
guacClientManager.removeManagedClient(client.id); guacClientManager.removeManagedClient(client.id);
// Ensure at least one client has focus (the only client with
// focus may just have been removed)
ManagedClientGroup.verifyFocus($scope.clientGroup);
}; };
/** /**

View File

@@ -253,15 +253,13 @@ angular.module('client').factory('guacClientManager', ['$injector',
clients.push(service.getManagedClient(id)); clients.push(service.getManagedClient(id));
}); });
// Focus the first client if there are no clients focused
if (clients.length >= 1 && _.findIndex(clients, client => client.clientProperties.focused) === -1) {
clients[0].clientProperties.focused = true;
}
var group = new ManagedClientGroup({ var group = new ManagedClientGroup({
clients : clients clients : clients
}); });
// Focus the first client if there are no clients focused
ManagedClientGroup.verifyFocus(group);
managedClientGroups.push(group); managedClientGroups.push(group);
return group; return group;

View File

@@ -337,6 +337,23 @@ angular.module('client').factory('ManagedClientGroup', ['$injector', function de
}; };
/**
* Verifies that focus is assigned to at least one client in the given
* group. If no client has focus, focus is assigned to the first client in
* the group.
*
* @param {ManagedClientGroup} group
* The group to verify.
*/
ManagedClientGroup.verifyFocus = function verifyFocus(group) {
// Focus the first client if there are no clients focused
if (group.clients.length >= 1 && _.findIndex(group.clients, client => client.clientProperties.focused) === -1) {
group.clients[0].clientProperties.focused = true;
}
};
return ManagedClientGroup; return ManagedClientGroup;
}]); }]);