Skip to content

Commit fadbefe

Browse files
authored
GUACAMOLE-1904: Merge enhancements to available events/hooks related to client args and menu.
2 parents 22e1d47 + 70a7696 commit fadbefe

File tree

8 files changed

+92
-28
lines changed

8 files changed

+92
-28
lines changed

guacamole/src/main/frontend/src/app/client/controllers/clientController.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,21 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
468468
else if (menuShownPreviousState)
469469
$scope.applyParameterChanges($scope.focusedClient);
470470

471+
/* Broadcast changes to the menu display state */
472+
$scope.$broadcast('guacMenuShown', menuShown);
473+
471474
});
472475

476+
// Toggle the menu when the guacClientToggleMenu event is received
477+
$scope.$on('guacToggleMenu',
478+
() => $scope.menu.shown = !$scope.menu.shown);
479+
480+
// Show the menu when the guacClientShowMenu event is received
481+
$scope.$on('guacShowMenu', () => $scope.menu.shown = true);
482+
483+
// Hide the menu when the guacClientHideMenu event is received
484+
$scope.$on('guacHideMenu', () => $scope.menu.shown = false);
485+
473486
// Automatically track and cache the currently-focused client
474487
$scope.$on('guacClientFocused', function focusedClientChanged(event, newFocusedClient) {
475488

@@ -489,10 +502,9 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
489502

490503
// Automatically update connection parameters that have been modified
491504
// for the current focused client
492-
$scope.$on('guacClientArgumentsUpdated', function focusedClientChanged(event, focusedClient) {
505+
$scope.$on('guacClientArgumentsUpdated', function argumentsChanged(event, focusedClient) {
493506

494-
// Update available connection parameters, if the updated arguments are
495-
// for the current focused client - otherwise ignore them
507+
// Ignore any updated arguments not for the current focused client
496508
if ($scope.focusedClient && $scope.focusedClient === focusedClient)
497509
$scope.menu.connectionParameters = ManagedClient.getArgumentModel(focusedClient);
498510

guacamole/src/main/frontend/src/app/client/directives/guacTiledClients.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ angular.module('client').directive('guacTiledClients', [function guacTiledClient
6262
directive.controller = ['$scope', '$injector', '$element',
6363
function guacTiledClientsController($scope, $injector, $element) {
6464

65+
// Required services
66+
const $rootScope = $injector.get('$rootScope');
67+
6568
// Required types
6669
const ManagedClient = $injector.get('ManagedClient');
6770
const ManagedClientGroup = $injector.get('ManagedClientGroup');
@@ -89,12 +92,17 @@ angular.module('client').directive('guacTiledClients', [function guacTiledClient
8992

9093
// Notify whenever identify of currently-focused client changes
9194
$scope.$watch('getFocusedClient()', function focusedClientChanged(focusedClient) {
92-
$scope.$emit('guacClientFocused', focusedClient);
95+
$rootScope.$broadcast('guacClientFocused', focusedClient);
9396
});
9497

9598
// Notify whenever arguments of currently-focused client changes
9699
$scope.$watch('getFocusedClient().arguments', function focusedClientParametersChanged() {
97-
$scope.$emit('guacClientArgumentsUpdated', $scope.getFocusedClient());
100+
$rootScope.$broadcast('guacClientArgumentsUpdated', $scope.getFocusedClient());
101+
}, true);
102+
103+
// Notify whenever protocol of currently-focused client changes
104+
$scope.$watch('getFocusedClient().protocol', function focusedClientParametersChanged() {
105+
$rootScope.$broadcast('guacClientProtocolUpdated', $scope.getFocusedClient());
98106
}, true);
99107

100108
/**

guacamole/src/main/frontend/src/app/client/templates/client.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ <h3>{{'CLIENT.SECTION_HEADER_DEVICES' | translate}}</h3>
124124
<guac-form namespace="getProtocolNamespace(focusedClient.protocol)"
125125
content="focusedClient.forms"
126126
model="menu.connectionParameters"
127+
client="focusedClient"
127128
model-only="true"></guac-form>
128129
</div>
129130

guacamole/src/main/frontend/src/app/client/types/ManagedArgument.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ angular.module('client').factory('ManagedArgument', ['$q', function defineManage
5858
*/
5959
this.stream = template.stream;
6060

61+
/**
62+
* True if this argument has been modified in the webapp, but yet to
63+
* be confirmed by guacd, or false in any other case. A pending
64+
* argument cannot be modified again, and must be recreated before
65+
* editing is enabled again.
66+
*
67+
* @type {boolean}
68+
*/
69+
this.pending = false;
70+
6171
};
6272

6373
/**
@@ -110,43 +120,34 @@ angular.module('client').factory('ManagedArgument', ['$q', function defineManage
110120
* Sets the given editable argument (connection parameter) to the given
111121
* value, updating the behavior of the associated connection in real-time.
112122
* If successful, the ManagedArgument provided cannot be used for future
113-
* calls to setValue() and must be replaced with a new instance. This
114-
* function only has an effect if the new parameter value is different from
115-
* the current value.
123+
* calls to setValue() and will be read-only until replaced with a new
124+
* instance. This function only has an effect if the new parameter value
125+
* is different from the current value.
116126
*
117127
* @param {ManagedArgument} managedArgument
118128
* The ManagedArgument instance associated with the connection
119129
* parameter being modified.
120130
*
121131
* @param {String} value
122132
* The new value to assign to the connection parameter.
123-
*
124-
* @returns {Boolean}
125-
* true if the connection parameter was sent and the provided
126-
* ManagedArgument instance may no longer be used for future setValue()
127-
* calls, false if the connection parameter was NOT sent as it has not
128-
* changed.
129133
*/
130134
ManagedArgument.setValue = function setValue(managedArgument, value) {
131135

132-
// Stream new value only if value has changed
133-
if (value !== managedArgument.value) {
136+
// Stream new value only if value has changed and a change is not
137+
// already pending
138+
if (!managedArgument.pending && value !== managedArgument.value) {
134139

135140
var writer = new Guacamole.StringWriter(managedArgument.stream);
136141
writer.sendText(value);
137142
writer.sendEnd();
138143

139144
// ManagedArgument instance is no longer usable
140-
return true;
145+
managedArgument.pending = true;
141146

142147
}
143148

144-
// No parameter value change was attempted and the ManagedArgument
145-
// instance may be reused
146-
return false;
147-
148149
};
149150

150151
return ManagedArgument;
151152

152-
}]);
153+
}]);

guacamole/src/main/frontend/src/app/client/types/ManagedClient.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,7 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
836836
*/
837837
ManagedClient.setArgument = function setArgument(managedClient, name, value) {
838838
var managedArgument = managedClient.arguments[name];
839-
if (managedArgument && ManagedArgument.setValue(managedArgument, value))
840-
delete managedClient.arguments[name];
839+
managedArgument && ManagedArgument.setValue(managedArgument, value);
841840
};
842841

843842
/**
@@ -1007,4 +1006,4 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
10071006

10081007
return ManagedClient;
10091008

1010-
}]);
1009+
}]);

guacamole/src/main/frontend/src/app/form/directives/form.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* under the License.
1818
*/
1919

20+
/* global _ */
2021

2122
/**
2223
* A directive that allows editing of a collection of fields.
@@ -79,7 +80,19 @@ angular.module('form').directive('guacForm', [function form() {
7980
*
8081
* @type String
8182
*/
82-
focused : '='
83+
focused : '=',
84+
85+
/**
86+
* The client associated with this form, if any.
87+
*
88+
* NOTE: If the provided client has any managed arguments in the
89+
* pending state, any fields with the same name rendered by this
90+
* form will be disabled. The fields will be re-enabled when guacd
91+
* sends an updated argument with a the same name.
92+
*
93+
* @type ManagedClient
94+
*/
95+
client: '='
8396

8497
},
8598
templateUrl: 'app/form/templates/form.html',
@@ -240,6 +253,28 @@ angular.module('form').directive('guacForm', [function form() {
240253

241254
};
242255

256+
257+
/**
258+
* Returns whether the given field should be disabled (read-only)
259+
* when presented to the current user.
260+
*
261+
* @param {Field} field
262+
* The field to check.
263+
*
264+
* @returns {Boolean}
265+
* true if the given field should be disabled, false otherwise.
266+
*/
267+
$scope.isDisabled = function isDisabled(field) {
268+
269+
/*
270+
* The field is disabled if either the form as a whole is disabled,
271+
* or if a client is provided to the directive, and the field is
272+
* marked as pending.
273+
*/
274+
return $scope.disabled ||
275+
_.get($scope.client, ['arguments', field.name, 'pending']);
276+
};
277+
243278
/**
244279
* Returns whether at least one of the given fields should be
245280
* displayed to the current user.

guacamole/src/main/frontend/src/app/form/directives/formField.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ angular.module('form').directive('guacFormField', [function formField() {
6868
*
6969
* @type Boolean
7070
*/
71-
focused : '='
71+
focused : '=',
72+
73+
/**
74+
* The client associated with this form field, if any.
75+
*
76+
* @type ManagedClient
77+
*/
78+
client: '='
7279

7380
},
7481
templateUrl: 'app/form/templates/formField.html',

guacamole/src/main/frontend/src/app/form/templates/form.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ <h3 class="form-header" ng-show="form.name">{{getSectionHeader(form) | translate
1010
<div class="fields">
1111
<guac-form-field ng-repeat="field in form.fields" namespace="namespace"
1212
ng-if="isVisible(field)"
13-
data-disabled="disabled"
13+
data-disabled="isDisabled(field)"
1414
focused="isFocused(field)"
1515
field="field"
16+
client="client"
1617
model="values[field.name]"></guac-form-field>
1718
</div>
1819

0 commit comments

Comments
 (0)