2017-05-23 18:56:10 +00:00
|
|
|
angular.module('portainer.services')
|
|
|
|
.factory('NodeService', ['$q', 'Node', function NodeServiceFactory($q, Node) {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
|
|
|
|
2017-09-14 06:04:59 +00:00
|
|
|
service.nodes = function() {
|
2017-05-23 18:56:10 +00:00
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
Node.query({}).$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
var nodes = data.map(function (item) {
|
|
|
|
return new NodeViewModel(item);
|
|
|
|
});
|
|
|
|
deferred.resolve(nodes);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve nodes', err: err });
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
return service;
|
|
|
|
}]);
|