2018-01-21 16:26:24 +00:00
|
|
|
angular.module('extension.storidge')
|
2018-02-23 02:10:26 +00:00
|
|
|
.factory('StoridgeNodeService', ['$q', 'Storidge', function StoridgeNodeServiceFactory($q, Storidge) {
|
2018-01-21 16:26:24 +00:00
|
|
|
'use strict';
|
|
|
|
var service = {};
|
|
|
|
|
|
|
|
service.nodes = function() {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
2018-02-23 02:10:26 +00:00
|
|
|
Storidge.queryNodes().$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
var nodeData = data.nodes;
|
2018-01-21 16:26:24 +00:00
|
|
|
var nodes = [];
|
|
|
|
|
|
|
|
for (var key in nodeData) {
|
|
|
|
if (nodeData.hasOwnProperty(key)) {
|
|
|
|
nodes.push(new StoridgeNodeModel(key, nodeData[key]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deferred.resolve(nodes);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve Storidge profiles', err: err });
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
return service;
|
|
|
|
}]);
|