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
2016-05-31 22:51:12 +08:00

60 lines
2.4 KiB
JavaScript

(function () {
'use strict';
angular.module('ariaNg').controller('DownloadListController', ['$rootScope', '$scope', '$window', '$location', '$interval', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgTaskService', function ($rootScope, $scope, $window, $location, $interval, ariaNgCommonService, ariaNgSettingService, ariaNgTaskService) {
var location = $location.path().substring(1);
var downloadTaskRefreshPromise = null;
var needRequestWholeInfo = true;
var refreshDownloadTask = function () {
return ariaNgTaskService.getTaskList(location, needRequestWholeInfo, function (result) {
if (!ariaNgCommonService.extendArray(result, $rootScope.taskContext.list, 'gid')) {
if (needRequestWholeInfo) {
$rootScope.taskContext.list = result;
needRequestWholeInfo = false;
} else {
needRequestWholeInfo = true;
}
} else {
needRequestWholeInfo = false;
}
if ($rootScope.taskContext.list) {
ariaNgTaskService.processDownloadTasks($rootScope.taskContext.list);
$rootScope.taskContext.enableSelectAll = $rootScope.taskContext.list.length > 1;
}
});
};
$scope.filterByTaskName = function (task) {
if (!task || !angular.isString(task.taskName)) {
return false;
}
if (!$rootScope.searchContext || !$rootScope.searchContext.text) {
return true;
}
return (task.taskName.toLowerCase().indexOf($rootScope.searchContext.text.toLowerCase()) >= 0);
};
$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);
}
});
$rootScope.loadPromise = refreshDownloadTask();
}]);
})();