2017-05-23 18:56:10 +00:00
|
|
|
angular.module('portainer.services')
|
|
|
|
.factory('TaskService', ['$q', 'Task', function TaskServiceFactory($q, Task) {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
|
|
|
|
2017-09-14 06:04:59 +00:00
|
|
|
service.tasks = function() {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
Task.query().$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
var tasks = data.map(function (item) {
|
|
|
|
return new TaskViewModel(item);
|
|
|
|
});
|
|
|
|
deferred.resolve(tasks);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve tasks', err: err });
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
service.task = function(id) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
Task.get({ id: id }).$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
var task = new TaskViewModel(data);
|
|
|
|
deferred.resolve(task);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve task details', err: err });
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
service.serviceTasks = function(serviceName) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
Task.query({ filters: { service: [serviceName] } }).$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
var tasks = data.map(function (item) {
|
|
|
|
return new TaskViewModel(item);
|
|
|
|
});
|
|
|
|
deferred.resolve(tasks);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve tasks associated to the service', err: err });
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
return service;
|
|
|
|
}]);
|