diff --git a/guacamole/src/main/webapp/app/history/types/HistoryEntry.js b/guacamole/src/main/webapp/app/history/types/HistoryEntry.js index e4bdbe038..c6e5dcb0c 100644 --- a/guacamole/src/main/webapp/app/history/types/HistoryEntry.js +++ b/guacamole/src/main/webapp/app/history/types/HistoryEntry.js @@ -37,7 +37,8 @@ angular.module('history').factory('HistoryEntry', [function defineHistoryEntry() var HistoryEntry = function HistoryEntry(id, thumbnail) { /** - * The ID of the connection associated with this history entry. + * The ID of the connection associated with this history entry, + * including type prefix. */ this.id = id; diff --git a/guacamole/src/main/webapp/app/home/controllers/homeController.js b/guacamole/src/main/webapp/app/home/controllers/homeController.js index 77c580b5e..a8d3caccb 100644 --- a/guacamole/src/main/webapp/app/home/controllers/homeController.js +++ b/guacamole/src/main/webapp/app/home/controllers/homeController.js @@ -30,11 +30,7 @@ angular.module('home').controller('homeController', ['$scope', '$injector', var ConnectionGroup = $injector.get("ConnectionGroup"); // Get required services - var connectionGroupService = $injector.get("connectionGroupService"), - guacHistory = $injector.get("guacHistory"); - - // All valid recent connections - $scope.recentConnections = []; + var connectionGroupService = $injector.get("connectionGroupService"); // Set status to loading until we have all the connections and groups loaded $scope.loading = true; diff --git a/guacamole/src/main/webapp/app/home/directives/guacRecentConnections.js b/guacamole/src/main/webapp/app/home/directives/guacRecentConnections.js new file mode 100644 index 000000000..5e8865a91 --- /dev/null +++ b/guacamole/src/main/webapp/app/home/directives/guacRecentConnections.js @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * A directive which displays the contents of a connection group. + */ +angular.module('home').directive('guacRecentConnections', [function guacRecentConnections() { + + return { + restrict: 'E', + replace: true, + scope: { + + /** + * The root connection group, and all visible descendants. + * Recent connections will only be shown if they exist within this + * hierarchy, regardless of their existence within the history. + * + * @type ConnectionGroup + */ + rootGroup : '=' + + }, + + templateUrl: 'app/home/templates/guacRecentConnections.html', + controller: ['$scope', '$injector', 'guacHistory', 'RecentConnection', + function guacGroupListController($scope, $injector, guacHistory, RecentConnection) { + + var visibleObjects = {}; + + /** + * Adds the given connection to the internal set of visible + * objects. + * + * @param {Connection} connection + * The connection to add to the internal set of visible objects. + */ + var addVisibleConnection = function addVisibleConnection(connection) { + + // Add given connection to set of visible objects + visibleObjects['c/' + connection.identifier] = connection; + + }; + + /** + * Adds the given connection group to the internal set of visible + * objects, along with any descendants. + * + * @param {ConnectionGroup} connectionGroup + * The connection group to add to the internal set of visible + * objects, along with any descendants. + */ + var addVisibleConnectionGroup = function addVisibleConnectionGroup(connectionGroup) { + + // Add given connection group to set of visible objects + visibleObjects['g/' + connectionGroup.identifier] = connectionGroup; + + // Add all child connections + if (connectionGroup.childConnections) + connectionGroup.childConnections.forEach(addVisibleConnection); + + // Add all child connection groups + if (connectionGroup.childConnectionGroups) + connectionGroup.childConnectionGroups.forEach(addVisibleConnectionGroup); + + }; + + // Update visible objects when root group is set + $scope.$watch("rootGroup", function setRootGroup(rootGroup) { + + $scope.recentConnections = []; + + // Produce collection of visible objects + visibleObjects = {}; + if (rootGroup) + addVisibleConnectionGroup(rootGroup); + + // Add any recent connections that are visible + guacHistory.recentConnections.forEach(function addRecentConnection(historyEntry) { + + // Add recent connections for history entries with associated visible objects + if (historyEntry.id in visibleObjects) { + + var object = visibleObjects[historyEntry.id]; + $scope.recentConnections.push(new RecentConnection(object.name, historyEntry)); + + } + + }); + + }); // end rootGroup scope watch + + }] + + }; +}]); diff --git a/guacamole/src/main/webapp/app/home/templates/guacRecentConnections.html b/guacamole/src/main/webapp/app/home/templates/guacRecentConnections.html new file mode 100644 index 000000000..152fe8eff --- /dev/null +++ b/guacamole/src/main/webapp/app/home/templates/guacRecentConnections.html @@ -0,0 +1,44 @@ +
+ + + +

{{'home.noRecentConnections' | translate}}

+ + +
+ + + +
+ {{recentConnection.name}} +
+ + +
+ {{recentConnection.name}} +
+ +
+
+ +
diff --git a/guacamole/src/main/webapp/app/home/templates/home.html b/guacamole/src/main/webapp/app/home/templates/home.html index f474ec68c..373a8f990 100644 --- a/guacamole/src/main/webapp/app/home/templates/home.html +++ b/guacamole/src/main/webapp/app/home/templates/home.html @@ -29,20 +29,8 @@

{{'home.recentConnections' | translate}}

-
-

{{'home.noRecentConnections' | translate}}

-
-
-
- -
- {{recentConnection.name}} -
-
- {{recentConnection.name}} -
-
-
+
+
diff --git a/guacamole/src/main/webapp/app/home/types/RecentConnection.js b/guacamole/src/main/webapp/app/home/types/RecentConnection.js new file mode 100644 index 000000000..d28e52b3d --- /dev/null +++ b/guacamole/src/main/webapp/app/home/types/RecentConnection.js @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2014 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * Provides the RecentConnection class used by the guacRecentConnections + * directive. + */ +angular.module('home').factory('RecentConnection', [function defineRecentConnection() { + + /** + * A recently-user connection, visible to the current user, with an + * associated history entry. + * + * @constructor + */ + var RecentConnection = function RecentConnection(name, entry) { + + /** + * The human-readable name of this connection. + * + * @type String + */ + this.name = name; + + /** + * The history entry associated with this recent connection. + * + * @type HistoryEntry + */ + this.entry = entry; + + }; + + return RecentConnection; + +}]);