123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- (function () {
- 'use strict';
- angular.module('ariaNg').controller('DownloadListController', ['$rootScope', '$scope', '$window', '$location', '$route', '$interval', 'dragulaService', 'aria2RpcErrors', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2TaskService', function ($rootScope, $scope, $window, $location, $route, $interval, dragulaService, aria2RpcErrors, ariaNgCommonService, ariaNgSettingService, aria2TaskService) {
- var location = $location.path().substring(1);
- var downloadTaskRefreshPromise = null;
- var pauseDownloadTaskRefresh = false;
- var needRequestWholeInfo = true;
- var refreshDownloadTask = function (silent) {
- if (pauseDownloadTaskRefresh) {
- return;
- }
- return aria2TaskService.getTaskList(location, needRequestWholeInfo, function (response) {
- if (pauseDownloadTaskRefresh) {
- return;
- }
- if (!response.success) {
- if (response.data.message === aria2RpcErrors.Unauthorized.message) {
- $interval.cancel(downloadTaskRefreshPromise);
- }
- return;
- }
- var isRequestWholeInfo = response.context.requestWholeInfo;
- var taskList = response.data;
- if (isRequestWholeInfo) {
- $rootScope.taskContext.list = taskList;
- needRequestWholeInfo = false;
- } else {
- if ($rootScope.taskContext.list && $rootScope.taskContext.list.length > 0) {
- for (var i = 0; i < $rootScope.taskContext.list.length; i++) {
- var task = $rootScope.taskContext.list[i];
- delete task.verifiedLength;
- delete task.verifyIntegrityPending;
- }
- }
- if (ariaNgCommonService.extendArray(taskList, $rootScope.taskContext.list, 'gid')) {
- needRequestWholeInfo = false;
- } else {
- needRequestWholeInfo = true;
- }
- }
- if ($rootScope.taskContext.list && $rootScope.taskContext.list.length > 0) {
- aria2TaskService.processDownloadTasks($rootScope.taskContext.list);
- if (!isRequestWholeInfo) {
- var hasFullStruct = false;
- for (var i = 0; i < $rootScope.taskContext.list.length; i++) {
- var task = $rootScope.taskContext.list[i];
- if (task.hasTaskName || task.files || task.bittorrent) {
- hasFullStruct = true;
- break;
- }
- }
- if (!hasFullStruct) {
- needRequestWholeInfo = true;
- $rootScope.taskContext.list.length = 0;
- return;
- }
- }
- }
- $rootScope.taskContext.enableSelectAll = $rootScope.taskContext.list && $rootScope.taskContext.list.length > 0;
- }, silent);
- };
- $scope.getOrderType = function () {
- return ariaNgSettingService.getDisplayOrder();
- };
- $scope.isSupportDragTask = function () {
- if (!ariaNgSettingService.getDragAndDropTasks()) {
- return false;
- }
- var displayOrder = ariaNgCommonService.parseOrderType(ariaNgSettingService.getDisplayOrder());
- return location === 'waiting' && displayOrder.type === 'default';
- };
- if (ariaNgSettingService.getDownloadTaskRefreshInterval() > 0) {
- downloadTaskRefreshPromise = $interval(function () {
- refreshDownloadTask(true);
- }, ariaNgSettingService.getDownloadTaskRefreshInterval());
- }
- dragulaService.options($scope, 'task-list', {
- revertOnSpill: true,
- moves: function () {
- return $scope.isSupportDragTask();
- }
- });
- $scope.$on('task-list.drop-model', function (el, target, source) {
- var element = angular.element(target);
- var gid = element.attr('data-gid');
- var index = element.index();
- pauseDownloadTaskRefresh = true;
- aria2TaskService.changeTaskPosition(gid, index, function () {
- pauseDownloadTaskRefresh = false;
- }, true);
- });
- $scope.$on('$destroy', function () {
- pauseDownloadTaskRefresh = true;
- if (downloadTaskRefreshPromise) {
- $interval.cancel(downloadTaskRefreshPromise);
- }
- });
- $rootScope.keydownActions.selectAll = $scope.selectAllTasks;
- $rootScope.keydownActions.delete = $scope.removeTasks;
- $rootScope.loadPromise = refreshDownloadTask(false);
- }]);
- }());
|