2016-06-02 05:34:03 +00:00
|
|
|
angular.module('networks', [])
|
2016-11-17 12:50:46 +00:00
|
|
|
.controller('NetworksController', ['$scope', '$state', 'Network', 'Config', 'Messages', 'Settings',
|
|
|
|
function ($scope, $state, Network, Config, Messages, Settings) {
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.state = {};
|
|
|
|
$scope.state.selectedItemCount = 0;
|
2016-07-08 05:26:18 +00:00
|
|
|
$scope.state.advancedSettings = false;
|
2016-08-17 05:25:42 +00:00
|
|
|
$scope.sortType = 'Name';
|
2016-07-06 07:04:45 +00:00
|
|
|
$scope.sortReverse = false;
|
2016-11-17 12:50:46 +00:00
|
|
|
$scope.pagination_count = Settings.pagination_count;
|
2016-07-06 07:04:45 +00:00
|
|
|
$scope.config = {
|
2016-09-14 05:50:54 +00:00
|
|
|
Name: ''
|
2016-09-14 04:28:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function prepareNetworkConfiguration() {
|
|
|
|
var config = angular.copy($scope.config);
|
|
|
|
if ($scope.swarm) {
|
|
|
|
config.Driver = 'overlay';
|
2016-09-23 04:54:58 +00:00
|
|
|
// Force IPAM Driver to 'default', should not be required.
|
|
|
|
// See: https://github.com/docker/docker/issues/25735
|
|
|
|
config.IPAM = {
|
|
|
|
Driver: 'default'
|
|
|
|
};
|
2016-07-08 05:26:18 +00:00
|
|
|
}
|
2016-09-14 04:28:38 +00:00
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.createNetwork = function() {
|
|
|
|
$('#createNetworkSpinner').show();
|
|
|
|
var config = prepareNetworkConfiguration();
|
|
|
|
Network.create(config, function (d) {
|
|
|
|
if (d.message) {
|
|
|
|
$('#createNetworkSpinner').hide();
|
|
|
|
Messages.error('Unable to create network', {}, d.message);
|
|
|
|
} else {
|
|
|
|
Messages.send("Network created", d.Id);
|
|
|
|
$('#createNetworkSpinner').hide();
|
|
|
|
$state.go('networks', {}, {reload: true});
|
|
|
|
}
|
|
|
|
}, function (e) {
|
|
|
|
$('#createNetworkSpinner').hide();
|
|
|
|
Messages.error("Failure", e, 'Unable to create network');
|
|
|
|
});
|
2016-07-06 07:04:45 +00:00
|
|
|
};
|
2015-12-21 02:07:57 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.order = function(sortType) {
|
|
|
|
$scope.sortReverse = ($scope.sortType === sortType) ? !$scope.sortReverse : false;
|
|
|
|
$scope.sortType = sortType;
|
|
|
|
};
|
2015-12-18 05:35:04 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.selectItem = function (item) {
|
|
|
|
if (item.Checked) {
|
|
|
|
$scope.state.selectedItemCount++;
|
|
|
|
} else {
|
|
|
|
$scope.state.selectedItemCount--;
|
|
|
|
}
|
|
|
|
};
|
2015-12-18 05:35:04 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.removeAction = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadNetworksSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
var counter = 0;
|
|
|
|
var complete = function () {
|
|
|
|
counter = counter - 1;
|
|
|
|
if (counter === 0) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadNetworksSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
angular.forEach($scope.networks, function (network) {
|
|
|
|
if (network.Checked) {
|
|
|
|
counter = counter + 1;
|
|
|
|
Network.remove({id: network.Id}, function (d) {
|
2016-09-01 00:20:19 +00:00
|
|
|
if (d.message) {
|
|
|
|
Messages.send("Error", d.message);
|
2016-07-27 05:36:22 +00:00
|
|
|
} else {
|
2016-09-01 00:20:19 +00:00
|
|
|
Messages.send("Network removed", network.Id);
|
2016-07-27 05:36:22 +00:00
|
|
|
var index = $scope.networks.indexOf(network);
|
|
|
|
$scope.networks.splice(index, 1);
|
|
|
|
}
|
2016-06-02 05:34:03 +00:00
|
|
|
complete();
|
|
|
|
}, function (e) {
|
2016-09-02 05:40:03 +00:00
|
|
|
Messages.error("Failure", e, 'Unable to remove network');
|
2016-06-02 05:34:03 +00:00
|
|
|
complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2015-12-21 02:07:57 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
function fetchNetworks() {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadNetworksSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Network.query({}, function (d) {
|
|
|
|
$scope.networks = d;
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadNetworksSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadNetworksSpinner').hide();
|
2016-09-02 05:40:03 +00:00
|
|
|
Messages.error("Failure", e, "Unable to retrieve networks");
|
2016-10-08 01:59:58 +00:00
|
|
|
$scope.networks = [];
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
}
|
2016-08-10 06:20:18 +00:00
|
|
|
|
2016-09-14 04:28:38 +00:00
|
|
|
Config.$promise.then(function (c) {
|
|
|
|
$scope.swarm = c.swarm;
|
|
|
|
fetchNetworks();
|
|
|
|
});
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|