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
|
|
|
|
};
|
2017-04-08 18:38:19 +00:00
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
2017-04-08 18:38:19 +00:00
|
|
|
$scope.resetErrorMessage = function() {
|
2017-01-22 23:14:34 +00:00
|
|
|
$scope.state.error = '';
|
|
|
|
};
|
2016-12-25 20:34:02 +00:00
|
|
|
|
2017-04-08 18:38:19 +00:00
|
|
|
function showErrorMessage(message) {
|
|
|
|
$scope.state.uploadInProgress = false;
|
|
|
|
$scope.state.error = message;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateEndpointState(endpointID) {
|
|
|
|
EndpointProvider.setEndpointID(endpointID);
|
|
|
|
StateManager.updateEndpointState(false)
|
|
|
|
.then(function success(data) {
|
|
|
|
$state.go('dashboard');
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
EndpointService.deleteEndpoint(endpointID)
|
|
|
|
.then(function success() {
|
|
|
|
showErrorMessage('Unable to connect to the Docker endpoint');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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)
|
2017-04-08 18:38:19 +00:00
|
|
|
.then(function success(data) {
|
2017-03-12 16:24:15 +00:00
|
|
|
var endpointID = data.Id;
|
2017-04-08 18:38:19 +00:00
|
|
|
updateEndpointState(data.Id);
|
|
|
|
}, 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-04-08 18:38:19 +00:00
|
|
|
|
|
|
|
EndpointService.createRemoteEndpoint(name, URL, TLS, TLSCAFile, TLSCertFile, TLSKeyFile)
|
2017-01-22 23:14:34 +00:00
|
|
|
.then(function success(data) {
|
2017-03-12 16:24:15 +00:00
|
|
|
var endpointID = data.Id;
|
2017-04-08 18:38:19 +00:00
|
|
|
updateEndpointState(endpointID);
|
2016-12-25 20:34:02 +00:00
|
|
|
}, function error(err) {
|
2017-04-08 18:38:19 +00:00
|
|
|
showErrorMessage(err.msg);
|
2016-12-25 20:34:02 +00:00
|
|
|
}, function update(evt) {
|
|
|
|
if (evt.upload) {
|
|
|
|
$scope.state.uploadInProgress = evt.upload;
|
|
|
|
}
|
2017-04-08 18:38:19 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#initEndpointSpinner').hide();
|
2016-12-25 20:34:02 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}]);
|