mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-09 14:41:21 +00:00
Merge pull request #133 from glyptodon/client-user-menu
GUAC-1126: Add user menu to Guacamole menu
This commit is contained in:
@@ -69,7 +69,7 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-header {
|
.menu-content .header {
|
||||||
|
|
||||||
-ms-flex: 0 0 auto;
|
-ms-flex: 0 0 auto;
|
||||||
-moz-box-flex: 0;
|
-moz-box-flex: 0;
|
||||||
@@ -77,60 +77,7 @@
|
|||||||
-webkit-flex: 0 0 auto;
|
-webkit-flex: 0 0 auto;
|
||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
|
|
||||||
/* IE10 */
|
margin-bottom: 0;
|
||||||
display: -ms-flexbox;
|
|
||||||
-ms-flex-align: center;
|
|
||||||
-ms-flex-direction: row;
|
|
||||||
|
|
||||||
/* Ancient Mozilla */
|
|
||||||
display: -moz-box;
|
|
||||||
-moz-box-align: center;
|
|
||||||
-moz-box-orient: horizontal;
|
|
||||||
|
|
||||||
/* Ancient WebKit */
|
|
||||||
display: -webkit-box;
|
|
||||||
-webkit-box-align: center;
|
|
||||||
-webkit-box-orient: horizontal;
|
|
||||||
|
|
||||||
/* Old WebKit */
|
|
||||||
display: -webkit-flex;
|
|
||||||
-webkit-align-items: center;
|
|
||||||
-webkit-flex-direction: row;
|
|
||||||
|
|
||||||
/* W3C */
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
flex-direction: row;
|
|
||||||
|
|
||||||
padding: 0.75em 0.5em;
|
|
||||||
|
|
||||||
border-bottom: 1px solid rgba(0, 0, 0, 0.125);
|
|
||||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.125);
|
|
||||||
background: rgba(0, 0, 0, 0.04);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-header > * {
|
|
||||||
-ms-flex: 0 0 auto;
|
|
||||||
-moz-box-flex: 0;
|
|
||||||
-webkit-box-flex: 0;
|
|
||||||
-webkit-flex: 0 0 auto;
|
|
||||||
flex: 0 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-header > h2 {
|
|
||||||
|
|
||||||
-ms-flex: 1 1 auto;
|
|
||||||
-moz-box-flex: 1;
|
|
||||||
-webkit-box-flex: 1;
|
|
||||||
-webkit-flex: 1 1 auto;
|
|
||||||
flex: 1 1 auto;
|
|
||||||
|
|
||||||
border: none;
|
|
||||||
padding: 0;
|
|
||||||
box-shadow: none;
|
|
||||||
background: none;
|
|
||||||
margin: 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -57,10 +57,9 @@
|
|||||||
<div class="menu-content">
|
<div class="menu-content">
|
||||||
|
|
||||||
<!-- Stationary header -->
|
<!-- Stationary header -->
|
||||||
<div class="menu-header">
|
<div class="header">
|
||||||
<h2>{{client.name}}</h2>
|
<h2>{{client.name}}</h2>
|
||||||
<a class="home button" href="#/">{{'CLIENT.ACTION_NAVIGATE_HOME' | translate}}</a>
|
<guac-user-menu></guac-user-menu>
|
||||||
<a class="disconnect danger button" ng-click="disconnect()">{{'CLIENT.ACTION_DISCONNECT' | translate}}</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Scrollable body -->
|
<!-- Scrollable body -->
|
||||||
|
@@ -30,11 +30,8 @@ angular.module('home').controller('homeController', ['$scope', '$injector',
|
|||||||
var ConnectionGroup = $injector.get("ConnectionGroup");
|
var ConnectionGroup = $injector.get("ConnectionGroup");
|
||||||
|
|
||||||
// Get required services
|
// Get required services
|
||||||
var $location = $injector.get("$location");
|
|
||||||
var authenticationService = $injector.get("authenticationService");
|
var authenticationService = $injector.get("authenticationService");
|
||||||
var connectionGroupService = $injector.get("connectionGroupService");
|
var connectionGroupService = $injector.get("connectionGroupService");
|
||||||
var permissionService = $injector.get("permissionService");
|
|
||||||
var userPageService = $injector.get("userPageService");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The root connection group, or null if the connection group hierarchy has
|
* The root connection group, or null if the connection group hierarchy has
|
||||||
@@ -44,14 +41,6 @@ angular.module('home').controller('homeController', ['$scope', '$injector',
|
|||||||
*/
|
*/
|
||||||
$scope.rootConnectionGroup = null;
|
$scope.rootConnectionGroup = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* All permissions associated with the current user, or null if the user's
|
|
||||||
* permissions have not yet been loaded.
|
|
||||||
*
|
|
||||||
* @type PermissionSet
|
|
||||||
*/
|
|
||||||
$scope.permissions = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether critical data has completed being loaded.
|
* Returns whether critical data has completed being loaded.
|
||||||
*
|
*
|
||||||
@@ -61,27 +50,14 @@ angular.module('home').controller('homeController', ['$scope', '$injector',
|
|||||||
*/
|
*/
|
||||||
$scope.isLoaded = function isLoaded() {
|
$scope.isLoaded = function isLoaded() {
|
||||||
|
|
||||||
return $scope.rootConnectionGroup !== null
|
return $scope.rootConnectionGroup !== null;
|
||||||
&& $scope.permissions !== null;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Retrieve root group and all descendants
|
// Retrieve root group and all descendants
|
||||||
connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER)
|
connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER)
|
||||||
.success(function rootGroupRetrieved(rootConnectionGroup) {
|
.success(function rootGroupRetrieved(rootConnectionGroup) {
|
||||||
|
|
||||||
$scope.rootConnectionGroup = rootConnectionGroup;
|
$scope.rootConnectionGroup = rootConnectionGroup;
|
||||||
|
|
||||||
// Navigate to home page, if not already there
|
|
||||||
var homePage = userPageService.getHomePage(rootConnectionGroup);
|
|
||||||
$location.url(homePage.url);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// Retrieve current permissions
|
|
||||||
permissionService.getPermissions(authenticationService.getCurrentUserID())
|
|
||||||
.success(function permissionsRetrieved(permissions) {
|
|
||||||
$scope.permissions = permissions;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
<!-- The recent connections for this user -->
|
<!-- The recent connections for this user -->
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h2>{{'HOME.SECTION_HEADER_RECENT_CONNECTIONS' | translate}}</h2>
|
<h2>{{'HOME.SECTION_HEADER_RECENT_CONNECTIONS' | translate}}</h2>
|
||||||
<guac-user-menu permissions="permissions" root-group="rootConnectionGroup"></guac-user-menu>
|
<guac-user-menu></guac-user-menu>
|
||||||
</div>
|
</div>
|
||||||
<div class="recent-connections">
|
<div class="recent-connections">
|
||||||
<guac-recent-connections root-group="rootConnectionGroup"></guac-recent-connections>
|
<guac-recent-connections root-group="rootConnectionGroup"></guac-recent-connections>
|
||||||
|
@@ -62,6 +62,57 @@ angular.module('index').config(['$routeProvider', '$locationProvider',
|
|||||||
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirects the user to their home page. This necessarily requires
|
||||||
|
* attempting to re-authenticate with the Guacamole server, as the user's
|
||||||
|
* credentials may have changed, and thus their most-appropriate home page
|
||||||
|
* may have changed as well.
|
||||||
|
*
|
||||||
|
* @param {Service} $injector
|
||||||
|
* The Angular $injector service.
|
||||||
|
*
|
||||||
|
* @returns {Promise}
|
||||||
|
* A promise which resolves successfully only after an attempt to
|
||||||
|
* re-authenticate and determine the user's proper home page has been
|
||||||
|
* made.
|
||||||
|
*/
|
||||||
|
var routeToUserHomePage = ['$injector', function routeToUserHomePage($injector) {
|
||||||
|
|
||||||
|
// Required services
|
||||||
|
var $location = $injector.get('$location');
|
||||||
|
var $q = $injector.get('$q');
|
||||||
|
var userPageService = $injector.get('userPageService');
|
||||||
|
|
||||||
|
// Promise for redirection attempt
|
||||||
|
var redirect = $q.defer();
|
||||||
|
|
||||||
|
// Re-authenticate including any parameters in URL
|
||||||
|
$injector.invoke(updateCurrentToken)
|
||||||
|
.then(function tokenUpdateComplete() {
|
||||||
|
|
||||||
|
// Redirect to home page
|
||||||
|
userPageService.getHomePage()
|
||||||
|
.then(function homePageRetrieved(homePage) {
|
||||||
|
$location.url(homePage.url);
|
||||||
|
})
|
||||||
|
|
||||||
|
// If retrieval of home page fails, assume '/'
|
||||||
|
['catch'](function homePageFailed() {
|
||||||
|
$location.url('/');
|
||||||
|
})
|
||||||
|
|
||||||
|
// Resolve promise in either case
|
||||||
|
['finally'](function retrievalAttemptComplete() {
|
||||||
|
redirect.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Return promise that will resolve regardless of success/failure
|
||||||
|
return redirect.promise;
|
||||||
|
|
||||||
|
}];
|
||||||
|
|
||||||
// Configure each possible route
|
// Configure each possible route
|
||||||
$routeProvider
|
$routeProvider
|
||||||
|
|
||||||
@@ -71,7 +122,7 @@ angular.module('index').config(['$routeProvider', '$locationProvider',
|
|||||||
bodyClassName : 'home',
|
bodyClassName : 'home',
|
||||||
templateUrl : 'app/home/templates/home.html',
|
templateUrl : 'app/home/templates/home.html',
|
||||||
controller : 'homeController',
|
controller : 'homeController',
|
||||||
resolve : { updateCurrentToken: updateCurrentToken }
|
resolve : { routeToUserHomePage: routeToUserHomePage }
|
||||||
})
|
})
|
||||||
|
|
||||||
// Connection management screen
|
// Connection management screen
|
||||||
@@ -147,9 +198,7 @@ angular.module('index').config(['$routeProvider', '$locationProvider',
|
|||||||
|
|
||||||
// Redirect to home screen if page not found
|
// Redirect to home screen if page not found
|
||||||
.otherwise({
|
.otherwise({
|
||||||
redirectTo : '/'
|
resolve : { routeToUserHomePage: routeToUserHomePage }
|
||||||
});
|
});
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|
||||||
|
@@ -29,6 +29,7 @@ angular.module('index', [
|
|||||||
'home',
|
'home',
|
||||||
'login',
|
'login',
|
||||||
'manage',
|
'manage',
|
||||||
|
'navigation',
|
||||||
'ngRoute',
|
'ngRoute',
|
||||||
'ngTouch',
|
'ngTouch',
|
||||||
'notification',
|
'notification',
|
||||||
|
@@ -26,6 +26,7 @@ angular.module('login').controller('loginController', ['$scope', '$injector',
|
|||||||
// Required services
|
// Required services
|
||||||
var $location = $injector.get("$location");
|
var $location = $injector.get("$location");
|
||||||
var authenticationService = $injector.get("authenticationService");
|
var authenticationService = $injector.get("authenticationService");
|
||||||
|
var userPageService = $injector.get('userPageService');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether an error occurred during login.
|
* Whether an error occurred during login.
|
||||||
@@ -52,7 +53,10 @@ angular.module('login').controller('loginController', ['$scope', '$injector',
|
|||||||
|
|
||||||
// Redirect to main view upon success
|
// Redirect to main view upon success
|
||||||
.success(function success(data, status, headers, config) {
|
.success(function success(data, status, headers, config) {
|
||||||
$location.path('/');
|
userPageService.getHomePage()
|
||||||
|
.then(function homePageRetrieved(homePage) {
|
||||||
|
$location.url(homePage.url);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// Reset and focus password upon failure
|
// Reset and focus password upon failure
|
||||||
|
@@ -23,4 +23,4 @@
|
|||||||
/**
|
/**
|
||||||
* The module for the login functionality.
|
* The module for the login functionality.
|
||||||
*/
|
*/
|
||||||
angular.module('login', ['element']);
|
angular.module('login', ['element', 'navigation']);
|
||||||
|
@@ -25,7 +25,7 @@ THE SOFTWARE.
|
|||||||
<!-- Main property editor -->
|
<!-- Main property editor -->
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h2>{{'MANAGE_CONNECTION.SECTION_HEADER_EDIT_CONNECTION' | translate}}</h2>
|
<h2>{{'MANAGE_CONNECTION.SECTION_HEADER_EDIT_CONNECTION' | translate}}</h2>
|
||||||
<guac-user-menu permissions="permissions"></guac-user-menu>
|
<guac-user-menu></guac-user-menu>
|
||||||
</div>
|
</div>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<table class="properties">
|
<table class="properties">
|
||||||
|
@@ -25,7 +25,7 @@ THE SOFTWARE.
|
|||||||
<!-- Main property editor -->
|
<!-- Main property editor -->
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h2>{{'MANAGE_CONNECTION_GROUP.SECTION_HEADER_EDIT_CONNECTION_GROUP' | translate}}</h2>
|
<h2>{{'MANAGE_CONNECTION_GROUP.SECTION_HEADER_EDIT_CONNECTION_GROUP' | translate}}</h2>
|
||||||
<guac-user-menu permissions="permissions"></guac-user-menu>
|
<guac-user-menu></guac-user-menu>
|
||||||
</div>
|
</div>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<table class="properties">
|
<table class="properties">
|
||||||
|
@@ -24,7 +24,7 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h2>{{'MANAGE_CONNECTION.SECTION_HEADER_CONNECTIONS' | translate}}</h2>
|
<h2>{{'MANAGE_CONNECTION.SECTION_HEADER_CONNECTIONS' | translate}}</h2>
|
||||||
<guac-user-menu permissions="permissions"></guac-user-menu>
|
<guac-user-menu></guac-user-menu>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Connection management -->
|
<!-- Connection management -->
|
||||||
|
@@ -24,7 +24,7 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h2>{{'MANAGE_SESSION.SECTION_HEADER_SESSIONS' | translate}}</h2>
|
<h2>{{'MANAGE_SESSION.SECTION_HEADER_SESSIONS' | translate}}</h2>
|
||||||
<guac-user-menu permissions="permissions"></guac-user-menu>
|
<guac-user-menu></guac-user-menu>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- User Session management -->
|
<!-- User Session management -->
|
||||||
|
@@ -25,7 +25,7 @@ THE SOFTWARE.
|
|||||||
<!-- Main property editor -->
|
<!-- Main property editor -->
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h2>{{'MANAGE_USER.SECTION_HEADER_EDIT_USER' | translate}}</h2>
|
<h2>{{'MANAGE_USER.SECTION_HEADER_EDIT_USER' | translate}}</h2>
|
||||||
<guac-user-menu permissions="permissions"></guac-user-menu>
|
<guac-user-menu></guac-user-menu>
|
||||||
</div>
|
</div>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<table class="properties">
|
<table class="properties">
|
||||||
|
@@ -24,7 +24,7 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h2>{{'MANAGE_USER.SECTION_HEADER_USERS' | translate}}</h2>
|
<h2>{{'MANAGE_USER.SECTION_HEADER_USERS' | translate}}</h2>
|
||||||
<guac-user-menu permissions="permissions"></guac-user-menu>
|
<guac-user-menu></guac-user-menu>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- User management -->
|
<!-- User management -->
|
||||||
|
@@ -30,36 +30,20 @@ angular.module('navigation').directive('guacUserMenu', [function guacUserMenu()
|
|||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
replace: true,
|
replace: true,
|
||||||
scope: {
|
scope: {
|
||||||
|
|
||||||
/**
|
|
||||||
* The permissions associated with the user for whom this menu is
|
|
||||||
* being displayed.
|
|
||||||
*
|
|
||||||
* @type PermissionSet
|
|
||||||
*/
|
|
||||||
permissions : '=',
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The root of the connection group tree.
|
|
||||||
*
|
|
||||||
* @type ConnectionGroup
|
|
||||||
*/
|
|
||||||
rootGroup : '='
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
templateUrl: 'app/navigation/templates/guacUserMenu.html',
|
templateUrl: 'app/navigation/templates/guacUserMenu.html',
|
||||||
controller: ['$scope', '$injector', '$element', function guacUserMenuController($scope, $injector, $element) {
|
controller: ['$scope', '$injector', '$element', function guacUserMenuController($scope, $injector, $element) {
|
||||||
|
|
||||||
// Get required types
|
// Get required types
|
||||||
var ConnectionGroup = $injector.get('ConnectionGroup');
|
var PermissionSet = $injector.get('PermissionSet');
|
||||||
var PermissionSet = $injector.get('PermissionSet');
|
|
||||||
|
|
||||||
// Get required services
|
// Get required services
|
||||||
var $document = $injector.get('$document');
|
var $document = $injector.get('$document');
|
||||||
var $location = $injector.get('$location');
|
var $location = $injector.get('$location');
|
||||||
var authenticationService = $injector.get('authenticationService');
|
var authenticationService = $injector.get('authenticationService');
|
||||||
var guacNotification = $injector.get('guacNotification');
|
var guacNotification = $injector.get('guacNotification');
|
||||||
|
var permissionService = $injector.get("permissionService");
|
||||||
var userService = $injector.get('userService');
|
var userService = $injector.get('userService');
|
||||||
var userPageService = $injector.get('userPageService');
|
var userPageService = $injector.get('userPageService');
|
||||||
|
|
||||||
@@ -141,39 +125,22 @@ angular.module('navigation').directive('guacUserMenu', [function guacUserMenu()
|
|||||||
*/
|
*/
|
||||||
$scope.pages = null;
|
$scope.pages = null;
|
||||||
|
|
||||||
/**
|
// Retrieve current permissions
|
||||||
* Updates the visible menu items based on the permissions and root
|
permissionService.getPermissions(authenticationService.getCurrentUserID())
|
||||||
* group on the scope, if available. If either the permissions or
|
.success(function permissionsRetrieved(permissions) {
|
||||||
* the root group are not yet available, this function has no
|
|
||||||
* effect.
|
|
||||||
*/
|
|
||||||
var updateMenuItems = function updateMenuItems() {
|
|
||||||
|
|
||||||
// Menu items are unknown until permissions and rootGroup are both available
|
|
||||||
if (!$scope.permissions || !$scope.rootGroup) {
|
|
||||||
$scope.canChangePassword = null;
|
|
||||||
$scope.pages = [];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve the main pages from the user page service
|
|
||||||
$scope.pages = userPageService.getMainPages($scope.rootGroup, $scope.permissions);
|
|
||||||
|
|
||||||
// Check whether the current user can change their own password
|
// Check whether the current user can change their own password
|
||||||
$scope.canChangePassword = PermissionSet.hasUserPermission(
|
$scope.canChangePassword = PermissionSet.hasUserPermission(
|
||||||
$scope.permissions, PermissionSet.ObjectPermissionType.UPDATE,
|
permissions, PermissionSet.ObjectPermissionType.UPDATE,
|
||||||
authenticationService.getCurrentUserID()
|
authenticationService.getCurrentUserID()
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
// Update available menu options when permissions are changed
|
|
||||||
$scope.$watch('permissions', function permissionsChanged() {
|
|
||||||
updateMenuItems();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update available menu options when root group is changed
|
// Retrieve the main pages from the user page service
|
||||||
$scope.$watch('rootGroup', function rootGroupChanged() {
|
userPageService.getMainPages()
|
||||||
updateMenuItems();
|
.then(function retrievedMainPages(pages) {
|
||||||
|
$scope.pages = pages;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -23,4 +23,4 @@
|
|||||||
/**
|
/**
|
||||||
* Module for generating and implementing user navigation options.
|
* Module for generating and implementing user navigation options.
|
||||||
*/
|
*/
|
||||||
angular.module('navigation', ['notification']);
|
angular.module('navigation', ['notification', 'rest']);
|
||||||
|
@@ -31,7 +31,10 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
var PermissionSet = $injector.get('PermissionSet');
|
var PermissionSet = $injector.get('PermissionSet');
|
||||||
|
|
||||||
// Get required services
|
// Get required services
|
||||||
var authenticationService = $injector.get('authenticationService');
|
var $q = $injector.get('$q');
|
||||||
|
var authenticationService = $injector.get('authenticationService');
|
||||||
|
var connectionGroupService = $injector.get("connectionGroupService");
|
||||||
|
var permissionService = $injector.get("permissionService");
|
||||||
|
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
@@ -62,7 +65,7 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
* @returns {Page}
|
* @returns {Page}
|
||||||
* The user's home page.
|
* The user's home page.
|
||||||
*/
|
*/
|
||||||
service.getHomePage = function getHomePage(rootGroup) {
|
var generateHomePage = function generateHomePage(rootGroup) {
|
||||||
|
|
||||||
// Get children
|
// Get children
|
||||||
var connections = rootGroup.childConnections || [];
|
var connections = rootGroup.childConnections || [];
|
||||||
@@ -96,7 +99,7 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default home page
|
// Resolve promise with default home page
|
||||||
return new Page(
|
return new Page(
|
||||||
'USER_MENU.ACTION_NAVIGATE_HOME',
|
'USER_MENU.ACTION_NAVIGATE_HOME',
|
||||||
'/'
|
'/'
|
||||||
@@ -104,6 +107,27 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a promise which resolves with an appropriate home page for the
|
||||||
|
* current user.
|
||||||
|
*
|
||||||
|
* @returns {Promise.<Page>}
|
||||||
|
* A promise which resolves with the user's default home page.
|
||||||
|
*/
|
||||||
|
service.getHomePage = function getHomePage() {
|
||||||
|
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
// Resolve promise using home page derived from root connection group
|
||||||
|
connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER)
|
||||||
|
.success(function rootConnectionGroupRetrieved(rootGroup) {
|
||||||
|
deferred.resolve(generateHomePage(rootGroup));
|
||||||
|
});
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all the main pages that the current user can visit. This can
|
* Returns all the main pages that the current user can visit. This can
|
||||||
* include the home page, manage pages, etc. In the case that there are no
|
* include the home page, manage pages, etc. In the case that there are no
|
||||||
@@ -115,10 +139,10 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
* @param {PermissionSet} permissions
|
* @param {PermissionSet} permissions
|
||||||
* The permissions for the current user.
|
* The permissions for the current user.
|
||||||
*
|
*
|
||||||
* @returns {Array}
|
* @returns {Page[]}
|
||||||
* An array of objects like this
|
* An array of all main pages that the current user can visit.
|
||||||
*/
|
*/
|
||||||
service.getMainPages = function getMainPages(rootGroup, permissions) {
|
var generateMainPages = function generateMainPages(rootGroup, permissions) {
|
||||||
|
|
||||||
var pages = [];
|
var pages = [];
|
||||||
|
|
||||||
@@ -172,7 +196,7 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
PermissionSet.hasSystemPermission(permissions, PermissionSet.SystemPermissionType.ADMINISTER);
|
PermissionSet.hasSystemPermission(permissions, PermissionSet.SystemPermissionType.ADMINISTER);
|
||||||
|
|
||||||
// Add home page
|
// Add home page
|
||||||
pages.push(service.getHomePage(rootGroup));
|
pages.push(generateHomePage(rootGroup));
|
||||||
|
|
||||||
// If user can manage users, add link to user management page
|
// If user can manage users, add link to user management page
|
||||||
if (canManageUsers) {
|
if (canManageUsers) {
|
||||||
@@ -201,6 +225,50 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
return pages;
|
return pages;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a promise which resolves to an array of all main pages that the
|
||||||
|
* current user can visit. This can include the home page, manage pages,
|
||||||
|
* etc. In the case that there are no applicable pages of this sort, it may
|
||||||
|
* return a client page.
|
||||||
|
*
|
||||||
|
* @returns {Promise.<Page[]>}
|
||||||
|
* A promise which resolves to an array of all main pages that the
|
||||||
|
* current user can visit.
|
||||||
|
*/
|
||||||
|
service.getMainPages = function getMainPages() {
|
||||||
|
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
var rootGroup = null;
|
||||||
|
var permissions = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the main pages retrieval promise, if possible. If
|
||||||
|
* insufficient data is available, this function does nothing.
|
||||||
|
*/
|
||||||
|
var resolveMainPages = function resolveMainPages() {
|
||||||
|
if (rootGroup && permissions)
|
||||||
|
deferred.resolve(generateMainPages(rootGroup, permissions));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Retrieve root group, resolving main pages if possible
|
||||||
|
connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER)
|
||||||
|
.success(function rootConnectionGroupRetrieved(retrievedRootGroup) {
|
||||||
|
rootGroup = retrievedRootGroup;
|
||||||
|
resolveMainPages();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Retrieve current permissions, resolving main pages if possible
|
||||||
|
permissionService.getPermissions(authenticationService.getCurrentUserID())
|
||||||
|
.success(function permissionsRetrieved(retrievedPermissions) {
|
||||||
|
permissions = retrievedPermissions;
|
||||||
|
resolveMainPages();
|
||||||
|
});
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
|
||||||
}]);
|
}]);
|
Reference in New Issue
Block a user