Github user jmuehlner commented on a diff in the pull request:
https://github.com/apache/guacamole-client/pull/282#discussion_r185389179
--- Diff:
guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js
---
@@ -157,205 +137,178 @@
angular.module('manage').controller('manageConnectionController', ['$scope', '$i
*/
$scope.isLoaded = function isLoaded() {
- return $scope.protocols !== null
- && $scope.rootGroup !== null
- && $scope.connection !== null
- && $scope.parameters !== null
- && $scope.historyDateFormat !== null
- && $scope.historyEntryWrappers !== null
- && $scope.permissions !== null
- && $scope.attributes !== null
- && $scope.canSaveConnection !== null
- && $scope.canDeleteConnection !== null
- && $scope.canCloneConnection !== null;
+ return $scope.protocols !== null
+ && $scope.rootGroup !== null
+ && $scope.connection !== null
+ && $scope.parameters !== null
+ && $scope.historyDateFormat !== null
+ && $scope.historyEntryWrappers !== null
+ && $scope.managementPermissions !== null
+ && $scope.attributes !== null;
};
- // Pull connection attribute schema
- schemaService.getConnectionAttributes($scope.selectedDataSource)
- .then(function attributesReceived(attributes) {
- $scope.attributes = attributes;
- }, requestService.WARN);
-
- // Pull connection group hierarchy
- connectionGroupService.getConnectionGroupTree(
- $scope.selectedDataSource,
- ConnectionGroup.ROOT_IDENTIFIER,
- [PermissionSet.ObjectPermissionType.ADMINISTER]
- )
- .then(function connectionGroupReceived(rootGroup) {
- $scope.rootGroup = rootGroup;
- }, requestService.WARN);
-
- // Query the user's permissions for the current connection
- permissionService.getEffectivePermissions($scope.selectedDataSource,
authenticationService.getCurrentUsername())
- .then(function permissionsReceived(permissions) {
-
- $scope.permissions = permissions;
-
- // Check if the connection is new or if the user has UPDATE
permission
- $scope.canSaveConnection =
- !identifier
- || PermissionSet.hasSystemPermission(permissions,
PermissionSet.SystemPermissionType.ADMINISTER)
- || PermissionSet.hasConnectionPermission(permissions,
PermissionSet.ObjectPermissionType.UPDATE, identifier);
-
- // Check if connection is not new and the user has DELETE
permission
- $scope.canDeleteConnection =
- !!identifier && (
- PermissionSet.hasSystemPermission(permissions,
PermissionSet.SystemPermissionType.ADMINISTER)
- || PermissionSet.hasConnectionPermission(permissions,
PermissionSet.ObjectPermissionType.DELETE, identifier)
- );
-
- // Check if the connection is not new and the user has UPDATE and
CREATE_CONNECTION permissions
- $scope.canCloneConnection =
- !!identifier && (
- PermissionSet.hasSystemPermission(permissions,
PermissionSet.SystemPermissionType.ADMINISTER) || (
- PermissionSet.hasConnectionPermission(permissions,
PermissionSet.ObjectPermissionType.UPDATE, identifier)
- && PermissionSet.hasSystemPermission(permissions,
PermissionSet.SystemPermissionType.CREATE_CONNECTION)
- )
- );
-
- }, requestService.WARN);
-
- // Get protocol metadata
- schemaService.getProtocols($scope.selectedDataSource)
- .then(function protocolsReceived(protocols) {
- $scope.protocols = protocols;
- }, requestService.WARN);
-
- // Get history date format
- $translate('MANAGE_CONNECTION.FORMAT_HISTORY_START').then(function
historyDateFormatReceived(historyDateFormat) {
- $scope.historyDateFormat = historyDateFormat;
- }, angular.noop);
-
- // If we are editing an existing connection, pull its data
- if (identifier) {
-
- // Pull data from existing connection
- connectionService.getConnection($scope.selectedDataSource,
identifier)
- .then(function connectionRetrieved(connection) {
- $scope.connection = connection;
- }, requestService.WARN);
+ /**
+ * Loads the data associated with the connection having the given
+ * identifier, preparing the interface for making modifications to that
+ * existing connection.
+ *
+ * @param {String} dataSource
+ * The unique identifier of the data source containing the
connection to
+ * load.
+ *
+ * @param {String} identifier
+ * The identifier of the connection to load.
+ *
+ * @returns {Promise}
+ * A promise which is resolved when the interface has been
prepared for
+ * editing the given connection.
+ */
+ var loadExistingConnection = function
loadExistingConnection(dataSource, identifier) {
+ return $q.all({
+ connection : connectionService.getConnection(dataSource,
identifier),
+ historyEntries :
connectionService.getConnectionHistory(dataSource, identifier),
+ parameters :
connectionService.getConnectionParameters(dataSource, identifier)
+ })
+ .then(function connectionDataRetrieved(values) {
- // Pull connection history
- connectionService.getConnectionHistory($scope.selectedDataSource,
identifier)
- .then(function historyReceived(historyEntries) {
+ $scope.connection = values.connection;
+ $scope.parameters = values.parameters;
// Wrap all history entries for sake of display
$scope.historyEntryWrappers = [];
- historyEntries.forEach(function wrapHistoryEntry(historyEntry)
{
- $scope.historyEntryWrappers.push(new
HistoryEntryWrapper(historyEntry));
+ angular.forEach(values.historyEntries, function
wrapHistoryEntry(historyEntry) {
+ $scope.historyEntryWrappers.push(new
HistoryEntryWrapper(historyEntry));
});
- }, requestService.WARN);
+ });
+ };
- // Pull connection parameters
-
connectionService.getConnectionParameters($scope.selectedDataSource, identifier)
- .then(function parametersReceived(parameters) {
- $scope.parameters = parameters;
- }, requestService.WARN);
- }
-
- // If we are cloning an existing connection, pull its data instead
- else if (cloneSourceIdentifier) {
+ /**
+ * Loads the data associated with the connection having the given
+ * identifier, preparing the interface for cloning that existing
+ * connection.
+ *
+ * @param {String} dataSource
+ * The unique identifier of the data source containing the
connection
+ * to be cloned.
+ *
+ * @param {String} identifier
+ * The identifier of the connection being cloned.
+ *
+ * @returns {Promise}
+ * A promise which is resolved when the interface has been
prepared for
+ * cloning the given connection.
+ */
+ var loadClonedConnection = function loadClonedConnection(dataSource,
identifier) {
+ return $q.all({
+ connection : connectionService.getConnection(dataSource,
identifier),
+ parameters :
connectionService.getConnectionParameters(dataSource, identifier)
+ })
+ .then(function connectionDataRetrieved(values) {
+
+ $scope.connection = values.connection;
+ $scope.parameters = values.parameters;
- // Pull data from cloned connection
- connectionService.getConnection($scope.selectedDataSource,
cloneSourceIdentifier)
- .then(function connectionRetrieved(connection) {
- $scope.connection = connection;
-
// Clear the identifier field because this connection is new
delete $scope.connection.identifier;
- }, requestService.WARN);
- // Do not pull connection history
- $scope.historyEntryWrappers = [];
-
- // Pull connection parameters from cloned connection
-
connectionService.getConnectionParameters($scope.selectedDataSource,
cloneSourceIdentifier)
- .then(function parametersReceived(parameters) {
- $scope.parameters = parameters;
- }, requestService.WARN);
- }
-
- // If we are creating a new connection, populate skeleton connection
data
- else {
+ // Cloned connections have no history
+ $scope.historyEntryWrappers = [];
+
+ });
+ };
+
+ /**
+ * Loads skeleton connection data, preparing the interface for
creating a
+ * new connection.
+ *
+ * @returns {Promise}
+ * A promise which is resolved when the interface has been
prepared for
+ * creating a new connection.
+ */
+ var loadSkeletonConnection = function loadSkeletonConnection() {
+
+ // Use skeleton connection object with no associated permissions,
+ // history, or parameters
$scope.connection = new Connection({
protocol : 'vnc',
parentIdentifier : $location.search().parent
});
$scope.historyEntryWrappers = [];
$scope.parameters = {};
- }
- /**
- * Returns whether the current user can change/set all connection
- * attributes for the connection being edited, regardless of whether
those
- * attributes are already explicitly associated with that connection.
- *
- * @returns {Boolean}
- * true if the current user can change all attributes for the
- * connection being edited, regardless of whether those attributes
are
- * already explicitly associated with that connection, false
otherwise.
- */
- $scope.canChangeAllAttributes = function canChangeAllAttributes() {
-
- // All attributes can be set if we are creating the connection
- return !identifier;
+ return $q.resolve();
};
/**
- * Returns the translation string namespace for the protocol having the
- * given name. The namespace will be of the form:
- *
- * <code>PROTOCOL_NAME</code>
+ * Loads the data requred for performing the management task requested
--- End diff --
`requred`?
---