GUACAMOLE-220: Move common protocol namespace/name retrieval to Protocol class.

This commit is contained in:
Michael Jumper
2018-05-01 12:42:36 -07:00
parent c1f5ad4075
commit 82803c9148
4 changed files with 62 additions and 69 deletions

View File

@@ -29,6 +29,7 @@ angular.module('manage').controller('manageConnectionController', ['$scope', '$i
var HistoryEntryWrapper = $injector.get('HistoryEntryWrapper'); var HistoryEntryWrapper = $injector.get('HistoryEntryWrapper');
var ManagementPermissions = $injector.get('ManagementPermissions'); var ManagementPermissions = $injector.get('ManagementPermissions');
var PermissionSet = $injector.get('PermissionSet'); var PermissionSet = $injector.get('PermissionSet');
var Protocol = $injector.get('Protocol');
// Required services // Required services
var $location = $injector.get('$location'); var $location = $injector.get('$location');
@@ -41,7 +42,6 @@ angular.module('manage').controller('manageConnectionController', ['$scope', '$i
var permissionService = $injector.get('permissionService'); var permissionService = $injector.get('permissionService');
var requestService = $injector.get('requestService'); var requestService = $injector.get('requestService');
var schemaService = $injector.get('schemaService'); var schemaService = $injector.get('schemaService');
var translationStringService = $injector.get('translationStringService');
/** /**
* The unique identifier of the data source containing the connection being * The unique identifier of the data source containing the connection being
@@ -295,51 +295,14 @@ angular.module('manage').controller('manageConnectionController', ['$scope', '$i
}, angular.noop); }, angular.noop);
/** /**
* Returns the translation string namespace for the protocol having the * @borrows Protocol.getNamespace
* given name. The namespace will be of the form:
*
* <code>PROTOCOL_NAME</code>
*
* where <code>NAME</code> is the protocol name transformed via
* translationStringService.canonicalize().
*
* @param {String} protocolName
* The name of the protocol.
*
* @returns {String}
* The translation namespace for the protocol specified, or null if no
* namespace could be generated.
*/ */
$scope.getNamespace = function getNamespace(protocolName) { $scope.getNamespace = Protocol.getNamespace;
// Do not generate a namespace if no protocol is selected
if (!protocolName)
return null;
return 'PROTOCOL_' + translationStringService.canonicalize(protocolName);
};
/** /**
* Given the internal name of a protocol, produces the translation string * @borrows Protocol.getName
* for the localized version of that protocol's name. The translation
* string will be of the form:
*
* <code>NAMESPACE.NAME<code>
*
* where <code>NAMESPACE</code> is the namespace generated from
* $scope.getNamespace().
*
* @param {String} protocolName
* The name of the protocol.
*
* @returns {String}
* The translation string which produces the localized name of the
* protocol specified.
*/ */
$scope.getProtocolName = function getProtocolName(protocolName) { $scope.getProtocolName = Protocol.getName;
return $scope.getNamespace(protocolName) + '.NAME';
};
/** /**
* Cancels all pending edits, returning to the main list of connections * Cancels all pending edits, returning to the main list of connections

View File

@@ -27,6 +27,7 @@ angular.module('manage').controller('manageSharingProfileController', ['$scope',
var ManagementPermissions = $injector.get('ManagementPermissions'); var ManagementPermissions = $injector.get('ManagementPermissions');
var SharingProfile = $injector.get('SharingProfile'); var SharingProfile = $injector.get('SharingProfile');
var PermissionSet = $injector.get('PermissionSet'); var PermissionSet = $injector.get('PermissionSet');
var Protocol = $injector.get('Protocol');
// Required services // Required services
var $location = $injector.get('$location'); var $location = $injector.get('$location');
@@ -38,7 +39,6 @@ angular.module('manage').controller('manageSharingProfileController', ['$scope',
var requestService = $injector.get('requestService'); var requestService = $injector.get('requestService');
var schemaService = $injector.get('schemaService'); var schemaService = $injector.get('schemaService');
var sharingProfileService = $injector.get('sharingProfileService'); var sharingProfileService = $injector.get('sharingProfileService');
var translationStringService = $injector.get('translationStringService');
/** /**
* The unique identifier of the data source containing the sharing profile * The unique identifier of the data source containing the sharing profile
@@ -269,30 +269,9 @@ angular.module('manage').controller('manageSharingProfileController', ['$scope',
}, requestService.WARN); }, requestService.WARN);
/** /**
* Returns the translation string namespace for the protocol having the * @borrows Protocol.getNamespace
* given name. The namespace will be of the form:
*
* <code>PROTOCOL_NAME</code>
*
* where <code>NAME</code> is the protocol name transformed via
* translationStringService.canonicalize().
*
* @param {String} protocolName
* The name of the protocol.
*
* @returns {String}
* The translation namespace for the protocol specified, or null if no
* namespace could be generated.
*/ */
$scope.getNamespace = function getNamespace(protocolName) { $scope.getNamespace = Protocol.getNamespace;
// Do not generate a namespace if no protocol is selected
if (!protocolName)
return null;
return 'PROTOCOL_' + translationStringService.canonicalize(protocolName);
};
/** /**
* Cancels all pending edits, returning to the main list of connections * Cancels all pending edits, returning to the main list of connections

View File

@@ -22,5 +22,6 @@
* Guacamole web application. * Guacamole web application.
*/ */
angular.module('rest', [ angular.module('rest', [
'auth' 'auth',
'locale'
]); ]);

View File

@@ -20,7 +20,10 @@
/** /**
* Service which defines the Protocol class. * Service which defines the Protocol class.
*/ */
angular.module('rest').factory('Protocol', [function defineProtocol() { angular.module('rest').factory('Protocol', ['$injector', function defineProtocol($injector) {
// Required services
var translationStringService = $injector.get('translationStringService');
/** /**
* The object returned by REST API calls when representing the data * The object returned by REST API calls when representing the data
@@ -64,6 +67,53 @@ angular.module('rest').factory('Protocol', [function defineProtocol() {
}; };
/**
* Returns the translation string namespace for the protocol having the
* given name. The namespace will be of the form:
*
* <code>PROTOCOL_NAME</code>
*
* where <code>NAME</code> is the protocol name transformed via
* translationStringService.canonicalize().
*
* @param {String} protocolName
* The name of the protocol.
*
* @returns {String}
* The translation namespace for the protocol specified, or null if no
* namespace could be generated.
*/
Protocol.getNamespace = function getNamespace(protocolName) {
// Do not generate a namespace if no protocol is selected
if (!protocolName)
return null;
return 'PROTOCOL_' + translationStringService.canonicalize(protocolName);
};
/**
* Given the internal name of a protocol, produces the translation string
* for the localized version of that protocol's name. The translation
* string will be of the form:
*
* <code>NAMESPACE.NAME<code>
*
* where <code>NAMESPACE</code> is the namespace generated from
* $scope.getNamespace().
*
* @param {String} protocolName
* The name of the protocol.
*
* @returns {String}
* The translation string which produces the localized name of the
* protocol specified.
*/
Protocol.getName = function getProtocolName(protocolName) {
return Protocol.getNamespace(protocolName) + '.NAME';
};
return Protocol; return Protocol;
}]); }]);