mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-932: Migrate home to connection list directive.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
}]);
|
||||
|
@@ -20,4 +20,4 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
angular.module('home', ['history', 'rest']);
|
||||
angular.module('home', ['history', 'groupList', 'rest']);
|
||||
|
@@ -20,31 +20,6 @@
|
||||
THE SOFTWARE.
|
||||
-->
|
||||
|
||||
<script type="text/ng-template" id="nestedGroup.html">
|
||||
<div class="connection" ng-show="item.isConnection">
|
||||
<a ng-href="#/client/c/{{item.identifier}}">
|
||||
<div class="caption">
|
||||
<div class="protocol">
|
||||
<div class="icon type" ng-class="item.protocol"></div>
|
||||
</div>
|
||||
<span class="name">{{item.name}}</span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="group" ng-show="!item.isConnection">
|
||||
<div class="caption">
|
||||
<div class="icon group type" ng-click="toggleExpanded(item)" ng-class="{expanded: item.expanded, empty: !item.children.length, balancer: item.balancer && !item.children.length}"></div>
|
||||
<span class="name">
|
||||
<a ng-show="item.balancer" ng-href="#/client/g/{{item.identifier}}">{{item.name}}</a>
|
||||
<span ng-show="!item.balancer">{{item.name}}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="children" ng-show="item.expanded">
|
||||
<div class="list-item" ng-repeat="item in item.children | orderBy : 'name'" ng-include="'nestedGroup.html'">
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<div class="connection-list-ui">
|
||||
|
||||
<div class="logout-panel">
|
||||
@@ -73,6 +48,7 @@
|
||||
<!-- All connections for this user -->
|
||||
<h2>{{'home.allConnections' | translate}}</h2>
|
||||
<div class="all-connections" ng-class="{loading: loading}">
|
||||
<div class="list-item" ng-repeat="item in connectionsAndGroups | orderBy : 'name'" ng-include="'nestedGroup.html'"></div>
|
||||
<guac-group-list connection-group="rootConnectionGroup"/>
|
||||
</div>
|
||||
|
||||
</div>
|
Reference in New Issue
Block a user