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

76 lines
3 KiB
JavaScript
Raw Normal View History

2016-05-13 18:09:12 +02:00
(function () {
'use strict';
2016-05-30 17:02:03 +02:00
angular.module('ariaNg').controller('DownloadListController', ['$rootScope', '$scope', '$window', '$location', '$interval', 'aria2RpcService', 'ariaNgSettingService', 'utils', function ($rootScope, $scope, $window, $location, $interval, 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;
2016-05-24 16:22:47 +02:00
2016-05-13 18:09:12 +02:00
if (location == 'downloading') {
invokeMethod = aria2RpcService.tellActive;
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-16 15:45:54 +02:00
} else if (location == 'stopped') {
2016-05-13 18:09:12 +02:00
invokeMethod = aria2RpcService.tellStopped;
}
if (invokeMethod) {
2016-05-17 17:32:36 +02:00
return invokeMethod({
2016-05-30 19:26:41 +02:00
requestParams: needRequestWholeInfo ? aria2RpcService.getFullTaskParams() : aria2RpcService.getBasicTaskParams(),
2016-05-13 18:09:12 +02:00
callback: function (result) {
2016-05-30 16:34:15 +02:00
if (!utils.extendArray(result, $rootScope.taskContext.list, 'gid')) {
2016-05-24 16:22:47 +02:00
if (needRequestWholeInfo) {
2016-05-30 16:34:15 +02:00
$rootScope.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-30 16:34:15 +02:00
if ($rootScope.taskContext.list && $rootScope.taskContext.list.length > 0) {
for (var i = 0; i < $rootScope.taskContext.list.length; i++) {
utils.processDownloadTask($rootScope.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-30 19:26:41 +02:00
$rootScope.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;
}
2016-05-30 16:34:15 +02:00
if (!$rootScope.searchContext || !$rootScope.searchContext.text) {
2016-05-28 16:20:42 +02:00
return true;
}
2016-05-30 16:34:15 +02:00
return (task.taskName.toLowerCase().indexOf($rootScope.searchContext.text.toLowerCase()) >= 0);
2016-05-28 16:20:42 +02:00
};
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
}]);
})();