2016-12-15 03:33:47 +00:00
|
|
|
angular.module('sidebar', [])
|
2017-04-12 19:47:22 +00:00
|
|
|
.controller('SidebarController', ['$scope', '$state', 'Settings', 'Config', 'EndpointService', 'StateManager', 'EndpointProvider', 'Notifications', 'Authentication',
|
|
|
|
function ($scope, $state, Settings, Config, EndpointService, StateManager, EndpointProvider, Notifications, Authentication) {
|
2016-12-15 03:33:47 +00:00
|
|
|
|
|
|
|
Config.$promise.then(function (c) {
|
|
|
|
$scope.logo = c.logo;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.uiVersion = Settings.uiVersion;
|
2017-03-12 16:24:15 +00:00
|
|
|
$scope.userRole = Authentication.getUserDetails().role;
|
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
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function fetchEndpoints() {
|
2017-03-12 16:24:15 +00:00
|
|
|
EndpointService.endpoints()
|
|
|
|
.then(function success(data) {
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.endpoints = data;
|
2017-03-12 16:24:15 +00:00
|
|
|
var activeEndpointID = EndpointProvider.endpointID();
|
|
|
|
angular.forEach($scope.endpoints, function (endpoint) {
|
|
|
|
if (endpoint.Id === activeEndpointID) {
|
|
|
|
$scope.activeEndpoint = endpoint;
|
2017-05-01 10:19:43 +00:00
|
|
|
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
|
2017-03-12 16:24:15 +00:00
|
|
|
}
|
2016-12-25 20:34:02 +00:00
|
|
|
});
|
2017-03-12 16:24:15 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.endpoints = [];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchEndpoints();
|
2016-12-15 03:33:47 +00:00
|
|
|
}]);
|