2016-05-13 18:09:12 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2016-05-16 17:41:39 +02:00
|
|
|
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
|
|
|
|
|
|
|
var getTitleWidth = function () {
|
2016-05-23 19:19:01 +02:00
|
|
|
var titleColumn = angular.element('#task-table > .row > .col-md-8:first-child');
|
2016-05-13 18:09:12 +02:00
|
|
|
|
|
|
|
if (titleColumn.length > 0) {
|
|
|
|
return titleColumn.width();
|
|
|
|
} else {
|
2016-05-23 19:19:01 +02:00
|
|
|
var taskTable = angular.element('#task-table');
|
2016-05-13 18:09:12 +02:00
|
|
|
|
|
|
|
if ($window.innerWidth <= 767) {
|
|
|
|
return taskTable.width();
|
|
|
|
} else {
|
|
|
|
return taskTable.width() / 12 * 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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-24 16:22:47 +02:00
|
|
|
if (!utils.extendArray(result, $scope.downloadTasks, 'gid')) {
|
|
|
|
if (needRequestWholeInfo) {
|
|
|
|
$scope.downloadTasks = result;
|
|
|
|
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-24 16:22:47 +02:00
|
|
|
if ($scope.downloadTasks && $scope.downloadTasks.length > 0) {
|
|
|
|
for (var i = 0; i < $scope.downloadTasks.length; i++) {
|
|
|
|
utils.processDownloadTask($scope.downloadTasks[i]);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
angular.element($window).bind('resize', function () {
|
|
|
|
$scope.titleWidth = getTitleWidth();
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.titleWidth = getTitleWidth();
|
|
|
|
|
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());
|
|
|
|
}
|
2016-05-16 17:41:39 +02:00
|
|
|
|
|
|
|
$scope.$on('$destroy', function () {
|
|
|
|
if (downloadTaskRefreshPromise) {
|
|
|
|
$interval.cancel(downloadTaskRefreshPromise);
|
|
|
|
}
|
|
|
|
});
|
2016-05-13 18:09:12 +02:00
|
|
|
}]);
|
|
|
|
})();
|