2016-12-25 20:34:02 +00:00
|
|
|
angular.module('endpoint', [])
|
2017-04-12 19:47:22 +00:00
|
|
|
.controller('EndpointController', ['$scope', '$state', '$stateParams', '$filter', 'EndpointService', 'Notifications',
|
|
|
|
function ($scope, $state, $stateParams, $filter, EndpointService, Notifications) {
|
2017-02-06 05:29:34 +00:00
|
|
|
|
|
|
|
if (!$scope.applicationState.application.endpointManagement) {
|
|
|
|
$state.go('endpoints');
|
|
|
|
}
|
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.state = {
|
|
|
|
error: '',
|
|
|
|
uploadInProgress: false
|
|
|
|
};
|
2017-04-09 18:38:41 +00:00
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.formValues = {
|
|
|
|
TLSCACert: null,
|
|
|
|
TLSCert: null,
|
|
|
|
TLSKey: null
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.updateEndpoint = function() {
|
|
|
|
var ID = $scope.endpoint.Id;
|
2017-03-12 16:24:15 +00:00
|
|
|
var endpointParams = {
|
|
|
|
name: $scope.endpoint.Name,
|
|
|
|
URL: $scope.endpoint.URL,
|
2017-05-01 10:19:43 +00:00
|
|
|
PublicURL: $scope.endpoint.PublicURL,
|
2017-03-12 16:24:15 +00:00
|
|
|
TLS: $scope.endpoint.TLS,
|
|
|
|
TLSCACert: $scope.formValues.TLSCACert !== $scope.endpoint.TLSCACert ? $scope.formValues.TLSCACert : null,
|
|
|
|
TLSCert: $scope.formValues.TLSCert !== $scope.endpoint.TLSCert ? $scope.formValues.TLSCert : null,
|
|
|
|
TLSKey: $scope.formValues.TLSKey !== $scope.endpoint.TLSKey ? $scope.formValues.TLSKey : null,
|
|
|
|
type: $scope.endpointType
|
|
|
|
};
|
|
|
|
|
|
|
|
EndpointService.updateEndpoint(ID, endpointParams)
|
|
|
|
.then(function success(data) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Endpoint updated', $scope.endpoint.Name);
|
2016-12-25 20:34:02 +00:00
|
|
|
$state.go('endpoints');
|
|
|
|
}, function error(err) {
|
|
|
|
$scope.state.error = err.msg;
|
|
|
|
}, function update(evt) {
|
|
|
|
if (evt.upload) {
|
|
|
|
$scope.state.uploadInProgress = evt.upload;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function getEndpoint(endpointID) {
|
|
|
|
$('#loadingViewSpinner').show();
|
|
|
|
EndpointService.endpoint($stateParams.id).then(function success(data) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
$scope.endpoint = data;
|
2017-05-23 18:56:10 +00:00
|
|
|
if (data.URL.indexOf('unix://') === 0) {
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.endpointType = 'local';
|
|
|
|
} else {
|
|
|
|
$scope.endpointType = 'remote';
|
|
|
|
}
|
|
|
|
$scope.endpoint.URL = $filter('stripprotocol')(data.URL);
|
|
|
|
$scope.formValues.TLSCACert = data.TLSCACert;
|
|
|
|
$scope.formValues.TLSCert = data.TLSCert;
|
|
|
|
$scope.formValues.TLSKey = data.TLSKey;
|
|
|
|
}, function error(err) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve endpoint details');
|
2016-12-25 20:34:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getEndpoint($stateParams.id);
|
|
|
|
}]);
|