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

90 lines
3.4 KiB
JavaScript
Raw Normal View History

2016-05-13 18:09:12 +02:00
(function () {
'use strict';
2016-06-01 16:05:36 +02:00
angular.module('ariaNg').controller('DownloadListController', ['$rootScope', '$scope', '$window', '$location', '$route', '$interval', 'dragulaService', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2TaskService', function ($rootScope, $scope, $window, $location, $route, $interval, dragulaService, ariaNgCommonService, ariaNgSettingService, aria2TaskService) {
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;
var pauseDownloadTaskRefresh = false;
2016-05-24 16:22:47 +02:00
var needRequestWholeInfo = true;
2016-05-13 18:09:12 +02:00
2016-06-04 09:33:40 +02:00
var refreshDownloadTask = function (silent) {
if (pauseDownloadTaskRefresh) {
return;
}
2016-06-01 16:05:36 +02:00
return aria2TaskService.getTaskList(location, needRequestWholeInfo, function (result) {
2016-05-31 16:51:12 +02:00
if (!ariaNgCommonService.extendArray(result, $rootScope.taskContext.list, 'gid')) {
if (needRequestWholeInfo) {
$rootScope.taskContext.list = result;
needRequestWholeInfo = false;
} else {
needRequestWholeInfo = true;
2016-05-13 18:09:12 +02:00
}
2016-05-31 16:51:12 +02:00
} else {
needRequestWholeInfo = false;
}
if ($rootScope.taskContext.list) {
2016-06-01 16:05:36 +02:00
aria2TaskService.processDownloadTasks($rootScope.taskContext.list);
2016-05-31 16:51:12 +02:00
$rootScope.taskContext.enableSelectAll = $rootScope.taskContext.list.length > 1;
}
2016-06-04 09:33:40 +02:00
}, silent);
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();
};
$scope.isSupportDragTask = function () {
var displayOrder = ariaNgCommonService.parseOrderType(ariaNgSettingService.getDisplayOrder());
return location == 'waiting' && displayOrder.type == 'default';
};
2016-05-17 16:15:28 +02:00
if (ariaNgSettingService.getDownloadTaskRefreshInterval() > 0) {
downloadTaskRefreshPromise = $interval(function () {
2016-06-04 09:33:40 +02:00
refreshDownloadTask(true);
2016-05-17 16:15:28 +02:00
}, ariaNgSettingService.getDownloadTaskRefreshInterval());
}
dragulaService.options($scope, 'task-list', {
revertOnSpill: true,
moves: function (el, container, handle) {
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;
2016-06-01 16:05:36 +02:00
aria2TaskService.changeTaskPosition(gid, index, function (result) {
pauseDownloadTaskRefresh = false;
});
});
$scope.$on('$destroy', function () {
if (downloadTaskRefreshPromise) {
$interval.cancel(downloadTaskRefreshPromise);
}
});
2016-05-31 16:51:12 +02:00
2016-06-04 09:33:40 +02:00
$rootScope.loadPromise = refreshDownloadTask(false);
2016-05-13 18:09:12 +02:00
}]);
})();