You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by jm...@apache.org on 2016/08/10 23:45:07 UTC

[4/5] incubator-guacamole-client git commit: GUACAMOLE-5: Use contextual actions to add connections and connection groups.

GUACAMOLE-5: Use contextual actions to add connections and connection groups.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/5779274e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/5779274e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/5779274e

Branch: refs/heads/master
Commit: 5779274e257f0d05fee94aa52beb3017290ea2b8
Parents: 4c7af7e
Author: Michael Jumper <mj...@apache.org>
Authored: Sun Aug 7 23:41:09 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sun Aug 7 23:41:09 2016 -0700

----------------------------------------------------------------------
 .../controllers/manageConnectionController.js   |   5 +-
 .../manageConnectionGroupController.js          |   4 +-
 .../directives/guacSettingsConnections.js       | 133 +++++++++++++++++--
 .../app/settings/styles/connection-list.css     |  34 +++++
 .../app/settings/templates/newConnection.html   |   3 +
 .../settings/templates/newConnectionGroup.html  |   3 +
 .../settings/templates/settingsConnections.html |   8 +-
 7 files changed, 174 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/5779274e/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js
index 0e21873..a911ab2 100644
--- a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js
+++ b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionController.js
@@ -291,7 +291,10 @@ angular.module('manage').controller('manageConnectionController', ['$scope', '$i
 
     // If we are creating a new connection, populate skeleton connection data
     else {
-        $scope.connection = new Connection({ protocol: 'vnc' });
+        $scope.connection = new Connection({
+            protocol         : 'vnc',
+            parentIdentifier : $location.search().parent
+        });
         $scope.historyEntryWrappers = [];
         $scope.parameters = {};
     }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/5779274e/guacamole/src/main/webapp/app/manage/controllers/manageConnectionGroupController.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionGroupController.js b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionGroupController.js
index d76b27a..0d0af59 100644
--- a/guacamole/src/main/webapp/app/manage/controllers/manageConnectionGroupController.js
+++ b/guacamole/src/main/webapp/app/manage/controllers/manageConnectionGroupController.js
@@ -175,7 +175,9 @@ angular.module('manage').controller('manageConnectionGroupController', ['$scope'
 
     // If we are creating a new connection group, populate skeleton connection group data
     else
-        $scope.connectionGroup = new ConnectionGroup();
+        $scope.connectionGroup = new ConnectionGroup({
+            parentIdentifier : $location.search().parent
+        });
 
     /**
      * Available connection group types, as translation string / internal value

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/5779274e/guacamole/src/main/webapp/app/settings/directives/guacSettingsConnections.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/settings/directives/guacSettingsConnections.js b/guacamole/src/main/webapp/app/settings/directives/guacSettingsConnections.js
index 1414f91..b174a8d 100644
--- a/guacamole/src/main/webapp/app/settings/directives/guacSettingsConnections.js
+++ b/guacamole/src/main/webapp/app/settings/directives/guacSettingsConnections.js
@@ -35,6 +35,7 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
 
             // Required types
             var ConnectionGroup = $injector.get('ConnectionGroup');
+            var GroupListItem   = $injector.get('GroupListItem');
             var PermissionSet   = $injector.get('PermissionSet');
 
             // Required services
@@ -205,6 +206,112 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
 
             };
 
+            /**
+             * Returns whether the current user can update the connection group
+             * having the given identifier within the current data source.
+             *
+             * @param {String} identifier
+             *     The identifier of the connection group to check.
+             *
+             * @return {Boolean}
+             *     true if the current user can update the connection group
+             *     having the given identifier within the current data source,
+             *     false otherwise.
+             */
+            $scope.canUpdateConnectionGroup = function canUpdateConnectionGroup(identifier) {
+
+                // Abort if permissions have not yet loaded
+                if (!$scope.permissions)
+                    return false;
+
+                // Can update the connection if adminstrator or have explicit permission
+                if (PermissionSet.hasSystemPermission($scope.permissions, PermissionSet.SystemPermissionType.ADMINISTER)
+                 || PermissionSet.hasConnectionGroupPermission($scope.permissions, PermissionSet.ObjectPermissionType.UPDATE, identifier))
+                     return true;
+
+                // Current data sources does not allow the connection group to be updated
+                return false;
+
+            };
+
+            /**
+             * Adds connection-group-specific contextual actions to the given
+             * array of GroupListItems. Each contextual action will be
+             * represented by a new GroupListItem.
+             *
+             * @param {GroupListItem[]} items
+             *     The array of GroupListItems to which new GroupListItems
+             *     representing connection-group-specific contextual actions
+             *     should be added.
+             *
+             * @param {GroupListItem} [parent]
+             *     The GroupListItem representing the connection group which
+             *     contains the given array of GroupListItems, if known.
+             */
+            var addConnectionGroupActions = function addConnectionGroupActions(items, parent) {
+
+                // Do nothing if we lack permission to modify the parent at all
+                if (parent && !$scope.canUpdateConnectionGroup(parent.identifier))
+                    return;
+
+                // Add action for creating a child connection, if the user has
+                // permission to do so
+                if ($scope.canCreateConnections())
+                    items.push(new GroupListItem({
+                        type        : 'new-connection',
+                        dataSource  : $scope.dataSource,
+                        weight      : 1,
+                        wrappedItem : parent
+                    }));
+
+                // Add action for creating a child connection group, if the user
+                // has permission to do so
+                if ($scope.canCreateConnectionGroups())
+                    items.push(new GroupListItem({
+                        type        : 'new-connection-group',
+                        dataSource  : $scope.dataSource,
+                        weight      : 1,
+                        wrappedItem : parent
+                    }));
+
+            };
+
+            /**
+             * Decorates the given GroupListItem, including all descendants,
+             * adding contextual actions.
+             *
+             * @param {GroupListItem} item
+             *     The GroupListItem which should be decorated with additional
+             *     GroupListItems representing contextual actions.
+             */
+            var decorateItem = function decorateItem(item) {
+
+                // If the item is a connection group, add actions specific to
+                // connection groups
+                if (item.type === GroupListItem.Type.CONNECTION_GROUP)
+                    addConnectionGroupActions(item.children, item);
+
+                // Decorate all children
+                angular.forEach(item.children, decorateItem);
+
+            };
+
+            /**
+             * Callback which decorates all items within the given array of
+             * GroupListItems, including their descendants, adding contextual
+             * actions.
+             *
+             * @param {GroupListItem[]} items
+             *     The array of GroupListItems which should be decorated with
+             *     additional GroupListItems representing contextual actions.
+             */
+            $scope.rootItemDecorator = function rootItemDecorator(items) {
+
+                // Decorate each root-level item
+                angular.forEach(items, decorateItem);
+
+            };
+
             // Retrieve current permissions
             permissionService.getPermissions($scope.dataSource, currentUsername)
             .success(function permissionsRetrieved(permissions) {
@@ -219,19 +326,19 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
                 if (!$scope.canManageConnections())
                     $location.path('/');
 
-            });
-            
-            // Retrieve all connections for which we have UPDATE or DELETE permission
-            dataSourceService.apply(
-                connectionGroupService.getConnectionGroupTree,
-                [$scope.dataSource],
-                ConnectionGroup.ROOT_IDENTIFIER,
-                [PermissionSet.ObjectPermissionType.UPDATE, PermissionSet.ObjectPermissionType.DELETE]
-            )
-            .then(function connectionGroupsReceived(rootGroups) {
-                $scope.rootGroups = rootGroups;
-            });
-            
+                // Retrieve all connections for which we have UPDATE or DELETE permission
+                dataSourceService.apply(
+                    connectionGroupService.getConnectionGroupTree,
+                    [$scope.dataSource],
+                    ConnectionGroup.ROOT_IDENTIFIER,
+                    [PermissionSet.ObjectPermissionType.UPDATE, PermissionSet.ObjectPermissionType.DELETE]
+                )
+                .then(function connectionGroupsReceived(rootGroups) {
+                    $scope.rootGroups = rootGroups;
+                });
+
+            }); // end retrieve permissions
+
         }]
     };
     

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/5779274e/guacamole/src/main/webapp/app/settings/styles/connection-list.css
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/settings/styles/connection-list.css b/guacamole/src/main/webapp/app/settings/styles/connection-list.css
new file mode 100644
index 0000000..7bf3553
--- /dev/null
+++ b/guacamole/src/main/webapp/app/settings/styles/connection-list.css
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+.settings.connections .connection-list .new-connection,
+.settings.connections .connection-list .new-connection-group {
+    opacity: 0.5;
+    font-style: italic;
+}
+
+.settings.connections .connection-list .new-connection a,
+.settings.connections .connection-list .new-connection a:hover,
+.settings.connections .connection-list .new-connection a:visited,
+.settings.connections .connection-list .new-connection-group a,
+.settings.connections .connection-list .new-connection-group a:hover,
+.settings.connections .connection-list .new-connection-group a:visited {
+    text-decoration:none;
+    color: black;
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/5779274e/guacamole/src/main/webapp/app/settings/templates/newConnection.html
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/settings/templates/newConnection.html b/guacamole/src/main/webapp/app/settings/templates/newConnection.html
new file mode 100644
index 0000000..e4debbe
--- /dev/null
+++ b/guacamole/src/main/webapp/app/settings/templates/newConnection.html
@@ -0,0 +1,3 @@
+<a ng-href="#/manage/{{item.dataSource}}/connections/?parent={{item.wrappedItem.identifier}}">
+    <span class="name">{{'SETTINGS_CONNECTIONS.ACTION_NEW_CONNECTION' | translate}}</span>
+</a>

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/5779274e/guacamole/src/main/webapp/app/settings/templates/newConnectionGroup.html
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/settings/templates/newConnectionGroup.html b/guacamole/src/main/webapp/app/settings/templates/newConnectionGroup.html
new file mode 100644
index 0000000..c1d6bba
--- /dev/null
+++ b/guacamole/src/main/webapp/app/settings/templates/newConnectionGroup.html
@@ -0,0 +1,3 @@
+<a ng-href="#/manage/{{item.dataSource}}/connectionGroups/?parent={{item.wrappedItem.identifier}}">
+    <span class="name">{{'SETTINGS_CONNECTIONS.ACTION_NEW_CONNECTION_GROUP' | translate}}</span>
+</a>

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/5779274e/guacamole/src/main/webapp/app/settings/templates/settingsConnections.html
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/settings/templates/settingsConnections.html b/guacamole/src/main/webapp/app/settings/templates/settingsConnections.html
index d56993e..dfdf686 100644
--- a/guacamole/src/main/webapp/app/settings/templates/settingsConnections.html
+++ b/guacamole/src/main/webapp/app/settings/templates/settingsConnections.html
@@ -33,9 +33,15 @@
         <guac-group-list
             page-size="25"
             connection-groups="filteredRootGroups"
+            decorator="rootItemDecorator"
             templates="{
+
                 'connection'       : 'app/settings/templates/connection.html',
-                'connection-group' : 'app/settings/templates/connectionGroup.html'
+                'connection-group' : 'app/settings/templates/connectionGroup.html',
+
+                'new-connection'       : 'app/settings/templates/newConnection.html',
+                'new-connection-group' : 'app/settings/templates/newConnectionGroup.html'
+
             }"/>
     </div>
 </div>