diff --git a/src/langs/zh_Hans.txt b/src/langs/zh_Hans.txt index 9be034f..0a62d7c 100644 --- a/src/langs/zh_Hans.txt +++ b/src/langs/zh_Hans.txt @@ -1,4 +1,5 @@ [global] +Operation Result=操作结果 Operation Succeeded=操作成功 {{name}} is connected={{name}} 已连接 Error=错误 @@ -16,6 +17,7 @@ New=新建 Start=开始任务 Pause=暂停任务 Retry=重试 +Retry Selected Tasks=重试选中任务 Delete=删除任务 Select All=全部选中 Select None=全部不选 @@ -113,8 +115,9 @@ No Data=无数据 No connected peers=没有连接到其他节点 Failed to change some tasks state.=修改一些任务状态时失败. Confirm Retry=确认重试 -Are you sure you want to retry this task? AriaNg will create a same task after clicking OK.=您是否要重试这个任务? 点击 "确定" 后, AriaNg 将会创建一个相同的任务. +Are you sure you want to retry the selected task? AriaNg will create same task after clicking OK.=您是否要重试选中的任务? 点击 "确定" 后, AriaNg 将会创建相同的任务. Failed to retry this task.=该任务重试失败. +{{successCount}} tasks have been retried and {{failedCount}} tasks are failed.={{successCount}} 个任务重试成功以及 {{failedCount}} 个任务失败. Confirm Remove=确认删除 Are you sure you want to remove the selected task?=您是否要删除选中的任务? Failed to remove some task(s).=删除一些任务时失败. diff --git a/src/langs/zh_Hant.txt b/src/langs/zh_Hant.txt index 58abbfd..5116eae 100644 --- a/src/langs/zh_Hant.txt +++ b/src/langs/zh_Hant.txt @@ -1,4 +1,5 @@ [global] +Operation Result=操作結果 Operation Succeeded=操作成功 {{name}} is connected={{name}} 已連線 Error=錯誤 @@ -16,6 +17,7 @@ New=新增 Start=開始工作 Pause=暫停工作 Retry=重試 +Retry Selected Tasks=重試選中工作 Delete=刪除工作 Select All=全部選中 Select None=全部不選 @@ -113,8 +115,9 @@ No Data=無資料 No connected peers=沒有連線到其他節點 Failed to change some tasks state.=修改一些工作狀態時失敗. Confirm Retry=確認重試 -Are you sure you want to retry this task? AriaNg will create a same task after clicking OK.=您是否要重試這個工作? 點選 "確定" 後, AriaNg 將會建立一個相同的工作. +Are you sure you want to retry the selected task? AriaNg will create same task after clicking OK.=您是否要重試選中的工作? 點選 "確定" 後, AriaNg 將會建立相同的工作. Failed to retry this task.=該工作重試失敗. +{{successCount}} tasks have been retried and {{failedCount}} tasks are failed.={{successCount}} 个工作重試成功以及 {{failedCount}} 个工作失敗. Confirm Remove=確認刪除 Are you sure you want to remove the selected task?=您是否要刪除選中的工作? Failed to remove some task(s).=刪除一些工作時失敗. diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index b6ee223..241daed 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -3,6 +3,7 @@ angular.module('ariaNg').config(['$translateProvider', 'ariaNgConstants', function ($translateProvider, ariaNgConstants) { var defaultLanguageResource = { + 'Operation Result': 'Operation Result', 'Operation Succeeded': 'Operation Succeeded', '{{name}} is connected': '{{name}} is connected', 'Error': 'Error', @@ -20,6 +21,7 @@ 'Start': 'Start', 'Pause': 'Pause', 'Retry': 'Retry', + 'Retry Selected Tasks': 'Retry Selected Tasks', 'Delete': 'Delete', 'Select All': 'Select All', 'Select None': 'Select None', @@ -117,8 +119,9 @@ 'No connected peers': 'No connected peers', 'Failed to change some tasks state.': 'Failed to change some tasks state.', 'Confirm Retry': 'Confirm Retry', - 'Are you sure you want to retry this task? AriaNg will create a same task after clicking OK.': 'Are you sure you want to retry this task? AriaNg will create a same task after clicking OK.', + 'Are you sure you want to retry the selected task? AriaNg will create same task after clicking OK.': 'Are you sure you want to retry the selected task? AriaNg will create same task after clicking OK.', 'Failed to retry this task.': 'Failed to retry this task.', + '{{successCount}} tasks have been retried and {{failedCount}} tasks are failed.': '{{successCount}} tasks have been retried and {{failedCount}} tasks are failed.', '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).', diff --git a/src/scripts/controllers/main.js b/src/scripts/controllers/main.js index c602e4a..c51748c 100644 --- a/src/scripts/controllers/main.js +++ b/src/scripts/controllers/main.js @@ -139,7 +139,7 @@ }; $scope.retryTask = function (task) { - ariaNgLocalizationService.confirm('Confirm Retry', 'Are you sure you want to retry this task? AriaNg will create a same task after clicking OK.', 'info', function () { + ariaNgLocalizationService.confirm('Confirm Retry', 'Are you sure you want to retry the selected task? AriaNg will create same task after clicking OK.', 'info', function () { $rootScope.loadPromise = aria2TaskService.retryTask(task.gid, function (response) { if (!response.success) { ariaNgLocalizationService.showError('Failed to retry this task.'); @@ -167,6 +167,75 @@ }); }; + $scope.isTaskRetryable = function (task) { + return task && task.status === 'error' && task.errorDescription && !task.bittorrent; + }; + + $scope.isSelectedTaskRetryable = function () { + var selectedTasks = $rootScope.taskContext.getSelectedTasks(); + + if (selectedTasks.length < 1) { + return false; + } + + for (var i = 0; i < selectedTasks.length; i++) { + if (!$scope.isTaskRetryable(selectedTasks[i])) { + return false; + } + } + + return true; + }; + + $scope.retryTasks = function () { + var tasks = $rootScope.taskContext.getSelectedTasks(); + + if (!tasks || tasks.length < 1) { + return; + } else if (tasks.length === 1) { + return $scope.retryTask(tasks[0]); + } + + var retryableTasks = []; + var skipCount = 0; + + for (var i = 0; i < tasks.length; i++) { + if ($scope.isTaskRetryable(tasks[i])) { + retryableTasks.push(tasks[i]); + } else { + skipCount++; + } + } + + ariaNgLocalizationService.confirm('Confirm Retry', 'Are you sure you want to retry the selected task? AriaNg will create same task after clicking OK.', 'info', function () { + $rootScope.loadPromise = aria2TaskService.retryTasks(retryableTasks, function (response) { + refreshGlobalStat(true); + + ariaNgLocalizationService.showInfo('Operation Result', '{{successCount}} tasks have been retried and {{failedCount}} tasks are failed.', function () { + var actionAfterRetryingTask = ariaNgSettingService.getAfterRetryingTask(); + + if (response.hasSuccess) { + if (actionAfterRetryingTask === 'task-list-downloading') { + if ($location.path() !== '/downloading') { + $location.path('/downloading'); + } else { + $route.reload(); + } + } else { + $route.reload(); + } + } + }, { + textParams: { + successCount: response.successCount, + failedCount: response.failedCount, + skipCount: skipCount + } + }); + }, false); + }, true); + }; + $scope.removeTasks = function () { var tasks = $rootScope.taskContext.getSelectedTasks(); diff --git a/src/scripts/services/aria2TaskService.js b/src/scripts/services/aria2TaskService.js index 09bf9df..b264b38 100644 --- a/src/scripts/services/aria2TaskService.js +++ b/src/scripts/services/aria2TaskService.js @@ -720,6 +720,63 @@ return deferred.promise; }, + retryTasks: function (tasks, callback, silent) { + if (!callback) { + ariaNgLogService.warn('[aria2TaskService.retryTasks] callback is null'); + return; + } + + var retryTaskFunc = this.retryTask; + + var deferred = $q.defer(); + var lastPromise = null; + + var successCount = 0; + var failedCount = 0; + + var doRetryFunc = function (task, index) { + return retryTaskFunc(task.gid, function (response) { + ariaNgLogService.debug('[aria2TaskService.retryTasks] task#' + index + ', gid=' + task.gid + ', result=' + response.success, task); + + if (response.success) { + successCount++; + } else { + failedCount++; + } + + if ((successCount + failedCount) === tasks.length) { + var finalResponse = { + successCount: successCount, + failedCount: failedCount, + hasSuccess: successCount > 0, + hasError: failedCount > 0 + }; + + deferred.resolve(finalResponse); + callback(finalResponse); + } + }, silent); + }; + + for (var i = 0; i < tasks.length; i++) { + var task = tasks[i]; + var currentPromise = null; + + if (!lastPromise) { + currentPromise = doRetryFunc(task, i); + } else { + currentPromise = (function (task, index) { + return lastPromise.then(function () { + return doRetryFunc(task, index); + }); + })(task, i); + } + + lastPromise = currentPromise; + } + + return deferred.promise; + }, removeTasks: function (tasks, callback, silent) { var runningTaskGids = []; var stoppedTaskGids = []; diff --git a/src/scripts/services/ariaNgLocalizationService.js b/src/scripts/services/ariaNgLocalizationService.js index a26a472..f5120fb 100644 --- a/src/scripts/services/ariaNgLocalizationService.js +++ b/src/scripts/services/ariaNgLocalizationService.js @@ -15,20 +15,25 @@ getLongDateFormat: function () { return this.getLocalizedText('format.longdate'); }, - showDialog: function (title, text, type, callback) { + showDialog: function (title, text, type, callback, extendSettings) { + if (!extendSettings) { + extendSettings = {}; + } + if (title) { title = this.getLocalizedText(title); } if (text) { - text = this.getLocalizedText(text); + text = this.getLocalizedText(text, extendSettings.textParams); } - var options = { - confirmButtonText: this.getLocalizedText('OK') - }; + extendSettings.confirmButtonText = this.getLocalizedText('OK'); - ariaNgCommonService.showDialog(title, text, type, callback, options); + ariaNgCommonService.showDialog(title, text, type, callback, extendSettings); + }, + showInfo: function (title, text, callback, extendSettings) { + this.showDialog(title, text, 'info', callback, extendSettings); }, showError: function (text, callback) { this.showDialog('Error', text, 'error', callback); diff --git a/src/views/list.html b/src/views/list.html index 29e84b5..630165e 100644 --- a/src/views/list.html +++ b/src/views/list.html @@ -48,7 +48,7 @@ - Retry + Retry
@@ -76,6 +76,13 @@