2016-05-23 19:06:50 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('ariaNg').controller('TaskDetailController', ['$scope', '$routeParams', '$interval', 'aria2RpcService', 'ariaNgSettingService', 'utils', function ($scope, $routeParams, $interval, aria2RpcService, ariaNgSettingService, utils) {
|
|
|
|
var downloadTaskRefreshPromise = null;
|
|
|
|
|
2016-05-24 17:30:33 +02:00
|
|
|
var refreshPeers = function () {
|
|
|
|
return aria2RpcService.getPeers({
|
|
|
|
params: [$routeParams.gid],
|
|
|
|
callback: function (result) {
|
|
|
|
if (!utils.extendArray(result, $scope.peers, 'peerId')) {
|
|
|
|
$scope.peers = result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2016-05-23 19:06:50 +02:00
|
|
|
var refreshDownloadTask = function () {
|
|
|
|
return aria2RpcService.tellStatus({
|
|
|
|
params: [$routeParams.gid],
|
|
|
|
callback: function (result) {
|
|
|
|
var task = utils.processDownloadTask(result);
|
2016-05-24 17:30:33 +02:00
|
|
|
|
|
|
|
if (task.status == 'active' && task.bittorrent) {
|
|
|
|
refreshPeers();
|
|
|
|
}
|
|
|
|
|
2016-05-23 19:06:50 +02:00
|
|
|
$scope.task = utils.copyObjectTo(task, $scope.task);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.context = {
|
|
|
|
currentTab: 'overview'
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.loadPromise = refreshDownloadTask();
|
|
|
|
|
|
|
|
if (ariaNgSettingService.getDownloadTaskRefreshInterval() > 0) {
|
|
|
|
downloadTaskRefreshPromise = $interval(function () {
|
|
|
|
refreshDownloadTask();
|
|
|
|
}, ariaNgSettingService.getDownloadTaskRefreshInterval());
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function () {
|
|
|
|
if (downloadTaskRefreshPromise) {
|
|
|
|
$interval.cancel(downloadTaskRefreshPromise);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}]);
|
|
|
|
})();
|