support restart task

This commit is contained in:
MaysWind 2016-12-11 00:25:19 +08:00
parent d03de0dc5c
commit 74e3b8f614
5 changed files with 133 additions and 9 deletions

View file

@ -15,6 +15,7 @@ RPC=RPC
New=新建 New=新建
Start=开始任务 Start=开始任务
Pause=暂停任务 Pause=暂停任务
Restart=重试
Delete=删除任务 Delete=删除任务
Select All=全选 Select All=全选
Select None=不选 Select None=不选
@ -96,6 +97,9 @@ Speed=速度
No Data=无数据 No Data=无数据
No connected peers=没有连接到其他节点 No connected peers=没有连接到其他节点
Failed to change some tasks state.=修改一些任务状态时失败. Failed to change some tasks state.=修改一些任务状态时失败.
Confirm Restart=确认重试
Are you sure you want to restart this task? AriaNg will create a same task after clicking OK.=您是否要重试这个任务? 点击 "确定" 后, AriaNg 将会创建一个相同的任务.
Failed to restart this task.=该任务重试失败.
Confirm Remove=确认删除 Confirm Remove=确认删除
Are you sure you want to remove the selected task?=您是否要删除选中的任务? Are you sure you want to remove the selected task?=您是否要删除选中的任务?
Failed to remove some task(s).=删除一些任务时失败. Failed to remove some task(s).=删除一些任务时失败.

View file

@ -19,6 +19,7 @@
'New': 'New', 'New': 'New',
'Start': 'Start', 'Start': 'Start',
'Pause': 'Pause', 'Pause': 'Pause',
'Restart': 'Restart',
'Delete': 'Delete', 'Delete': 'Delete',
'Select All': 'Select All', 'Select All': 'Select All',
'Select None': 'Select None', 'Select None': 'Select None',
@ -100,6 +101,9 @@
'No Data': 'No Data', 'No Data': 'No Data',
'No connected peers': 'No connected peers', 'No connected peers': 'No connected peers',
'Failed to change some tasks state.': 'Failed to change some tasks state.', 'Failed to change some tasks state.': 'Failed to change some tasks state.',
'Confirm Restart': 'Confirm Restart',
'Are you sure you want to restart this task? AriaNg will create a same task after clicking OK.': 'Are you sure you want to restart this task? AriaNg will create a same task after clicking OK.',
'Failed to restart this task.': 'Failed to restart this task.',
'Confirm Remove': 'Confirm Remove', 'Confirm Remove': 'Confirm Remove',
'Are you sure you want to remove the selected task?': 'Are you sure you want to remove the selected task?', 'Are you sure you want to remove the selected task?': 'Are you sure you want to remove the selected task?',
'Failed to remove some task(s).': 'Failed to remove some task(s).', 'Failed to remove some task(s).': 'Failed to remove some task(s).',

View file

