mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 15:29:42 +02:00
fix(networks): review how networks are loaded for usage in multiple views (#1104)
This commit is contained in:
parent
3d5f9a76e4
commit
d814f3aaa4
5 changed files with 67 additions and 90 deletions
|
@ -3,21 +3,29 @@ angular.module('portainer.services')
|
|||
'use strict';
|
||||
var service = {};
|
||||
|
||||
service.networks = function() {
|
||||
return Network.query({}).$promise;
|
||||
};
|
||||
|
||||
service.retrieveSwarmNetworks = function() {
|
||||
service.networks = function(localNetworks, swarmNetworks, swarmAttachableNetworks, globalNetworks) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
service.networks()
|
||||
Network.query({}).$promise
|
||||
.then(function success(data) {
|
||||
var networks = data.filter(function (network) {
|
||||
if (network.Scope === 'swarm') {
|
||||
var networks = data;
|
||||
|
||||
var filteredNetworks = networks.filter(function(network) {
|
||||
if (localNetworks && network.Scope === 'local') {
|
||||
return network;
|
||||
}
|
||||
if (swarmNetworks && network.Scope === 'swarm') {
|
||||
return network;
|
||||
}
|
||||
if (swarmAttachableNetworks && network.Scope === 'swarm' && network.Attachable === true) {
|
||||
return network;
|
||||
}
|
||||
if (globalNetworks && network.Scope === 'global') {
|
||||
return network;
|
||||
}
|
||||
});
|
||||
deferred.resolve(networks);
|
||||
|
||||
deferred.resolve(filteredNetworks);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject({msg: 'Unable to retrieve networks', err: err});
|
||||
|
@ -26,27 +34,5 @@ angular.module('portainer.services')
|
|||
return deferred.promise;
|
||||
};
|
||||
|
||||
service.filterGlobalNetworks = function(networks) {
|
||||
return networks.filter(function (network) {
|
||||
if (network.Scope === 'global') {
|
||||
return network;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
service.filterSwarmModeAttachableNetworks = function(networks) {
|
||||
return networks.filter(function (network) {
|
||||
if (network.Scope === 'swarm' && network.Attachable === true) {
|
||||
return network;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
service.addPredefinedLocalNetworks = function(networks) {
|
||||
networks.push({Scope: 'local', Name: 'bridge'});
|
||||
networks.push({Scope: 'local', Name: 'host'});
|
||||
networks.push({Scope: 'local', Name: 'none'});
|
||||
};
|
||||
|
||||
return service;
|
||||
}]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue