2016-05-13 18:09:12 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2016-05-30 19:26:41 +02:00
|
|
|
angular.module('ariaNg').controller('MainController', ['$rootScope', '$scope', '$route', '$interval', 'aria2RpcService', 'ariaNgSettingService', 'utils', function ($rootScope, $scope, $route, $interval, aria2RpcService, ariaNgSettingService, utils) {
|
2016-05-17 16:15:28 +02:00
|
|
|
var globalStatRefreshPromise = null;
|
|
|
|
|
2016-05-13 18:09:12 +02:00
|
|
|
var processStatResult = function (stat) {
|
|
|
|
var activeCount = parseInt(stat.numActive);
|
|
|
|
var waitingCount = parseInt(stat.numWaiting);
|
|
|
|
var totalRunningCount = activeCount + waitingCount;
|
|
|
|
|
|
|
|
stat.totalRunningCount = totalRunningCount;
|
|
|
|
};
|
|
|
|
|
2016-05-17 16:15:28 +02:00
|
|
|
var refreshGlobalStat = function () {
|
2016-05-13 18:09:12 +02:00
|
|
|
aria2RpcService.getGlobalStat({
|
|
|
|
callback: function (result) {
|
|
|
|
if (result) {
|
|
|
|
processStatResult(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.globalStat = result;
|
|
|
|
}
|
|
|
|
});
|
2016-05-17 16:15:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
refreshGlobalStat();
|
|
|
|
|
2016-05-30 19:26:41 +02:00
|
|
|
$scope.startTask = function () {
|
|
|
|
var gids = $rootScope.taskContext.getSelectedTaskIds();
|
|
|
|
|
|
|
|
if (!gids || gids.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rootScope.loadPromise = aria2RpcService.unpauseMulti({
|
|
|
|
gids: gids,
|
|
|
|
callback: function (result) {
|
|
|
|
$route.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.pauseTask = function () {
|
|
|
|
var gids = $rootScope.taskContext.getSelectedTaskIds();
|
|
|
|
|
|
|
|
if (!gids || gids.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rootScope.loadPromise = aria2RpcService.forcePauseMulti({
|
|
|
|
gids: gids,
|
|
|
|
callback: function (result) {
|
|
|
|
$route.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeTask = function () {
|
|
|
|
var gids = $rootScope.taskContext.getSelectedTaskIds();
|
|
|
|
|
|
|
|
if (!gids || gids.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
utils.confirm('Confirm Remove', 'Are you sure you want to remove the selected task?', 'warning', function () {
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.clearFinishedTasks = function () {
|
|
|
|
utils.confirm('Confirm Clear', 'Are you sure you want to clear finished tasks?', 'warning', function () {
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-05-29 17:27:47 +02:00
|
|
|
$scope.isTaskSelected = function () {
|
2016-05-30 16:34:15 +02:00
|
|
|
return $rootScope.taskContext.getSelectedTaskIds().length > 0;
|
2016-05-29 17:27:47 +02:00
|
|
|
};
|
|
|
|
|
2016-05-30 19:26:41 +02:00
|
|
|
$scope.isStartableTaskSelected = function () {
|
|
|
|
var selectedTasks = $rootScope.taskContext.getSelectedTasks();
|
|
|
|
|
|
|
|
if (selectedTasks.length < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < selectedTasks.length; i++) {
|
|
|
|
if (selectedTasks[i].status == 'paused') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.isPausableTaskSelected = function () {
|
|
|
|
var selectedTasks = $rootScope.taskContext.getSelectedTasks();
|
|
|
|
|
|
|
|
if (selectedTasks.length < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < selectedTasks.length; i++) {
|
|
|
|
if (selectedTasks[i].status == 'active') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2016-05-29 17:27:47 +02:00
|
|
|
$scope.selectAllTasks = function () {
|
2016-05-30 16:34:15 +02:00
|
|
|
$rootScope.taskContext.selectAll();
|
2016-05-29 17:27:47 +02:00
|
|
|
};
|
|
|
|
|
2016-05-22 05:13:05 +02:00
|
|
|
$scope.changeDisplayOrder = function (type, autoSetReverse) {
|
|
|
|
var oldType = utils.parseOrderType(ariaNgSettingService.getDisplayOrder());
|
|
|
|
var newType = utils.parseOrderType(type);
|
|
|
|
|
|
|
|
if (autoSetReverse && newType.type == oldType.type) {
|
|
|
|
newType.reverse = !oldType.reverse;
|
|
|
|
}
|
|
|
|
|
|
|
|
ariaNgSettingService.setDisplayOrder(newType.getValue());
|
2016-05-17 16:15:28 +02:00
|
|
|
};
|
|
|
|
|
2016-05-25 18:09:00 +02:00
|
|
|
$scope.isSetDisplayOrder = function (type) {
|
2016-05-22 05:13:05 +02:00
|
|
|
var orderType = utils.parseOrderType(ariaNgSettingService.getDisplayOrder());
|
2016-05-25 18:09:00 +02:00
|
|
|
var targetType = utils.parseOrderType(type);
|
2016-05-22 05:13:05 +02:00
|
|
|
|
2016-05-25 18:09:00 +02:00
|
|
|
return orderType.equals(targetType);
|
2016-05-17 16:15:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (ariaNgSettingService.getGlobalStatRefreshInterval() > 0) {
|
|
|
|
globalStatRefreshPromise = $interval(function () {
|
|
|
|
refreshGlobalStat();
|
|
|
|
}, ariaNgSettingService.getGlobalStatRefreshInterval());
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function () {
|
|
|
|
if (globalStatRefreshPromise) {
|
|
|
|
$interval.cancel(globalStatRefreshPromise);
|
|
|
|
}
|
|
|
|
});
|
2016-05-13 18:09:12 +02:00
|
|
|
}]);
|
|
|
|
})();
|