2016-12-25 20:34:02 +00:00
|
|
|
angular.module('endpointInit', [])
|
2017-03-12 16:24:15 +00:00
|
|
|
.controller('EndpointInitController', ['$scope', '$state', 'EndpointService', 'StateManager', 'EndpointProvider', 'Messages',
|
|
|
|
function ($scope, $state, EndpointService, StateManager, EndpointProvider, Messages) {
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.state = {
|
|
|
|
error: '',
|
|
|
|
uploadInProgress: false
|
|
|
|
};
|
|
|
|
$scope.formValues = {
|
|
|
|
endpointType: "remote",
|
|
|
|
Name: '',
|
|
|
|
URL: '',
|
|
|
|
TLS: false,
|
|
|
|
TLSCACert: null,
|
|
|
|
TLSCert: null,
|
|
|
|
TLSKey: null
|
|
|
|
};
|
|
|
|
|
2017-01-22 23:14:34 +00:00
|
|
|
if (!_.isEmpty($scope.applicationState.endpoint)) {
|
2016-12-25 20:34:02 +00:00
|
|
|
$state.go('dashboard');
|
2017-01-22 23:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.cleanError = function() {
|
|
|
|
$scope.state.error = '';
|
|
|
|
};
|
2016-12-25 20:34:02 +00:00
|
|
|
|
|
|
|
$scope.createLocalEndpoint = function() {
|
2017-01-22 23:14:34 +00:00
|
|
|
$('#initEndpointSpinner').show();
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.state.error = '';
|
|
|
|
var name = "local";
|
|
|
|
var URL = "unix:///var/run/docker.sock";
|
|
|
|
var TLS = false;
|
2017-03-12 16:24:15 +00:00
|
|
|
|
|
|
|
EndpointService.createLocalEndpoint(name, URL, TLS, true)
|
|
|
|
.then(
|
|
|
|
function success(data) {
|
|
|
|
var endpointID = data.Id;
|
|
|
|
EndpointProvider.setEndpointID(endpointID);
|
|
|
|
StateManager.updateEndpointState(false).then(
|
|
|
|
function success() {
|
2017-01-22 23:14:34 +00:00
|
|
|
$state.go('dashboard');
|
2017-03-12 16:24:15 +00:00
|
|
|
},
|
|
|
|
function error(err) {
|
|
|
|
EndpointService.deleteEndpoint(endpointID)
|
2017-01-22 23:14:34 +00:00
|
|
|
.then(function success() {
|
|
|
|
$scope.state.error = 'Unable to connect to the Docker endpoint';
|
|
|
|
});
|
|
|
|
});
|
2017-03-12 16:24:15 +00:00
|
|
|
},
|
|
|
|
function error() {
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.state.error = 'Unable to create endpoint';
|
2017-03-12 16:24:15 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#initEndpointSpinner').hide();
|
2016-12-25 20:34:02 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.createRemoteEndpoint = function() {
|
2017-01-22 23:14:34 +00:00
|
|
|
$('#initEndpointSpinner').show();
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.state.error = '';
|
|
|
|
var name = $scope.formValues.Name;
|
|
|
|
var URL = $scope.formValues.URL;
|
|
|
|
var TLS = $scope.formValues.TLS;
|
|
|
|
var TLSCAFile = $scope.formValues.TLSCACert;
|
|
|
|
var TLSCertFile = $scope.formValues.TLSCert;
|
|
|
|
var TLSKeyFile = $scope.formValues.TLSKey;
|
2017-01-22 23:14:34 +00:00
|
|
|
EndpointService.createRemoteEndpoint(name, URL, TLS, TLSCAFile, TLSCertFile, TLSKeyFile, TLS ? false : true)
|
|
|
|
.then(function success(data) {
|
2017-03-12 16:24:15 +00:00
|
|
|
var endpointID = data.Id;
|
|
|
|
EndpointProvider.setEndpointID(endpointID);
|
2017-01-22 23:14:34 +00:00
|
|
|
StateManager.updateEndpointState(false)
|
|
|
|
.then(function success() {
|
|
|
|
$state.go('dashboard');
|
|
|
|
}, function error(err) {
|
2017-03-12 16:24:15 +00:00
|
|
|
EndpointService.deleteEndpoint(endpointID)
|
2017-01-22 23:14:34 +00:00
|
|
|
.then(function success() {
|
|
|
|
$('#initEndpointSpinner').hide();
|
|
|
|
$scope.state.error = 'Unable to connect to the Docker endpoint';
|
|
|
|
});
|
|
|
|
});
|
2016-12-25 20:34:02 +00:00
|
|
|
}, function error(err) {
|
2017-01-22 23:14:34 +00:00
|
|
|
$('#initEndpointSpinner').hide();
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.state.uploadInProgress = false;
|
|
|
|
$scope.state.error = err.msg;
|
|
|
|
}, function update(evt) {
|
|
|
|
if (evt.upload) {
|
|
|
|
$scope.state.uploadInProgress = evt.upload;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}]);
|