mirror of https://github.com/portainer/portainer
74 lines
2.5 KiB
JavaScript
74 lines
2.5 KiB
JavaScript
angular.module('sidebar', [])
|
|
.controller('SidebarController', ['$q', '$scope', '$state', 'Settings', 'Config', 'EndpointService', 'StateManager', 'EndpointProvider', 'Notifications', 'Authentication', 'UserService',
|
|
function ($q, $scope, $state, Settings, Config, EndpointService, StateManager, EndpointProvider, Notifications, Authentication, UserService) {
|
|
|
|
Config.$promise.then(function (c) {
|
|
$scope.logo = c.logo;
|
|
});
|
|
|
|
$scope.uiVersion = Settings.uiVersion;
|
|
$scope.endpoints = [];
|
|
|
|
$scope.switchEndpoint = function(endpoint) {
|
|
var activeEndpointID = EndpointProvider.endpointID();
|
|
var activeEndpointPublicURL = EndpointProvider.endpointPublicURL();
|
|
EndpointProvider.setEndpointID(endpoint.Id);
|
|
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
|
|
StateManager.updateEndpointState(true)
|
|
.then(function success() {
|
|
$state.go('dashboard');
|
|
})
|
|
.catch(function error(err) {
|
|
Notifications.error('Failure', err, 'Unable to connect to the Docker endpoint');
|
|
EndpointProvider.setEndpointID(activeEndpointID);
|
|
EndpointProvider.setEndpointPublicURL(activeEndpointPublicURL);
|
|
StateManager.updateEndpointState(true)
|
|
.then(function success() {});
|
|
});
|
|
};
|
|
|
|
function setActiveEndpoint(endpoints) {
|
|
var activeEndpointID = EndpointProvider.endpointID();
|
|
angular.forEach(endpoints, function (endpoint) {
|
|
if (endpoint.Id === activeEndpointID) {
|
|
$scope.activeEndpoint = endpoint;
|
|
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
|
|
}
|
|
});
|
|
}
|
|
|
|
function checkPermissions(memberships) {
|
|
var isLeader = false;
|
|
angular.forEach(memberships, function(membership) {
|
|
if (membership.Role === 1) {
|
|
isLeader = true;
|
|
}
|
|
});
|
|
$scope.isTeamLeader = isLeader;
|
|
}
|
|
|
|
function initView() {
|
|
EndpointService.endpoints()
|
|
.then(function success(data) {
|
|
var endpoints = data;
|
|
$scope.endpoints = endpoints;
|
|
setActiveEndpoint(endpoints);
|
|
|
|
if (StateManager.getState().application.authentication) {
|
|
var userDetails = Authentication.getUserDetails();
|
|
var isAdmin = userDetails.role === 1 ? true: false;
|
|
$scope.isAdmin = isAdmin;
|
|
return $q.when(!isAdmin ? UserService.userMemberships(userDetails.ID) : []);
|
|
}
|
|
})
|
|
.then(function success(data) {
|
|
checkPermissions(data);
|
|
})
|
|
.catch(function error(err) {
|
|
Notifications.error('Failure', err, 'Unable to retrieve endpoints');
|
|
});
|
|
}
|
|
|
|
initView();
|
|
}]);
|