This repository has been archived on 2022-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
AriaNg/app/scripts/controllers/list.js

95 lines
3.5 KiB
JavaScript
Raw Normal View History

2016-05-13 18:09:12 +02:00
(function () {
'use strict';
angular.module('ariaNg').controller('DownloadListController', ['$scope', '$window', '$location', '$interval', 'translateFilter', 'aria2RpcService', 'ariaNgSettingService', 'utils', function ($scope, $window, $location, $interval, translateFilter, aria2RpcService, ariaNgSettingService, utils) {
2016-05-13 18:09:12 +02:00
var location = $location.path().substring(1);
2016-05-17 16:15:28 +02:00
var downloadTaskRefreshPromise = null;
2016-05-24 16:22:47 +02:00
var needRequestWholeInfo = true;
2016-05-13 18:09:12 +02:00
2016-05-17 16:15:28 +02:00
var refreshDownloadTask = function () {
2016-05-13 18:09:12 +02:00
var invokeMethod = null;
var params = [];
2016-05-22 05:23:20 +02:00
var requestParams = [
'gid',
'totalLength',
'completedLength',
'uploadSpeed',
'downloadSpeed',
'connections',
'numSeeders',
'seeder'
];
2016-05-13 18:09:12 +02:00
2016-05-24 16:22:47 +02:00
if (needRequestWholeInfo) {
requestParams.push('files');
requestParams.push('bittorrent');
}
2016-05-13 18:09:12 +02:00
if (location == 'downloading') {
invokeMethod = aria2RpcService.tellActive;
2016-05-22 05:23:20 +02:00
params = [requestParams];
2016-05-16 15:20:52 +02:00
} else if (location == 'waiting') {
2016-05-13 18:09:12 +02:00
invokeMethod = aria2RpcService.tellWaiting;
2016-05-22 05:23:20 +02:00
params = [0, 1000, requestParams];
2016-05-16 15:45:54 +02:00
} else if (location == 'stopped') {
2016-05-13 18:09:12 +02:00
invokeMethod = aria2RpcService.tellStopped;
2016-05-22 05:23:20 +02:00
params = [0, 1000, requestParams];
2016-05-13 18:09:12 +02:00
}
if (invokeMethod) {
2016-05-17 17:32:36 +02:00
return invokeMethod({
2016-05-13 18:09:12 +02:00
params: params,
callback: function (result) {
2016-05-29 17:27:47 +02:00
if (!utils.extendArray(result, $scope.taskContext.list, 'gid')) {
2016-05-24 16:22:47 +02:00
if (needRequestWholeInfo) {
2016-05-29 17:27:47 +02:00
$scope.taskContext.list = result;
2016-05-24 16:22:47 +02:00
needRequestWholeInfo = false;
} else {
needRequestWholeInfo = true;
2016-05-13 18:09:12 +02:00
}
2016-05-24 16:22:47 +02:00
} else {
needRequestWholeInfo = false;
2016-05-13 18:09:12 +02:00
}
2016-05-29 17:27:47 +02:00
if ($scope.taskContext.list && $scope.taskContext.list.length > 0) {
for (var i = 0; i < $scope.taskContext.list.length; i++) {
utils.processDownloadTask($scope.taskContext.list[i]);
2016-05-24 16:22:47 +02:00
}
2016-05-13 18:09:12 +02:00
}
}
});
}
2016-05-17 16:15:28 +02:00
};
2016-05-17 17:32:36 +02:00
$scope.loadPromise = refreshDownloadTask();
2016-05-17 16:15:28 +02:00
2016-05-28 16:20:42 +02:00
$scope.filterByTaskName = function (task) {
if (!task || !angular.isString(task.taskName)) {
return false;
}
if (!$scope.searchContext || !$scope.searchContext.text) {
return true;
}
return (task.taskName.toLowerCase().indexOf($scope.searchContext.text.toLowerCase()) >= 0);
};
2016-05-17 16:15:28 +02:00
$scope.getOrderType = function () {
return ariaNgSettingService.getDisplayOrder();
};
if (ariaNgSettingService.getDownloadTaskRefreshInterval() > 0) {
downloadTaskRefreshPromise = $interval(function () {
refreshDownloadTask();
}, ariaNgSettingService.getDownloadTaskRefreshInterval());
}
$scope.$on('$destroy', function () {
if (downloadTaskRefreshPromise) {
$interval.cancel(downloadTaskRefreshPromise);
}
});
2016-05-13 18:09:12 +02:00
}]);
})();