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 = {
|
|
|
|
error: '',
|
|
|
|
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: '',
|
2016-12-25 20:34:02 +00:00
|
|
|
TLS: false,
|
|
|
|
TLSCACert: null,
|
|
|
|
TLSCert: null,
|
|
|
|
TLSKey: null
|
|
|
|
};
|
|
|
|
|
|
|
|
$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() {
|
|
|
|
$scope.state.error = '';
|
|
|
|
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];
|
|
|
|
}
|
2016-12-25 20:34:02 +00:00
|
|
|
var TLS = $scope.formValues.TLS;
|
|
|
|
var TLSCAFile = $scope.formValues.TLSCACert;
|
|
|
|
var TLSCertFile = $scope.formValues.TLSCert;
|
|
|
|
var TLSKeyFile = $scope.formValues.TLSKey;
|
2017-05-01 10:19:43 +00:00
|
|
|
EndpointService.createRemoteEndpoint(name, URL, PublicURL, TLS, TLSCAFile, TLSCertFile, TLSKeyFile, false).then(function success(data) {
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success("Endpoint created", name);
|
2016-12-25 20:34:02 +00:00
|
|
|
$state.reload();
|
|
|
|
}, function error(err) {
|
|
|
|
$scope.state.uploadInProgress = false;
|
|
|
|
$scope.state.error = err.msg;
|
|
|
|
}, 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-04-12 19:47:22 +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-04-12 19:47:22 +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
|
|
|
$scope.activeEndpointID = EndpointProvider.endpointID();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-04-12 19:47:22 +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();
|
|
|
|
}]);
|