2016-06-02 05:34:03 +00:00
|
|
|
angular.module('networks', [])
|
2016-08-10 06:20:18 +00:00
|
|
|
.controller('NetworksController', ['$scope', '$state', 'Network', 'Config', 'Messages', 'errorMsgFilter',
|
|
|
|
function ($scope, $state, Network, Config, Messages, errorMsgFilter) {
|
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-07-08 05:26:18 +00:00
|
|
|
$scope.formValues = {
|
|
|
|
Subnet: '',
|
|
|
|
Gateway: ''
|
|
|
|
};
|
|
|
|
|
2016-07-06 07:04:45 +00:00
|
|
|
$scope.config = {
|
2016-07-08 05:26:18 +00:00
|
|
|
Name: '',
|
|
|
|
IPAM: {
|
|
|
|
Config: []
|
|
|
|
}
|
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-01 00:20:19 +00:00
|
|
|
console.log(JSON.stringify(e, null, 4));
|
|
|
|
if (e.data.message) {
|
|
|
|
Messages.error("Failure", e.data.message);
|
|
|
|
} else {
|
|
|
|
Messages.error("Failure", '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) {
|
|
|
|
Messages.error("Failure", e.data);
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadNetworksSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
}
|
2016-08-10 06:20:18 +00:00
|
|
|
|
2016-08-17 05:25:42 +00:00
|
|
|
fetchNetworks();
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|