2016-06-14 02:13:52 +00:00
|
|
|
angular.module('network', [])
|
2016-12-25 20:28:54 +00:00
|
|
|
.controller('NetworkController', ['$scope', '$state', '$stateParams', 'Network', 'Container', 'ContainerHelper', 'Messages',
|
|
|
|
function ($scope, $state, $stateParams, Network, Container, ContainerHelper, Messages) {
|
2016-06-02 05:34:03 +00:00
|
|
|
|
2016-09-14 05:48:20 +00:00
|
|
|
$scope.removeNetwork = function removeNetwork(networkId) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Network.remove({id: $stateParams.id}, function (d) {
|
2016-09-01 00:20:19 +00:00
|
|
|
if (d.message) {
|
2016-08-31 23:31:25 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
2016-09-02 05:59:32 +00:00
|
|
|
Messages.send("Error", {}, d.message);
|
2016-08-31 23:31:25 +00:00
|
|
|
} else {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2016-09-01 00:20:19 +00:00
|
|
|
Messages.send("Network removed", $stateParams.id);
|
2016-08-31 23:31:25 +00:00
|
|
|
$state.go('networks', {});
|
|
|
|
}
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
2016-09-02 05:59:32 +00:00
|
|
|
Messages.error("Failure", e, "Unable to remove network");
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
2015-12-21 01:13:53 +00:00
|
|
|
|
2016-12-25 20:28:54 +00:00
|
|
|
$scope.containerLeaveNetwork = function containerLeaveNetwork(network, containerId) {
|
|
|
|
$('#loadingViewSpinner').show();
|
|
|
|
Network.disconnect({id: $stateParams.id}, { Container: containerId, Force: false }, function (d) {
|
|
|
|
if (d.message) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
Messages.send("Error", {}, d.message);
|
|
|
|
} else {
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
Messages.send("Container left network", $stateParams.id);
|
|
|
|
$state.go('network', {id: network.Id}, {reload: true});
|
|
|
|
}
|
|
|
|
}, function (e) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
Messages.error("Failure", e, "Unable to disconnect container from network");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function getNetwork() {
|
|
|
|
$('#loadingViewSpinner').show();
|
|
|
|
Network.get({id: $stateParams.id}, function (d) {
|
|
|
|
$scope.network = d;
|
|
|
|
getContainersInNetwork(d);
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
}, function (e) {
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
Messages.error("Failure", e, "Unable to retrieve network info");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getContainersInNetwork(network) {
|
|
|
|
if (network.Containers) {
|
|
|
|
Container.query({
|
|
|
|
filters: {network: [$stateParams.id]}
|
|
|
|
}, function (containersInNetworkResult) {
|
|
|
|
if ($scope.containersToHideLabels) {
|
|
|
|
containersInNetworkResult = ContainerHelper.hideContainers(containersInNetworkResult, $scope.containersToHideLabels);
|
|
|
|
}
|
|
|
|
var containersInNetwork = [];
|
|
|
|
containersInNetworkResult.forEach(function(container) {
|
|
|
|
var containerInNetwork = network.Containers[container.Id];
|
|
|
|
containerInNetwork.Id = container.Id;
|
|
|
|
containersInNetwork.push(containerInNetwork);
|
|
|
|
});
|
|
|
|
$scope.containersInNetwork = containersInNetwork;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getNetwork();
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|