2019-03-21 05:46:49 +00:00
|
|
|
import { ResourceGroupViewModel } from '../models/resource_group';
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
angular.module('portainer.azure').factory('ResourceGroupService', [
|
|
|
|
'$q',
|
|
|
|
'ResourceGroup',
|
|
|
|
function ResourceGroupServiceFactory($q, ResourceGroup) {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
2018-05-28 14:40:33 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.resourceGroups = function (subscriptionId) {
|
|
|
|
var deferred = $q.defer();
|
2018-05-28 14:40:33 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
ResourceGroup.query({ subscriptionId: subscriptionId })
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
var resourceGroups = data.value.map(function (item) {
|
|
|
|
return new ResourceGroupViewModel(item, subscriptionId);
|
|
|
|
});
|
|
|
|
deferred.resolve(resourceGroups);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve resource groups', err: err });
|
|
|
|
});
|
2018-05-28 14:40:33 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return deferred.promise;
|
|
|
|
};
|
2018-05-28 14:40:33 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return service;
|
|
|
|
},
|
|
|
|
]);
|