@ -119,13 +119,13 @@
refreshGlobalStat(true); refreshGlobalStat(true);
if (!response.hasError && state === 'start') { if (!response.hasError && state === 'start') {
if ($location.path() === '/waiting') { if ($location.path() !== '/downloading') {
$location.path('/downloading'); $location.path('/downloading');
} else { } else {
$route.reload(); $route.reload();
} }
} else if (!response.hasError && state === 'pause') { } else if (!response.hasError && state === 'pause') {
if ($location.path() === '/downloading') { if ($location.path() !== '/waiting') {
$location.path('/waiting'); $location.path('/waiting');
} else { } else {
$route.reload(); $route.reload();
@ -134,6 +134,27 @@
}, (gids.length > 1)); }, (gids.length > 1));
}; };
$scope.restart = function (task) {
ariaNgCommonService.confirm('Confirm Restart', 'Are you sure you want to restart this task? AriaNg will create a same task after clicking OK.', 'info', function () {
$rootScope.loadPromise = aria2TaskService.restartTask(task.gid, function (response) {
if (!response.success) {
ariaNgCommonService.showError('Failed to restart this task.');
return;
}
refreshGlobalStat(true);
if (response.success) {
if ($location.path() !== '/downloading') {
$location.path('/downloading');
} else {
$route.reload();
}
}
}, false);
});
};
$scope.removeTasks = function () { $scope.removeTasks = function () {
var tasks = $rootScope.taskContext.getSelectedTasks(); var tasks = $rootScope.taskContext.getSelectedTasks();
@ -154,10 +175,10 @@
refreshGlobalStat(true); refreshGlobalStat(true);
if (!response.hasError) { if (!response.hasError) {
if ($location.path() === '/stopped') { if ($location.path() !== '/stopped') {
$route.reload();
} else {
$location.path('/stopped'); $location.path('/stopped');
} else {
$route.reload();
} }
} }
}, (tasks.length > 1)); }, (tasks.length > 1));
@ -173,10 +194,10 @@
refreshGlobalStat(true); refreshGlobalStat(true);
if ($location.path() === '/stopped') { if ($location.path() !== '/stopped') {
$route.reload();
} else {
$location.path('/stopped'); $location.path('/stopped');
} else {
$route.reload();
} }
}); });
}); });

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; 'use strict';
angular.module('ariaNg').factory('aria2TaskService', ['$q', '$translate', 'bittorrentPeeridService', 'aria2Errors', 'aria2RpcService', 'ariaNgCommonService', function ($q, $translate, bittorrentPeeridService, aria2Errors, aria2RpcService, ariaNgCommonService) { angular.module('ariaNg').factory('aria2TaskService', ['$q', '$translate', 'bittorrentPeeridService', 'aria2Errors', 'aria2RpcService', 'ariaNgCommonService', 'ariaNgLogService', function ($q, $translate, bittorrentPeeridService, aria2Errors, aria2RpcService, ariaNgCommonService, ariaNgLogService) {
var getFileName = function (file) { var getFileName = function (file) {
if (!file) { if (!file) {
return ''; return '';
@ -423,6 +423,100 @@
callback: callback callback: callback
}); });
}, },
restartTask: function (gid, callback, silent) {
var deferred = $q.defer();
var methods = [
aria2RpcService.tellStatus({gid: gid}, true),
aria2RpcService.getOption({gid: gid}, true)
];
var task = null, options = null;
aria2RpcService.multicall({
methods: methods,
silent: !!silent,
callback: function (response) {
if (!callback) {
ariaNgLogService.warn("[aria2TaskService.restartTask] callback is null");
return;
}
if (!response.success) {
ariaNgLogService.warn("[aria2TaskService.restartTask] response is not success");
deferred.reject(response);
callback(response);
return;
}
if (response.data.length > 0) {
task = response.data[0][0];
}
if (response.data.length > 1) {
options = response.data[1][0];
}
if (!task || !options || !task.files || task.files.length != 1 || task.bittorrent) {
if (!task) {
ariaNgLogService.warn("[aria2TaskService.restartTask] task is null");
}
if (!options) {
ariaNgLogService.warn("[aria2TaskService.restartTask] options is null");
}
if (!task.files) {
ariaNgLogService.warn("[aria2TaskService.restartTask] task file is null");
}
if (task.files.length != 1) {
ariaNgLogService.warn("[aria2TaskService.restartTask] task file length is not equal 1");
}
if (task.bittorrent) {
ariaNgLogService.warn("[aria2TaskService.restartTask] task is bittorrent");
}
deferred.reject(gid);
callback({
success: false
});
return;
}
var file = task.files[0];
var urls = [];
for (var i = 0; i < file.uris.length; i++) {
var uriObj = file.uris[i];
urls.push(uriObj.uri);
}
aria2RpcService.addUri({
task: {
urls: urls,
options: options
},
pauseOnAdded: false,
silent: !!silent,
callback: function (response) {
if (!response.success) {
ariaNgLogService.warn("[aria2TaskService.restartTask] addUri response is not success");
deferred.reject(response);
callback(response);
return;
}
deferred.resolve(response);
callback(response);
}
});
}
});
return deferred.promise;
},
removeTasks: function (tasks, callback, silent) { removeTasks: function (tasks, callback, silent) {
var runningTaskGids = []; var runningTaskGids = [];
var stoppedTaskGids = []; var stoppedTaskGids = [];

View file

@ -46,6 +46,7 @@
<a ng-href="#/task/detail/{{task.gid}}"> <a ng-href="#/task/detail/{{task.gid}}">
<span ng-if="task.files" ng-bind="('format.settings.file-count' | translate: {count: task.selectedFileCount})"></span> <span ng-if="task.files" ng-bind="('format.settings.file-count' | translate: {count: task.selectedFileCount})"></span>
</a><i class="icon-error fa fa-times" ng-if="task && task.status == 'error' && task.errorDescription" title="{{task.errorDescription | translate}}"></i><i class="icon-seeder fa fa-arrow-up" ng-if="task && task.status == 'active' && task.seeder" title="{{'Seeding' | translate}}"></i> </a><i class="icon-error fa fa-times" ng-if="task && task.status == 'error' && task.errorDescription" title="{{task.errorDescription | translate}}"></i><i class="icon-seeder fa fa-arrow-up" ng-if="task && task.status == 'active' && task.seeder" title="{{'Seeding' | translate}}"></i>
<a class="pointer-cursor" ng-if="task && task.status == 'error' && task.errorDescription && !task.bittorrent" ng-click="restart(task)" title="{{'Restart' | translate}}" translate>Restart</a>
</div> </div>
</div> </div>
<div class="col-md-2 col-sm-3 col-xs-12"> <div class="col-md-2 col-sm-3 col-xs-12">