2017-02-10 01:11:36 +00:00
|
|
|
angular.module('portainer.services')
|
|
|
|
.factory('NetworkService', ['$q', 'Network', function NetworkServiceFactory($q, Network) {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
|
|
|
|
2017-08-11 07:46:55 +00:00
|
|
|
service.networks = function(localNetworks, swarmNetworks, swarmAttachableNetworks, globalNetworks) {
|
2017-05-27 07:23:49 +00:00
|
|
|
var deferred = $q.defer();
|
|
|
|
|
2017-08-11 07:46:55 +00:00
|
|
|
Network.query({}).$promise
|
2017-05-27 07:23:49 +00:00
|
|
|
.then(function success(data) {
|
2017-08-11 07:46:55 +00:00
|
|
|
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') {
|
2017-05-27 07:23:49 +00:00
|
|
|
return network;
|
|
|
|
}
|
|
|
|
});
|
2017-08-11 07:46:55 +00:00
|
|
|
|
|
|
|
deferred.resolve(filteredNetworks);
|
2017-05-27 07:23:49 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({msg: 'Unable to retrieve networks', err: err});
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
2017-02-10 01:11:36 +00:00
|
|
|
return service;
|
|
|
|
}]);
|