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/main.js

110 lines
3.6 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('MainController', ['$rootScope', '$scope', '$route', '$interval', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $route, $interval, ariaNgCommonService, ariaNgSettingService, aria2TaskService, aria2SettingService) {
2016-05-17 16:15:28 +02:00
var globalStatRefreshPromise = null;
2016-06-04 09:33:40 +02:00
var refreshGlobalStat = function (silent) {
2016-05-31 16:51:12 +02:00
return aria2SettingService.getGlobalStat(function (result) {
$scope.globalStat = result;
2016-06-04 09:33:40 +02:00
}, silent);
2016-05-17 16:15:28 +02:00
};
2016-05-31 16:51:12 +02:00
$scope.isTaskSelected = function () {
return $rootScope.taskContext.getSelectedTaskIds().length > 0;
};
2016-05-17 16:15:28 +02:00
2016-05-31 16:51:12 +02:00
$scope.isSpecifiedTaskSelected = function (status) {
var selectedTasks = $rootScope.taskContext.getSelectedTasks();
2016-05-30 19:26:41 +02:00
2016-05-31 16:51:12 +02:00
if (selectedTasks.length < 1) {
return false;
2016-05-30 19:26:41 +02:00
}
2016-05-31 16:51:12 +02:00
for (var i = 0; i < selectedTasks.length; i++) {
if (selectedTasks[i].status == status) {
return true;
2016-05-30 19:26:41 +02:00
}
2016-05-31 16:51:12 +02:00
}
return false;
2016-05-30 19:26:41 +02:00
};
2016-05-31 16:51:12 +02:00
$scope.changeTasksState = function (state) {
2016-05-30 19:26:41 +02:00
var gids = $rootScope.taskContext.getSelectedTaskIds();
if (!gids || gids.length < 1) {
return;
}
2016-05-31 16:51:12 +02:00
var invoke = null;
if (state == 'start') {
2016-06-01 16:05:36 +02:00
invoke = aria2TaskService.startTasks;
2016-05-31 16:51:12 +02:00
} else if (state == 'pause') {
2016-06-01 16:05:36 +02:00
invoke = aria2TaskService.pauseTasks;
2016-05-31 16:51:12 +02:00
} else {
return;
}
$rootScope.loadPromise = invoke(gids, function (result) {
$route.reload();
2016-05-30 19:26:41 +02:00
});
};
2016-05-31 16:51:12 +02:00
$scope.removeTasks = function () {
2016-05-30 19:26:41 +02:00
var gids = $rootScope.taskContext.getSelectedTaskIds();
if (!gids || gids.length < 1) {
return;
}
2016-05-31 16:51:12 +02:00
ariaNgCommonService.confirm('Confirm Remove', 'Are you sure you want to remove the selected task?', 'warning', function () {
2016-05-30 19:26:41 +02:00
});
};
$scope.clearFinishedTasks = function () {
2016-05-31 16:51:12 +02:00
ariaNgCommonService.confirm('Confirm Clear', 'Are you sure you want to clear finished tasks?', 'warning', function () {
2016-05-30 19:26:41 +02:00
});
};
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
};
$scope.changeDisplayOrder = function (type, autoSetReverse) {
2016-05-31 16:51:12 +02:00
var oldType = ariaNgCommonService.parseOrderType(ariaNgSettingService.getDisplayOrder());
var newType = ariaNgCommonService.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-31 16:51:12 +02:00
var orderType = ariaNgCommonService.parseOrderType(ariaNgSettingService.getDisplayOrder());
var targetType = ariaNgCommonService.parseOrderType(type);
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 () {
2016-06-04 09:33:40 +02:00
refreshGlobalStat(true);
2016-05-17 16:15:28 +02:00
}, ariaNgSettingService.getGlobalStatRefreshInterval());
}
$scope.$on('$destroy', function () {
if (globalStatRefreshPromise) {
$interval.cancel(globalStatRefreshPromise);
}
});
2016-05-31 16:51:12 +02:00
2016-06-04 09:33:40 +02:00
refreshGlobalStat(false);
2016-05-13 18:09:12 +02:00
}]);
})();