diff --git a/app/index.html b/app/index.html index 3beb1b9..4817db4 100644 --- a/app/index.html +++ b/app/index.html @@ -55,7 +55,7 @@ -
  • +
  • @@ -66,9 +66,9 @@ Remove Task
  • -
  • - - Clear Finished Tasks +
  • + + Clear Stopped Tasks
  • diff --git a/app/langs/zh-CN.json b/app/langs/zh-CN.json index 51111d8..3eac07f 100644 --- a/app/langs/zh-CN.json +++ b/app/langs/zh-CN.json @@ -16,7 +16,7 @@ "Search": "搜索", "Default": "默认", "Remove Task": "删除任务", - "Clear Finished Tasks": "清空已完成任务", + "Clear Stopped Tasks": "清空已结束任务", "By File Name": "按文件名", "By File Size": "按文件大小", "By Completed Percent": "按进度", @@ -69,7 +69,7 @@ "Confirm Remove": "确认删除", "Are you sure you want to remove the selected task?": "您是否要删除选中的任务?", "Confirm Clear": "确认清除", - "Are you sure you want to clear finished tasks?": "您是否要清除已完成的任务?", + "Are you sure you want to clear stopped tasks?": "您是否要清除已结束的任务?", "Language": "语言", "Aria2 RPC Host": "Aria2 RPC 主机", "Aria2 RPC Port": "Aria2 RPC 端口", diff --git a/app/scripts/config/language-default.js b/app/scripts/config/language-default.js index 3d566f0..a75b335 100644 --- a/app/scripts/config/language-default.js +++ b/app/scripts/config/language-default.js @@ -20,7 +20,7 @@ 'Search': 'Search', 'Default': 'Default', 'Remove Task': 'Remove Task', - 'Clear Finished Tasks': 'Clear Finished Tasks', + 'Clear Stopped Tasks': 'Clear Stopped Tasks', 'By File Name': 'By File Name', 'By File Size': 'By File Size', 'By Completed Percent': 'By Completed Percent', @@ -73,7 +73,7 @@ 'Confirm Remove': 'Confirm Remove', 'Are you sure you want to remove the selected task?': 'Are you sure you want to remove the selected task?', 'Confirm Clear': 'Confirm Clear', - 'Are you sure you want to clear finished tasks?': 'Are you sure you want to clear finished tasks?', + 'Are you sure you want to clear stopped tasks?': 'Are you sure you want to clear stopped tasks?', 'Language': 'Language', 'Aria2 RPC Host': 'Aria2 RPC Host', 'Aria2 RPC Port': 'Aria2 RPC Port', diff --git a/app/scripts/controllers/main.js b/app/scripts/controllers/main.js index c82b655..5dc8cb9 100644 --- a/app/scripts/controllers/main.js +++ b/app/scripts/controllers/main.js @@ -1,7 +1,7 @@ (function () { 'use strict'; - angular.module('ariaNg').controller('MainController', ['$rootScope', '$scope', '$route', '$interval', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $route, $interval, ariaNgCommonService, ariaNgSettingService, aria2TaskService, aria2SettingService) { + angular.module('ariaNg').controller('MainController', ['$rootScope', '$scope', '$route', '$location', '$interval', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $route, $location, $interval, ariaNgCommonService, ariaNgSettingService, aria2TaskService, aria2SettingService) { var globalStatRefreshPromise = null; var refreshGlobalStat = function (silent) { @@ -14,7 +14,7 @@ return $rootScope.taskContext.getSelectedTaskIds().length > 0; }; - $scope.isSpecifiedTaskSelected = function (status) { + $scope.isSpecifiedTaskSelected = function () { var selectedTasks = $rootScope.taskContext.getSelectedTasks(); if (selectedTasks.length < 1) { @@ -22,8 +22,28 @@ } for (var i = 0; i < selectedTasks.length; i++) { - if (selectedTasks[i].status == status) { - return true; + for (var j = 0; j < arguments.length; j++) { + if (selectedTasks[i].status == arguments[j]) { + return true; + } + } + } + + return false; + }; + + $scope.isSpecifiedTaskShowing = function () { + var tasks = $rootScope.taskContext.list; + + if (tasks.length < 1) { + return false; + } + + for (var i = 0; i < tasks.length; i++) { + for (var j = 0; j < arguments.length; j++) { + if (tasks[i].status == arguments[j]) { + return true; + } } } @@ -53,20 +73,24 @@ }; $scope.removeTasks = function () { - var gids = $rootScope.taskContext.getSelectedTaskIds(); + var tasks = $rootScope.taskContext.getSelectedTasks(); - if (!gids || gids.length < 1) { + if (!tasks || tasks.length < 1) { return; } ariaNgCommonService.confirm('Confirm Remove', 'Are you sure you want to remove the selected task?', 'warning', function () { - + $rootScope.loadPromise = aria2TaskService.removeTasks(tasks, function (result) { + $location.path('/stopped'); + }); }); }; - $scope.clearFinishedTasks = function () { - ariaNgCommonService.confirm('Confirm Clear', 'Are you sure you want to clear finished tasks?', 'warning', function () { - + $scope.clearStoppedTasks = function () { + ariaNgCommonService.confirm('Confirm Clear', 'Are you sure you want to clear stopped tasks?', 'warning', function () { + $rootScope.loadPromise = aria2TaskService.clearStoppedTasks(function (result) { + $location.path('/stopped'); + }); }); }; diff --git a/app/scripts/services/aria2HttpRpcService.js b/app/scripts/services/aria2HttpRpcService.js index 139991d..e4e235f 100644 --- a/app/scripts/services/aria2HttpRpcService.js +++ b/app/scripts/services/aria2HttpRpcService.js @@ -30,7 +30,7 @@ } if (context.callback) { - context.callback(data.result); + context.callback(data.error); } }); } diff --git a/app/scripts/services/aria2RpcService.js b/app/scripts/services/aria2RpcService.js index 8b44a93..c0a629a 100644 --- a/app/scripts/services/aria2RpcService.js +++ b/app/scripts/services/aria2RpcService.js @@ -47,18 +47,17 @@ var invokeMulti = function (methodFunc, contexts, keyProperty, callback) { var promises = []; - var results = {}; + var results = []; for (var i = 0; i < contexts.length; i++) { contexts[i].callback = function (result) { - var key = this[keyProperty]; - results[key] = result; + results.push(result); }; promises.push(methodFunc(contexts[i])); } - return $q.all(promises).then(function () { + return $q.all(promises).finally(function () { if (callback) { callback(results); } @@ -241,6 +240,17 @@ removeDownloadResult: function (context) { return invoke('removeDownloadResult', buildRequestContext(context, context.gid)); }, + removeDownloadResultMulti: function (context) { + var contexts = []; + + for (var i = 0; i < context.gids.length; i++) { + contexts.push({ + gid: context.gids[i] + }); + } + + return invokeMulti(this.removeDownloadResult, contexts, 'gid', context.callback); + }, getVersion: function (context) { return invoke('getVersion', buildRequestContext(context)); }, diff --git a/app/scripts/services/aria2TaskService.js b/app/scripts/services/aria2TaskService.js index bf72e0c..741426d 100644 --- a/app/scripts/services/aria2TaskService.js +++ b/app/scripts/services/aria2TaskService.js @@ -1,7 +1,7 @@ (function () { 'use strict'; - angular.module('ariaNg').factory('aria2TaskService', ['$translate', 'aria2RpcService', function ($translate, aria2RpcService) { + angular.module('ariaNg').factory('aria2TaskService', ['$q', '$translate', 'aria2RpcService', function ($q, $translate, aria2RpcService) { var getFileNameFromPath = function (path) { if (!path) { return path; @@ -182,6 +182,48 @@ callback: callback }); }, + removeTasks: function (tasks, callback) { + var runningTaskGids = []; + var stoppedTaskGids = []; + + for (var i = 0; i < tasks.length; i++) { + if (tasks[i].status == 'complete' || tasks[i].status == 'error' || tasks[i].status == 'removed') { + stoppedTaskGids.push(tasks[i].gid); + } else { + runningTaskGids.push(tasks[i].gid); + } + } + + var promises = []; + var results = { + runningResult: null, + stoppedResult: null + }; + + if (runningTaskGids.length > 0) { + promises.push(aria2RpcService.forceRemoveMulti({ + gids: runningTaskGids, + callback: function (result) { + results.runningResult = result; + } + })); + } + + if (stoppedTaskGids.length > 0) { + promises.push(aria2RpcService.removeDownloadResultMulti({ + gids: stoppedTaskGids, + callback: function (result) { + results.stoppedResult = result; + } + })); + } + + return $q.all(promises).then(function () { + if (callback) { + callback(results); + } + }); + }, changeTaskPosition: function (gid, position, callback) { return aria2RpcService.changePosition({ gid: gid, @@ -190,6 +232,11 @@ callback: callback }) }, + clearStoppedTasks: function (callback) { + return aria2RpcService.purgeDownloadResult({ + callback: callback + }); + }, processDownloadTasks: function (tasks) { if (!angular.isArray(tasks)) { return; diff --git a/app/scripts/services/aria2WebSocketRpcService.js b/app/scripts/services/aria2WebSocketRpcService.js index b1eb3ec..a3a1ae2 100644 --- a/app/scripts/services/aria2WebSocketRpcService.js +++ b/app/scripts/services/aria2WebSocketRpcService.js @@ -22,7 +22,6 @@ } var uniqueId = content.id; - var result = content.result; if (!sendIdStates[uniqueId]) { return; @@ -43,7 +42,11 @@ }); if (callbackMethod) { - callbackMethod(result); + if (content.result) { + callbackMethod(content.result); + } else if (content.error) { + callbackMethod(content.error); + } } delete sendIdStates[uniqueId];