mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
GUAC-1160: Generalize parameters into fields. Depend on title in field.
This commit is contained in:
@@ -281,26 +281,6 @@ angular.module('manage').controller('manageConnectionController', ['$scope', '$i
|
|||||||
return 'PROTOCOL_' + translationStringService.canonicalize(protocolName) + '.NAME';
|
return 'PROTOCOL_' + translationStringService.canonicalize(protocolName) + '.NAME';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Given the internal name of a protocol and the internal name of a
|
|
||||||
* parameter for that protocol, produces the translation string
|
|
||||||
* for the localized, human-readable name of that protocol parameter.
|
|
||||||
*
|
|
||||||
* @param {String} protocolName
|
|
||||||
* The name of the protocol.
|
|
||||||
*
|
|
||||||
* @param {String} parameterName
|
|
||||||
* The name of the protocol parameter.
|
|
||||||
*
|
|
||||||
* @returns {String}
|
|
||||||
* The translation string which produces the translated name of the
|
|
||||||
* protocol parameter specified.
|
|
||||||
*/
|
|
||||||
$scope.getProtocolParameterName = function getProtocolParameterName(protocolName, parameterName) {
|
|
||||||
return 'PROTOCOL_' + translationStringService.canonicalize(protocolName)
|
|
||||||
+ '.FIELD_HEADER_' + translationStringService.canonicalize(parameterName);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels all pending edits, returning to the management page.
|
* Cancels all pending edits, returning to the management page.
|
||||||
*/
|
*/
|
||||||
|
@@ -33,36 +33,24 @@ angular.module('manage').directive('guacConnectionParameter', [function connecti
|
|||||||
scope: {
|
scope: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The protocol this parameter is associated with.
|
* The field to display.
|
||||||
*
|
*
|
||||||
* @type Protocol
|
* @type Field
|
||||||
*/
|
*/
|
||||||
protocol : '=',
|
field : '=',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The unique name of this parameter within the protocol
|
* The property which contains this fields current value. When this
|
||||||
* definition.
|
* field changes, the property will be updated accordingly.
|
||||||
*
|
*
|
||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
name : '=',
|
model : '='
|
||||||
|
|
||||||
/**
|
|
||||||
* The current map of parameter names to their corresponding string
|
|
||||||
* values.
|
|
||||||
*
|
|
||||||
* @type Object.<String, String>
|
|
||||||
*/
|
|
||||||
parameters : '='
|
|
||||||
|
|
||||||
},
|
},
|
||||||
templateUrl: 'app/manage/templates/connectionParameter.html',
|
templateUrl: 'app/manage/templates/connectionParameter.html',
|
||||||
controller: ['$scope', '$injector', function connectionParameterController($scope, $injector) {
|
controller: ['$scope', '$injector', function connectionParameterController($scope, $injector) {
|
||||||
|
|
||||||
// Required services
|
|
||||||
var $q = $injector.get('$q');
|
|
||||||
var translationStringService = $injector.get('translationStringService');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type to use for password input fields. By default, password
|
* The type to use for password input fields. By default, password
|
||||||
* input fields have type 'password', and are thus masked.
|
* input fields have type 'password', and are thus masked.
|
||||||
@@ -109,122 +97,82 @@ angular.module('manage').directive('guacConnectionParameter', [function connecti
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deferred load of the parameter definition, pending availability
|
* Translates the given string field value into an appropriately-
|
||||||
* of the protocol definition as a whole.
|
* typed value as dictated by the attributes of the field,
|
||||||
|
* exposing that typed value within the scope as
|
||||||
|
* <code>$scope.typedValue<code>.
|
||||||
*
|
*
|
||||||
* @type Deferred
|
* @param {String} modelValue
|
||||||
|
* The current string value of the field.
|
||||||
*/
|
*/
|
||||||
var parameterDefinitionAvailable = $q.defer();
|
var setTypedValue = function setTypedValue(modelValue) {
|
||||||
|
|
||||||
/**
|
// Don't bother if the modelValue is not yet defined
|
||||||
* Populates the parameter definition on the scope as
|
if (!$scope.field)
|
||||||
* <code>$scope.parameter</code> if both the parameter name and
|
|
||||||
* protocol definition are available. If either are unavailable,
|
|
||||||
* this function has no effect.
|
|
||||||
*/
|
|
||||||
var retrieveParameterDefinition = function retrieveParameterDefinition() {
|
|
||||||
|
|
||||||
// Both name and protocol are needed to retrieve the parameter definition
|
|
||||||
if (!$scope.name || !$scope.protocol)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Once protocol definition is available, locate parameter definition by name
|
// Coerce numeric strings to numbers
|
||||||
$scope.protocol.parameters.forEach(function findParameter(parameter) {
|
if ($scope.field.type === 'NUMERIC')
|
||||||
if (parameter.name === $scope.name) {
|
$scope.typedValue = (modelValue ? Number($scope.field.value) : null);
|
||||||
$scope.parameter = parameter;
|
|
||||||
parameterDefinitionAvailable.resolve(parameter);
|
// Coerce boolean strings to boolean values
|
||||||
}
|
else if ($scope.field.type === 'BOOLEAN')
|
||||||
});
|
$scope.typedValue = (modelValue === $scope.field.value);
|
||||||
|
|
||||||
|
// All other parameter types are represented internally as strings
|
||||||
|
else
|
||||||
|
$scope.typedValue = modelValue || '';
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Load parameter definition once protocol definition is available.
|
/**
|
||||||
$scope.$watch('name', retrieveParameterDefinition);
|
* Translates the given typed field value into a string as dictated
|
||||||
$scope.$watch('protocol', retrieveParameterDefinition);
|
* by the attributes of the field, assigning that string value to
|
||||||
|
* the model.
|
||||||
|
*
|
||||||
|
* @param {String|Number|Boolean} typedValue
|
||||||
|
* The current value of the field, as an appropriate JavaScript
|
||||||
|
* type.
|
||||||
|
*/
|
||||||
|
var setModelValue = function setModelValue(typedValue) {
|
||||||
|
|
||||||
|
// Don't bother if the model is not yet defined
|
||||||
|
if (!$scope.field)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Convert numeric values back into strings
|
||||||
|
if ($scope.field.type === 'NUMERIC') {
|
||||||
|
if (!typedValue)
|
||||||
|
$scope.model = '';
|
||||||
|
else
|
||||||
|
$scope.model = typedValue.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert boolean values back into strings based on protocol description
|
||||||
|
else if ($scope.field.type === 'BOOLEAN')
|
||||||
|
$scope.model = (typedValue ? $scope.field.value : '');
|
||||||
|
|
||||||
|
// All other parameter types are already strings
|
||||||
|
else
|
||||||
|
$scope.model = typedValue || '';
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update string value and re-assign to model when field is changed
|
||||||
|
$scope.$watch('field', function setField(field) {
|
||||||
|
setTypedValue($scope.model);
|
||||||
|
setModelValue($scope.typedValue);
|
||||||
|
});
|
||||||
|
|
||||||
// Update typed value when parameter set is changed
|
// Update typed value when parameter set is changed
|
||||||
$scope.$watch('parameters', function setParameters(parameters) {
|
$scope.$watch('model', function setModel(model) {
|
||||||
|
setTypedValue(model);
|
||||||
// Don't bother if no parameters were provided
|
|
||||||
if (!parameters)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Wait for parameter definition
|
|
||||||
parameterDefinitionAvailable.promise.then(function setTypedValue() {
|
|
||||||
|
|
||||||
// Pull parameter value
|
|
||||||
var value = parameters[$scope.name];
|
|
||||||
|
|
||||||
// Coerce numeric strings to numbers
|
|
||||||
if ($scope.parameter.type === 'NUMERIC')
|
|
||||||
$scope.typedValue = (value ? Number(value) : null);
|
|
||||||
|
|
||||||
// Coerce boolean strings to boolean values
|
|
||||||
else if ($scope.parameter.type === 'BOOLEAN')
|
|
||||||
$scope.typedValue = (value === $scope.parameter.value);
|
|
||||||
|
|
||||||
// All other parameter types are represented internally as strings
|
|
||||||
else
|
|
||||||
$scope.typedValue = value || '';
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update string value in parameter set when typed value is changed
|
// Update string value in parameter set when typed value is changed
|
||||||
$scope.$watch('typedValue', function typedValueChanged(typedValue) {
|
$scope.$watch('typedValue', function typedValueChanged(typedValue) {
|
||||||
|
setModelValue(typedValue);
|
||||||
// Don't bother if there's nothing to set
|
});
|
||||||
if (!$scope.parameters)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Wait for parameter definition
|
|
||||||
parameterDefinitionAvailable.promise.then(function setValue() {
|
|
||||||
|
|
||||||
// Convert numeric values back into strings
|
|
||||||
if ($scope.parameter.type === 'NUMERIC') {
|
|
||||||
if (!typedValue)
|
|
||||||
$scope.parameters[$scope.name] = '';
|
|
||||||
else
|
|
||||||
$scope.parameters[$scope.name] = typedValue.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert boolean values back into strings based on protocol description
|
|
||||||
else if ($scope.parameter.type === 'BOOLEAN')
|
|
||||||
$scope.parameters[$scope.name] = (typedValue ? $scope.parameter.value : '');
|
|
||||||
|
|
||||||
// All other parameter types are already strings
|
|
||||||
else
|
|
||||||
$scope.parameters[$scope.name] = typedValue || '';
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}); // end watch typedValue
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Given the internal name of a protocol, the internal name of a
|
|
||||||
* parameter for that protocol, and the internal name for a valid
|
|
||||||
* value of that parameter, produces the translation string for the
|
|
||||||
* localized, human-readable name of that parameter value.
|
|
||||||
*
|
|
||||||
* @param {String} protocolName
|
|
||||||
* The name of the protocol.
|
|
||||||
*
|
|
||||||
* @param {String} parameterName
|
|
||||||
* The name of the protocol parameter.
|
|
||||||
*
|
|
||||||
* @param {String} parameterValue
|
|
||||||
* The name of the parameter value.
|
|
||||||
*
|
|
||||||
* @returns {String}
|
|
||||||
* The translation string which produces the translated name of the
|
|
||||||
* parameter value specified.
|
|
||||||
*/
|
|
||||||
$scope.getProtocolParameterOption = function getProtocolParameterOption(protocolName, parameterName, parameterValue) {
|
|
||||||
return 'PROTOCOL_' + translationStringService.canonicalize(protocolName)
|
|
||||||
+ '.FIELD_OPTION_' + translationStringService.canonicalize(parameterName)
|
|
||||||
+ '_' + translationStringService.canonicalize(parameterValue || 'EMPTY');
|
|
||||||
};
|
|
||||||
|
|
||||||
}] // end controller
|
}] // end controller
|
||||||
};
|
};
|
||||||
|
@@ -22,21 +22,21 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- Generic input types -->
|
<!-- Generic input types -->
|
||||||
<input ng-show="parameter.type === 'TEXT'" type="text" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
|
<input ng-show="field.type === 'TEXT'" type="text" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
|
||||||
<input ng-show="parameter.type === 'NUMERIC'" type="number" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
|
<input ng-show="field.type === 'NUMERIC'" type="number" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
|
||||||
<input ng-show="parameter.type === 'USERNAME'" type="text" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
|
<input ng-show="field.type === 'USERNAME'" type="text" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
|
||||||
<input ng-show="parameter.type === 'BOOLEAN'" type="checkbox" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
|
<input ng-show="field.type === 'BOOLEAN'" type="checkbox" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
|
||||||
|
|
||||||
<!-- Password parameter -->
|
<!-- Password field -->
|
||||||
<div ng-show="parameter.type === 'PASSWORD'" class="password-field">
|
<div ng-show="field.type === 'PASSWORD'" class="password-field">
|
||||||
<input type="{{passwordInputType}}" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
|
<input type="{{passwordInputType}}" ng-model="typedValue" autocorrect="off" autocapitalize="off"/>
|
||||||
<div class="icon toggle-password" ng-click="togglePassword()" title="{{getTogglePasswordHelpText() | translate}}"></div>
|
<div class="icon toggle-password" ng-click="togglePassword()" title="{{getTogglePasswordHelpText() | translate}}"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Multiline parameter -->
|
<!-- Multiline field -->
|
||||||
<textarea ng-show="parameter.type === 'MULTILINE'" ng-model="typedValue" autocorrect="off" autocapitalize="off"></textarea>
|
<textarea ng-show="field.type === 'MULTILINE'" ng-model="typedValue" autocorrect="off" autocapitalize="off"></textarea>
|
||||||
|
|
||||||
<!-- Enumerated parameter -->
|
<!-- Enumerated field -->
|
||||||
<select ng-show="parameter.type === 'ENUM'" ng-model="typedValue" ng-options="option.value as getProtocolParameterOption(protocol.name, parameter.name, option.value) | translate for option in parameter.options | orderBy: value"></select>
|
<select ng-show="field.type === 'ENUM'" ng-model="typedValue" ng-options="option.value as option.title | translate for option in field.options | orderBy: value"></select>
|
||||||
|
|
||||||
</div>
|
</div>
|
@@ -64,9 +64,9 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
<!-- All the different possible editable field types -->
|
<!-- All the different possible editable field types -->
|
||||||
<tr ng-repeat="parameter in protocols[connection.protocol].parameters">
|
<tr ng-repeat="parameter in protocols[connection.protocol].parameters">
|
||||||
<th>{{getProtocolParameterName(connection.protocol, parameter.name) | translate}}</th>
|
<th>{{parameter.title | translate}}</th>
|
||||||
<td>
|
<td>
|
||||||
<guac-connection-parameter protocol="protocols[connection.protocol]" name="parameter.name" parameters="parameters"></guac-connection-parameter>
|
<guac-connection-parameter field="parameter" model="parameters[parameter.name]"></guac-connection-parameter>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
@@ -21,20 +21,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service which defines the ProtocolParameter class.
|
* Service which defines the Field class.
|
||||||
*/
|
*/
|
||||||
angular.module('rest').factory('ProtocolParameter', [function defineProtocolParameter() {
|
angular.module('rest').factory('Field', [function defineField() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The object returned by REST API calls when representing the data
|
* The object returned by REST API calls when representing the data
|
||||||
* associated with a configuration parameter of a remote desktop protocol.
|
* associated with a configuration parameter of a remote desktop protocol.
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {ProtocolParameter|Object} [template={}]
|
* @param {Field|Object} [template={}]
|
||||||
* The object whose properties should be copied within the new
|
* The object whose properties should be copied within the new
|
||||||
* ProtocolParameter.
|
* Field.
|
||||||
*/
|
*/
|
||||||
var ProtocolParameter = function ProtocolParameter(template) {
|
var Field = function Field(template) {
|
||||||
|
|
||||||
// Use empty object by default
|
// Use empty object by default
|
||||||
template = template || {};
|
template = template || {};
|
||||||
@@ -56,12 +56,12 @@ angular.module('rest').factory('ProtocolParameter', [function defineProtocolPara
|
|||||||
/**
|
/**
|
||||||
* The type string defining which values this parameter may contain,
|
* The type string defining which values this parameter may contain,
|
||||||
* as well as what properties are applicable. Valid types are listed
|
* as well as what properties are applicable. Valid types are listed
|
||||||
* within ProtocolParameter.Type.
|
* within Field.Type.
|
||||||
*
|
*
|
||||||
* @type String
|
* @type String
|
||||||
* @default ProtocolParameter.Type.TEXT
|
* @default Field.Type.TEXT
|
||||||
*/
|
*/
|
||||||
this.type = template.type || ProtocolParameter.Type.TEXT;
|
this.type = template.type || Field.Type.TEXT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value to set the parameter to, in the case of a BOOLEAN
|
* The value to set the parameter to, in the case of a BOOLEAN
|
||||||
@@ -75,7 +75,7 @@ angular.module('rest').factory('ProtocolParameter', [function defineProtocolPara
|
|||||||
* All possible legal values for this parameter. This property is only
|
* All possible legal values for this parameter. This property is only
|
||||||
* applicable to ENUM type parameters.
|
* applicable to ENUM type parameters.
|
||||||
*
|
*
|
||||||
* @type ProtocolParameterOption[]
|
* @type FieldOption[]
|
||||||
*/
|
*/
|
||||||
this.options = template.options;
|
this.options = template.options;
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ angular.module('rest').factory('ProtocolParameter', [function defineProtocolPara
|
|||||||
/**
|
/**
|
||||||
* All valid protocol parameter types.
|
* All valid protocol parameter types.
|
||||||
*/
|
*/
|
||||||
ProtocolParameter.Type = {
|
Field.Type = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type string associated with parameters that may contain a single
|
* The type string associated with parameters that may contain a single
|
||||||
@@ -147,6 +147,6 @@ angular.module('rest').factory('ProtocolParameter', [function defineProtocolPara
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return ProtocolParameter;
|
return Field;
|
||||||
|
|
||||||
}]);
|
}]);
|
@@ -21,20 +21,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service which defines the ProtocolParameterOption class.
|
* Service which defines the FieldOption class.
|
||||||
*/
|
*/
|
||||||
angular.module('rest').factory('ProtocolParameterOption', [function defineProtocolParameterOption() {
|
angular.module('rest').factory('FieldOption', [function defineFieldOption() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The object returned by REST API calls when representing a single possible
|
* The object returned by REST API calls when representing a single possible
|
||||||
* legal value of a configuration parameter of a remote desktop protocol.
|
* legal value of a configuration parameter of a remote desktop protocol.
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {ProtocolParameterOption|Object} [template={}]
|
* @param {FieldOption|Object} [template={}]
|
||||||
* The object whose properties should be copied within the new
|
* The object whose properties should be copied within the new
|
||||||
* ProtocolParameterOption.
|
* FieldOption.
|
||||||
*/
|
*/
|
||||||
var ProtocolParameterOption = function ProtocolParameterOption(template) {
|
var FieldOption = function FieldOption(template) {
|
||||||
|
|
||||||
// Use empty object by default
|
// Use empty object by default
|
||||||
template = template || {};
|
template = template || {};
|
||||||
@@ -56,6 +56,6 @@ angular.module('rest').factory('ProtocolParameterOption', [function defineProtoc
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return ProtocolParameterOption;
|
return FieldOption;
|
||||||
|
|
||||||
}]);
|
}]);
|
@@ -57,7 +57,7 @@ angular.module('rest').factory('Protocol', [function defineProtocol() {
|
|||||||
* An array of all known parameters for this protocol, their types,
|
* An array of all known parameters for this protocol, their types,
|
||||||
* and other information.
|
* and other information.
|
||||||
*
|
*
|
||||||
* @type ProtocolParameter[]
|
* @type Field[]
|
||||||
* @default []
|
* @default []
|
||||||
*/
|
*/
|
||||||
this.parameters = template.parameters || [];
|
this.parameters = template.parameters || [];
|
||||||
|
Reference in New Issue
Block a user