From 66e7fb22340e3fabc0d556b64f23bd407e29adde Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 19 Dec 2014 12:57:12 -0800 Subject: [PATCH] GUAC-932: Migrate internals of locationChooser to guacGroupList. --- .../manage/controllers/manageController.js | 2 - .../app/manage/directives/locationChooser.js | 140 +++++++++++------- .../manage/templates/editableConnection.html | 2 +- .../templates/editableConnectionGroup.html | 2 +- .../app/manage/templates/locationChooser.html | 27 +--- .../locationChooserConnectionGroup.html | 25 ++++ 6 files changed, 124 insertions(+), 74 deletions(-) create mode 100644 guacamole/src/main/webapp/app/manage/templates/locationChooserConnectionGroup.html diff --git a/guacamole/src/main/webapp/app/manage/controllers/manageController.js b/guacamole/src/main/webapp/app/manage/controllers/manageController.js index b3fa97381..d8182d8e0 100644 --- a/guacamole/src/main/webapp/app/manage/controllers/manageController.js +++ b/guacamole/src/main/webapp/app/manage/controllers/manageController.js @@ -105,7 +105,6 @@ angular.module('manage').controller('manageController', ['$scope', '$injector', { connection : {}, protocols : $scope.protocols, - moveItem : $scope.moveItem, rootGroup : $scope.rootGroup }); }; @@ -117,7 +116,6 @@ angular.module('manage').controller('manageController', ['$scope', '$injector', connectionGroupEditModal.activate( { connectionGroup : {}, - moveItem : $scope.moveItem, rootGroup : $scope.rootGroup }); }; diff --git a/guacamole/src/main/webapp/app/manage/directives/locationChooser.js b/guacamole/src/main/webapp/app/manage/directives/locationChooser.js index d476a0ffb..9b0961bbf 100644 --- a/guacamole/src/main/webapp/app/manage/directives/locationChooser.js +++ b/guacamole/src/main/webapp/app/manage/directives/locationChooser.js @@ -30,63 +30,101 @@ angular.module('manage').directive('locationChooser', [function locationChooser( // Element only restrict: 'E', replace: true, + scope: { - item: '=item', - root: '=root', + + /** + * The root connection group of the connection group hierarchy to + * display. + * + * @type ConnectionGroup + */ + rootGroup : '=', + + /** + * The unique identifier of the currently-selected connection + * group. If not specified, the root group will be used. + * + * @type String + */ + value : '=' + }, + templateUrl: 'app/manage/templates/locationChooser.html', - controller: ['$scope', '$injector', function locationChooserController($scope, $injector) { - // The dropdown should start closed - $scope.showDropDown = false; - - // Map of ID to name for all connection groups - $scope.connectionGroupNameMap = {}; - - // Set up the group for display and search - mapConnectionGroupNames($scope.root); - $scope.connectionGroups = [$scope.root]; + controller: ['$scope', function locationChooserController($scope) { - // Should be in the root group by default - if(!$scope.item.parentIdentifier) - $scope.item.parentIdentifier = $scope.root.parentIdentifier; + /** + * Map of unique identifiers to their corresponding connection + * groups. + * + * @type Object. + */ + var connectionGroups = {}; + + var mapConnectionGroups = function mapConnectionGroups(group) { + + // Map given group + connectionGroups[group.identifier] = group; + + // Map all child groups + group.childConnectionGroups.forEach(mapConnectionGroups); + + }; + + // Map all known groups + mapConnectionGroups($scope.rootGroup); + + // If no value is specified, default to the root identifier + if (!$scope.value || !($scope.value in connectionGroups)) + $scope.value = $scope.rootGroup.identifier; + + /** + * Whether the group list menu is currently open. + * + * @type Boolean + */ + $scope.menuOpen = false; + + /** + * The human-readable name of the currently-chosen connection + * group. + * + * @type String + */ + $scope.chosenConnectionGroupName = connectionGroups[$scope.value].name; + + /** + * Toggle the current state of the menu listing connection groups. + * If the menu is currently open, it will be closed. If currently + * closed, it will be opened. + */ + $scope.toggleMenu = function toggleMenu() { + $scope.menuOpen = !$scope.menuOpen; + }; + + // Expose selection function to group list template + $scope.groupListContext = { + + /** + * Selects the given group item. + * + * @param {GroupListItem} item + * The chosen item. + */ + chooseGroup : function chooseGroup(item) { + + // Record new parent + $scope.value = item.identifier; + $scope.chosenConnectionGroupName = item.name; + + // Close menu + $scope.menuOpen = false; - setCurrentParentName(); - - // Add the name of all connection groups under group to the group name map - function mapConnectionGroupNames(group) { - $scope.connectionGroupNameMap[group.identifier] = group.name; - for(var i = 0; i < group.children.length; i++) { - var child = group.children[i]; - if(!child.isConnection) - mapConnectionGroupNames(child); } - } - - //Set the current connection group name to the name of the connection group with the currently chosen ID - function setCurrentParentName() { - $scope.currentConnectionGroupName = $scope.connectionGroupNameMap[$scope.item.parentIdentifier]; - } - - // Watch for changes to the parentID, and update the current name as needed - $scope.currentConnectionGroupName = ""; - $scope.$watch('item.parentIdentifier', function watchParentID() { - setCurrentParentName(); - }); - - /** - * Toggle the drop down - open or closed. - */ - $scope.toggleDropDown = function toggleDropDown() { - $scope.showDropDown = !$scope.showDropDown; - } - - /** - * Choose a new parent ID for the item. - * @param {type} parentID The new parentID. - */ - $scope.chooseParentID = function chooseParentID(parentID) { - $scope.item.parentIdentifier = parentID; - } + + }; + }] }; diff --git a/guacamole/src/main/webapp/app/manage/templates/editableConnection.html b/guacamole/src/main/webapp/app/manage/templates/editableConnection.html index f9ee65458..a46883c2d 100644 --- a/guacamole/src/main/webapp/app/manage/templates/editableConnection.html +++ b/guacamole/src/main/webapp/app/manage/templates/editableConnection.html @@ -50,7 +50,7 @@ THE SOFTWARE. {{'manage.edit.connection.location' | translate}} - + diff --git a/guacamole/src/main/webapp/app/manage/templates/editableConnectionGroup.html b/guacamole/src/main/webapp/app/manage/templates/editableConnectionGroup.html index 13a04e2e0..f10a348db 100644 --- a/guacamole/src/main/webapp/app/manage/templates/editableConnectionGroup.html +++ b/guacamole/src/main/webapp/app/manage/templates/editableConnectionGroup.html @@ -50,7 +50,7 @@ THE SOFTWARE. {{'manage.edit.connectionGroup.location' | translate}} - + diff --git a/guacamole/src/main/webapp/app/manage/templates/locationChooser.html b/guacamole/src/main/webapp/app/manage/templates/locationChooser.html index 2bf72826e..8f7b793d5 100644 --- a/guacamole/src/main/webapp/app/manage/templates/locationChooser.html +++ b/guacamole/src/main/webapp/app/manage/templates/locationChooser.html @@ -21,26 +21,15 @@ THE SOFTWARE. --> - - -
{{currentConnectionGroupName}}
+
{{chosenConnectionGroupName}}
- diff --git a/guacamole/src/main/webapp/app/manage/templates/locationChooserConnectionGroup.html b/guacamole/src/main/webapp/app/manage/templates/locationChooserConnectionGroup.html new file mode 100644 index 000000000..fefaa7eac --- /dev/null +++ b/guacamole/src/main/webapp/app/manage/templates/locationChooserConnectionGroup.html @@ -0,0 +1,25 @@ + + + + {{item.name}} +