2016-12-15 03:33:47 +00:00
|
|
|
angular.module('sidebar', [])
|
2017-06-01 08:14:55 +00:00
|
|
|
.controller('SidebarController', ['$q', '$scope', '$state', 'Settings', 'EndpointService', 'StateManager', 'EndpointProvider', 'Notifications', 'Authentication', 'UserService',
|
|
|
|
function ($q, $scope, $state, Settings, EndpointService, StateManager, EndpointProvider, Notifications, Authentication, UserService) {
|
2016-12-15 03:33:47 +00:00
|
|
|
|
2017-06-01 08:14:55 +00:00
|
|
|
$scope.uiVersion = StateManager.getState().application.version;
|
|
|
|
$scope.displayExternalContributors = StateManager.getState().application.displayExternalContributors;
|
|
|
|
$scope.logo = StateManager.getState().application.logo;
|
2017-05-23 18:56:10 +00:00
|
|
|
$scope.endpoints = [];
|
2016-12-25 20:34:02 +00:00
|
|
|
|
|
|
|
$scope.switchEndpoint = function(endpoint) {
|
2017-03-12 16:24:15 +00:00
|
|
|
var activeEndpointID = EndpointProvider.endpointID();
|
2017-05-01 10:19:43 +00:00
|
|
|
var activeEndpointPublicURL = EndpointProvider.endpointPublicURL();
|
2017-03-12 16:24:15 +00:00
|
|
|
EndpointProvider.setEndpointID(endpoint.Id);
|
2017-05-01 10:19:43 +00:00
|
|
|
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
|
2017-03-12 16:24:15 +00:00
|
|
|
StateManager.updateEndpointState(true)
|
|
|
|
.then(function success() {
|
|
|
|
$state.go('dashboard');
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-18 21:00:08 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to connect to the Docker endpoint');
|
2017-03-12 16:24:15 +00:00
|
|
|
EndpointProvider.setEndpointID(activeEndpointID);
|
2017-05-01 10:19:43 +00:00
|
|
|
EndpointProvider.setEndpointPublicURL(activeEndpointPublicURL);
|
2017-01-22 23:14:34 +00:00
|
|
|
StateManager.updateEndpointState(true)
|
2017-03-12 16:24:15 +00:00
|
|
|
.then(function success() {});
|
2016-12-25 20:34:02 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
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() {
|
2017-03-12 16:24:15 +00:00
|
|
|
EndpointService.endpoints()
|
|
|
|
.then(function success(data) {
|
2017-05-23 18:56:10 +00:00
|
|
|
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);
|
2017-03-12 16:24:15 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve endpoints');
|
2016-12-25 20:34:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
initView();
|
2016-12-15 03:33:47 +00:00
|
|
|
}]);
|