mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-1904: Disable ManagedArgument instead of deleting when updated, to avoid fields disappearing upon modification.
This commit is contained in:
@@ -58,6 +58,16 @@ angular.module('client').factory('ManagedArgument', ['$q', function defineManage
|
|||||||
*/
|
*/
|
||||||
this.stream = template.stream;
|
this.stream = template.stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if this argument has been modified in the webapp, but yet to
|
||||||
|
* be confirmed by guacd, or false in any other case. A pending
|
||||||
|
* argument cannot be modified again, and must be recreated before
|
||||||
|
* editing is enabled again.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.pending = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,9 +120,9 @@ angular.module('client').factory('ManagedArgument', ['$q', function defineManage
|
|||||||
* Sets the given editable argument (connection parameter) to the given
|
* Sets the given editable argument (connection parameter) to the given
|
||||||
* value, updating the behavior of the associated connection in real-time.
|
* value, updating the behavior of the associated connection in real-time.
|
||||||
* If successful, the ManagedArgument provided cannot be used for future
|
* If successful, the ManagedArgument provided cannot be used for future
|
||||||
* calls to setValue() and must be replaced with a new instance. This
|
* calls to setValue() and will be read-only until replaced with a new
|
||||||
* function only has an effect if the new parameter value is different from
|
* instance. This function only has an effect if the new parameter value
|
||||||
* the current value.
|
* is different from the current value.
|
||||||
*
|
*
|
||||||
* @param {ManagedArgument} managedArgument
|
* @param {ManagedArgument} managedArgument
|
||||||
* The ManagedArgument instance associated with the connection
|
* The ManagedArgument instance associated with the connection
|
||||||
@@ -120,33 +130,24 @@ angular.module('client').factory('ManagedArgument', ['$q', function defineManage
|
|||||||
*
|
*
|
||||||
* @param {String} value
|
* @param {String} value
|
||||||
* The new value to assign to the connection parameter.
|
* The new value to assign to the connection parameter.
|
||||||
*
|
|
||||||
* @returns {Boolean}
|
|
||||||
* true if the connection parameter was sent and the provided
|
|
||||||
* ManagedArgument instance may no longer be used for future setValue()
|
|
||||||
* calls, false if the connection parameter was NOT sent as it has not
|
|
||||||
* changed.
|
|
||||||
*/
|
*/
|
||||||
ManagedArgument.setValue = function setValue(managedArgument, value) {
|
ManagedArgument.setValue = function setValue(managedArgument, value) {
|
||||||
|
|
||||||
// Stream new value only if value has changed
|
// Stream new value only if value has changed and a change is not
|
||||||
if (value !== managedArgument.value) {
|
// already pending
|
||||||
|
if (!managedArgument.pending && value !== managedArgument.value) {
|
||||||
|
|
||||||
var writer = new Guacamole.StringWriter(managedArgument.stream);
|
var writer = new Guacamole.StringWriter(managedArgument.stream);
|
||||||
writer.sendText(value);
|
writer.sendText(value);
|
||||||
writer.sendEnd();
|
writer.sendEnd();
|
||||||
|
|
||||||
// ManagedArgument instance is no longer usable
|
// ManagedArgument instance is no longer usable
|
||||||
return true;
|
managedArgument.pending = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No parameter value change was attempted and the ManagedArgument
|
|
||||||
// instance may be reused
|
|
||||||
return false;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return ManagedArgument;
|
return ManagedArgument;
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
@@ -836,8 +836,7 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
|||||||
*/
|
*/
|
||||||
ManagedClient.setArgument = function setArgument(managedClient, name, value) {
|
ManagedClient.setArgument = function setArgument(managedClient, name, value) {
|
||||||
var managedArgument = managedClient.arguments[name];
|
var managedArgument = managedClient.arguments[name];
|
||||||
if (managedArgument && ManagedArgument.setValue(managedArgument, value))
|
managedArgument && ManagedArgument.setValue(managedArgument, value);
|
||||||
delete managedClient.arguments[name];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1007,4 +1006,4 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
|||||||
|
|
||||||
return ManagedClient;
|
return ManagedClient;
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* global _ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A directive that allows editing of a collection of fields.
|
* A directive that allows editing of a collection of fields.
|
||||||
@@ -84,6 +85,11 @@ angular.module('form').directive('guacForm', [function form() {
|
|||||||
/**
|
/**
|
||||||
* The client associated with this form, if any.
|
* The client associated with this form, if any.
|
||||||
*
|
*
|
||||||
|
* NOTE: If the provided client has any managed arguments in the
|
||||||
|
* pending state, any fields with the same name rendered by this
|
||||||
|
* form will be disabled. The fields will be re-enabled when guacd
|
||||||
|
* sends an updated argument with a the same name.
|
||||||
|
*
|
||||||
* @type ManagedClient
|
* @type ManagedClient
|
||||||
*/
|
*/
|
||||||
client: '='
|
client: '='
|
||||||
@@ -247,6 +253,28 @@ angular.module('form').directive('guacForm', [function form() {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the given field should be disabled (read-only)
|
||||||
|
* when presented to the current user.
|
||||||
|
*
|
||||||
|
* @param {Field} field
|
||||||
|
* The field to check.
|
||||||
|
*
|
||||||
|
* @returns {Boolean}
|
||||||
|
* true if the given field should be disabled, false otherwise.
|
||||||
|
*/
|
||||||
|
$scope.isDisabled = function isDisabled(field) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The field is disabled if either the form as a whole is disabled,
|
||||||
|
* or if a client is provided to the directive, and the field is
|
||||||
|
* marked as pending.
|
||||||
|
*/
|
||||||
|
return $scope.disabled ||
|
||||||
|
_.get($scope.client, ['arguments', field.name, 'pending']);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether at least one of the given fields should be
|
* Returns whether at least one of the given fields should be
|
||||||
* displayed to the current user.
|
* displayed to the current user.
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
<div class="fields">
|
<div class="fields">
|
||||||
<guac-form-field ng-repeat="field in form.fields" namespace="namespace"
|
<guac-form-field ng-repeat="field in form.fields" namespace="namespace"
|
||||||
ng-if="isVisible(field)"
|
ng-if="isVisible(field)"
|
||||||
data-disabled="disabled"
|
data-disabled="isDisabled(field)"
|
||||||
focused="isFocused(field)"
|
focused="isFocused(field)"
|
||||||
field="field"
|
field="field"
|
||||||
client="client"
|
client="client"
|
||||||
|
Reference in New Issue
Block a user