2016-12-25 20:34:02 +00:00
|
|
|
angular.module('endpoints', [])
|
2017-04-12 19:47:22 +00:00
|
|
|
.controller('EndpointsController', ['$scope', '$state', 'EndpointService', 'EndpointProvider', 'Notifications', 'Pagination',
|
|
|
|
function ($scope, $state, EndpointService, EndpointProvider, Notifications, Pagination) {
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.state = {
|
|
|
|
uploadInProgress: false,
|
2017-01-24 01:28:40 +00:00
|
|
|
selectedItemCount: 0,
|
|
|
|
pagination_count: Pagination.getPaginationCount('endpoints')
|
2016-12-25 20:34:02 +00:00
|
|
|
};
|
|
|
|
$scope.sortType = 'Name';
|
|
|
|
$scope.sortReverse = true;
|
|
|
|
|
|
|
|
$scope.formValues = {
|
|
|
|
Name: '',
|
|
|
|
URL: '',
|
2017-05-01 10:19:43 +00:00
|
|
|
PublicURL: '',
|
2017-09-14 06:08:37 +00:00
|
|
|
SecurityFormData: new EndpointSecurityFormData()
|
2016-12-25 20:34:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.order = function(sortType) {
|
|
|
|
$scope.sortReverse = ($scope.sortType === sortType) ? !$scope.sortReverse : false;
|
|
|
|
$scope.sortType = sortType;
|
|
|
|
};
|
|
|
|
|
2017-01-24 01:28:40 +00:00
|
|
|
$scope.changePaginationCount = function() {
|
|
|
|
Pagination.setPaginationCount('endpoints', $scope.state.pagination_count);
|
|
|
|
};
|
|
|
|
|
2017-03-12 16:39:27 +00:00
|
|
|
$scope.selectItems = function (allSelected) {
|
|
|
|
angular.forEach($scope.state.filteredEndpoints, function (endpoint) {
|
|
|
|
if (endpoint.Checked !== allSelected) {
|
|
|
|
endpoint.Checked = allSelected;
|
|
|
|
$scope.selectItem(endpoint);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.selectItem = function (item) {
|
|
|
|
if (item.Checked) {
|
|
|
|
$scope.state.selectedItemCount++;
|
|
|
|
} else {
|
|
|
|
$scope.state.selectedItemCount--;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.addEndpoint = function() {
|
|
|
|
var name = $scope.formValues.Name;
|
|
|
|
var URL = $scope.formValues.URL;
|
2017-05-01 10:19:43 +00:00
|
|
|
var PublicURL = $scope.formValues.PublicURL;
|
|
|
|
if (PublicURL === '') {
|
|
|
|
PublicURL = URL.split(':')[0];
|
|
|
|
}
|
2017-09-14 06:08:37 +00:00
|
|
|
|
|
|
|
var securityData = $scope.formValues.SecurityFormData;
|
|
|
|
var TLS = securityData.TLS;
|
|
|
|
var TLSMode = securityData.TLSMode;
|
|
|
|
var TLSSkipVerify = TLS && (TLSMode === 'tls_client_noca' || TLSMode === 'tls_only');
|
|
|
|
var TLSSkipClientVerify = TLS && (TLSMode === 'tls_ca' || TLSMode === 'tls_only');
|
|
|
|
var TLSCAFile = TLSSkipVerify ? null : securityData.TLSCACert;
|
|
|
|
var TLSCertFile = TLSSkipClientVerify ? null : securityData.TLSCert;
|
|
|
|
var TLSKeyFile = TLSSkipClientVerify ? null : securityData.TLSKey;
|
|
|
|
|
|
|
|
EndpointService.createRemoteEndpoint(name, URL, PublicURL, TLS, TLSSkipVerify, TLSSkipClientVerify, TLSCAFile, TLSCertFile, TLSKeyFile).then(function success(data) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Endpoint created', name);
|
2016-12-25 20:34:02 +00:00
|
|
|
$state.reload();
|
|
|
|
}, function error(err) {
|
|
|
|
$scope.state.uploadInProgress = false;
|
2017-09-14 06:08:37 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to create endpoint');
|
2016-12-25 20:34:02 +00:00
|
|
|
}, function update(evt) {
|
|
|
|
if (evt.upload) {
|
|
|
|
$scope.state.uploadInProgress = evt.upload;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeAction = function () {
|
|
|
|
$('#loadEndpointsSpinner').show();
|
|
|
|
var counter = 0;
|
|
|
|
var complete = function () {
|
|
|
|
counter = counter - 1;
|
|
|
|
if (counter === 0) {
|
|
|
|
$('#loadEndpointsSpinner').hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
angular.forEach($scope.endpoints, function (endpoint) {
|
|
|
|
if (endpoint.Checked) {
|
|
|
|
counter = counter + 1;
|
|
|
|
EndpointService.deleteEndpoint(endpoint.Id).then(function success(data) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Endpoint deleted', endpoint.Name);
|
2016-12-25 20:34:02 +00:00
|
|
|
var index = $scope.endpoints.indexOf(endpoint);
|
|
|
|
$scope.endpoints.splice(index, 1);
|
|
|
|
complete();
|
|
|
|
}, function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to remove endpoint');
|
2016-12-25 20:34:02 +00:00
|
|
|
complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function fetchEndpoints() {
|
|
|
|
$('#loadEndpointsSpinner').show();
|
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
|
|
|
})
|
|
|
|
.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
|
|
|
$scope.endpoints = [];
|
2017-03-12 16:24:15 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#loadEndpointsSpinner').hide();
|
2016-12-25 20:34:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchEndpoints();
|
|
|
|
}]);
|