From 21ee9073d00997468a81df8442a82136c20db97b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 16 Dec 2014 19:25:20 -0800 Subject: [PATCH] GUAC-932: Migrate home to connection list directive. --- .../app/home/controllers/homeController.js | 70 ++++--------------- .../src/main/webapp/app/home/homeModule.js | 2 +- .../main/webapp/app/home/templates/home.html | 28 +------- 3 files changed, 16 insertions(+), 84 deletions(-) diff --git a/guacamole/src/main/webapp/app/home/controllers/homeController.js b/guacamole/src/main/webapp/app/home/controllers/homeController.js index ed3cb09b1..77c580b5e 100644 --- a/guacamole/src/main/webapp/app/home/controllers/homeController.js +++ b/guacamole/src/main/webapp/app/home/controllers/homeController.js @@ -25,71 +25,27 @@ */ angular.module('home').controller('homeController', ['$scope', '$injector', function homeController($scope, $injector) { + + // Get required types + var ConnectionGroup = $injector.get("ConnectionGroup"); - // The parameter name for getting the history from local storage - var GUAC_HISTORY_STORAGE_KEY = "GUAC_HISTORY"; - - // Get the dependencies commonJS style - var legacyConnectionGroupService = $injector.get("legacyConnectionGroupService"); - var guacHistory = $injector.get("guacHistory"); - - // All the connections and connection groups in root - $scope.connectionsAndGroups = []; + // Get required services + var connectionGroupService = $injector.get("connectionGroupService"), + guacHistory = $injector.get("guacHistory"); // All valid recent connections $scope.recentConnections = []; // Set status to loading until we have all the connections and groups loaded $scope.loading = true; - - /* Fetch all connections and groups, then find which recent connections - * still refer to valid connections and groups. - */ - legacyConnectionGroupService.getAllGroupsAndConnections($scope.connectionsAndGroups) - .then(function findRecentConnections() { - - // TODONT: Munch the guacHistory recentConnections list into a legacy-style object - var recentConnections = {}; - for (var i=0; i < guacHistory.recentConnections.length; i++) { - var entry = guacHistory.recentConnections[i]; - recentConnections[encodeURIComponent(entry.id)] = { - id : entry.id, - thumbnail : entry.thumbnail - }; - } - - // Figure out which recent connection entries are valid - $scope.connectionsAndGroups.forEach(function findValidEntries (connectionOrGroup) { - - var type = connectionOrGroup.isConnection ? "c" : "g"; - - // Find the unique ID to index into the recent connections - var uniqueId = encodeURIComponent( - type + "/" + connectionOrGroup.identifier - ); - - /* - * If it's a valid recent connection, add it to the list, - * along with enough information to make a connection url. - */ - var recentConnection = recentConnections[uniqueId]; - if(recentConnection) { - recentConnection.type = type; - recentConnection.id = connectionOrGroup.identifier; - $scope.recentConnections.push(recentConnection); - } - }); - + + // Retrieve root group and all descendants + connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER) + .success(function rootGroupRetrieved(rootConnectionGroup) { + + $scope.rootConnectionGroup = rootConnectionGroup; $scope.loading = false; + }); - /** - * Toggle the open/closed status of the connectionGroup. - * - * @param {object} connectionGroup The connection group to toggle. - */ - $scope.toggleExpanded = function toggleExpanded(connectionGroup) { - connectionGroup.expanded = !connectionGroup.expanded; - }; - }]); diff --git a/guacamole/src/main/webapp/app/home/homeModule.js b/guacamole/src/main/webapp/app/home/homeModule.js index f0eb2f0d4..a3c840e21 100644 --- a/guacamole/src/main/webapp/app/home/homeModule.js +++ b/guacamole/src/main/webapp/app/home/homeModule.js @@ -20,4 +20,4 @@ * THE SOFTWARE. */ -angular.module('home', ['history', 'rest']); +angular.module('home', ['history', 'groupList', 'rest']); diff --git a/guacamole/src/main/webapp/app/home/templates/home.html b/guacamole/src/main/webapp/app/home/templates/home.html index abbb095b0..f474ec68c 100644 --- a/guacamole/src/main/webapp/app/home/templates/home.html +++ b/guacamole/src/main/webapp/app/home/templates/home.html @@ -20,31 +20,6 @@ THE SOFTWARE. --> - -
@@ -73,6 +48,7 @@

{{'home.allConnections' | translate}}

-
+
+
\ No newline at end of file