support remove task and clear stopped tasks
This commit is contained in:
parent
d673e0696f
commit
53a4fc0403
|
@ -55,7 +55,7 @@
|
||||||
<i class="fa fa-pause"></i>
|
<i class="fa fa-pause"></i>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="disabled" ng-class="{'disabled': !taskContext.list || taskContext.list.length < 1}">
|
<li class="disabled" ng-class="{'disabled': !isTaskSelected() && !isSpecifiedTaskShowing('complete', 'error', 'removed')}">
|
||||||
<a class="toolbar dropdown-toggle" data-toggle="dropdown" title="{{'Delete' | translate}}">
|
<a class="toolbar dropdown-toggle" data-toggle="dropdown" title="{{'Delete' | translate}}">
|
||||||
<i class="fa fa-trash-o"></i>
|
<i class="fa fa-trash-o"></i>
|
||||||
<i class="fa fa-caret-right fa-right-bottom fa-rotate-45 fa-half" aria-hidden="true"></i>
|
<i class="fa fa-caret-right fa-right-bottom fa-rotate-45 fa-half" aria-hidden="true"></i>
|
||||||
|
@ -66,9 +66,9 @@
|
||||||
<span translate>Remove Task</span>
|
<span translate>Remove Task</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li ng-if="isSpecifiedTaskShowing('complete', 'error', 'removed')">
|
||||||
<a class="pointer-cursor" ng-click="clearFinishedTasks()">
|
<a class="pointer-cursor" ng-click="clearStoppedTasks()">
|
||||||
<span translate>Clear Finished Tasks</span>
|
<span translate>Clear Stopped Tasks</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
"Search": "搜索",
|
"Search": "搜索",
|
||||||
"Default": "默认",
|
"Default": "默认",
|
||||||
"Remove Task": "删除任务",
|
"Remove Task": "删除任务",
|
||||||
"Clear Finished Tasks": "清空已完成任务",
|
"Clear Stopped Tasks": "清空已结束任务",
|
||||||
"By File Name": "按文件名",
|
"By File Name": "按文件名",
|
||||||
"By File Size": "按文件大小",
|
"By File Size": "按文件大小",
|
||||||
"By Completed Percent": "按进度",
|
"By Completed Percent": "按进度",
|
||||||
|
@ -69,7 +69,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 stopped tasks?": "您是否要清除已结束的任务?",
|
||||||
"Language": "语言",
|
"Language": "语言",
|
||||||
"Aria2 RPC Host": "Aria2 RPC 主机",
|
"Aria2 RPC Host": "Aria2 RPC 主机",
|
||||||
"Aria2 RPC Port": "Aria2 RPC 端口",
|
"Aria2 RPC Port": "Aria2 RPC 端口",
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
'Search': 'Search',
|
'Search': 'Search',
|
||||||
'Default': 'Default',
|
'Default': 'Default',
|
||||||
'Remove Task': 'Remove Task',
|
'Remove Task': 'Remove Task',
|
||||||
'Clear Finished Tasks': 'Clear Finished Tasks',
|
'Clear Stopped Tasks': 'Clear Stopped Tasks',
|
||||||
'By File Name': 'By File Name',
|
'By File Name': 'By File Name',
|
||||||
'By File Size': 'By File Size',
|
'By File Size': 'By File Size',
|
||||||
'By Completed Percent': 'By Completed Percent',
|
'By Completed Percent': 'By Completed Percent',
|
||||||
|
@ -73,7 +73,7 @@
|
||||||
'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?',
|
||||||
'Confirm Clear': 'Confirm Clear',
|
'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',
|
'Language': 'Language',
|
||||||
'Aria2 RPC Host': 'Aria2 RPC Host',
|
'Aria2 RPC Host': 'Aria2 RPC Host',
|
||||||
'Aria2 RPC Port': 'Aria2 RPC Port',
|
'Aria2 RPC Port': 'Aria2 RPC Port',
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'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 globalStatRefreshPromise = null;
|
||||||
|
|
||||||
var refreshGlobalStat = function (silent) {
|
var refreshGlobalStat = function (silent) {
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
return $rootScope.taskContext.getSelectedTaskIds().length > 0;
|
return $rootScope.taskContext.getSelectedTaskIds().length > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.isSpecifiedTaskSelected = function (status) {
|
$scope.isSpecifiedTaskSelected = function () {
|
||||||
var selectedTasks = $rootScope.taskContext.getSelectedTasks();
|
var selectedTasks = $rootScope.taskContext.getSelectedTasks();
|
||||||
|
|
||||||
if (selectedTasks.length < 1) {
|
if (selectedTasks.length < 1) {
|
||||||
|
@ -22,10 +22,30 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < selectedTasks.length; i++) {
|
for (var i = 0; i < selectedTasks.length; i++) {
|
||||||
if (selectedTasks[i].status == status) {
|
for (var j = 0; j < arguments.length; j++) {
|
||||||
|
if (selectedTasks[i].status == arguments[j]) {
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -53,20 +73,24 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.removeTasks = function () {
|
$scope.removeTasks = function () {
|
||||||
var gids = $rootScope.taskContext.getSelectedTaskIds();
|
var tasks = $rootScope.taskContext.getSelectedTasks();
|
||||||
|
|
||||||
if (!gids || gids.length < 1) {
|
if (!tasks || tasks.length < 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ariaNgCommonService.confirm('Confirm Remove', 'Are you sure you want to remove the selected task?', 'warning', function () {
|
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 () {
|
$scope.clearStoppedTasks = function () {
|
||||||
ariaNgCommonService.confirm('Confirm Clear', 'Are you sure you want to clear finished tasks?', 'warning', 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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.callback) {
|
if (context.callback) {
|
||||||
context.callback(data.result);
|
context.callback(data.error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,18 +47,17 @@
|
||||||
|
|
||||||
var invokeMulti = function (methodFunc, contexts, keyProperty, callback) {
|
var invokeMulti = function (methodFunc, contexts, keyProperty, callback) {
|
||||||
var promises = [];
|
var promises = [];
|
||||||
var results = {};
|
var results = [];
|
||||||
|
|
||||||
for (var i = 0; i < contexts.length; i++) {
|
for (var i = 0; i < contexts.length; i++) {
|
||||||
contexts[i].callback = function (result) {
|
contexts[i].callback = function (result) {
|
||||||
var key = this[keyProperty];
|
results.push(result);
|
||||||
results[key] = result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
promises.push(methodFunc(contexts[i]));
|
promises.push(methodFunc(contexts[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $q.all(promises).then(function () {
|
return $q.all(promises).finally(function () {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(results);
|
callback(results);
|
||||||
}
|
}
|
||||||
|
@ -241,6 +240,17 @@
|
||||||
removeDownloadResult: function (context) {
|
removeDownloadResult: function (context) {
|
||||||
return invoke('removeDownloadResult', buildRequestContext(context, context.gid));
|
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) {
|
getVersion: function (context) {
|
||||||
return invoke('getVersion', buildRequestContext(context));
|
return invoke('getVersion', buildRequestContext(context));
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'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) {
|
var getFileNameFromPath = function (path) {
|
||||||
if (!path) {
|
if (!path) {
|
||||||
return path;
|
return path;
|
||||||
|
@ -182,6 +182,48 @@
|
||||||
callback: callback
|
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) {
|
changeTaskPosition: function (gid, position, callback) {
|
||||||
return aria2RpcService.changePosition({
|
return aria2RpcService.changePosition({
|
||||||
gid: gid,
|
gid: gid,
|
||||||
|
@ -190,6 +232,11 @@
|
||||||
callback: callback
|
callback: callback
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
clearStoppedTasks: function (callback) {
|
||||||
|
return aria2RpcService.purgeDownloadResult({
|
||||||
|
callback: callback
|
||||||
|
});
|
||||||
|
},
|
||||||
processDownloadTasks: function (tasks) {
|
processDownloadTasks: function (tasks) {
|
||||||
if (!angular.isArray(tasks)) {
|
if (!angular.isArray(tasks)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var uniqueId = content.id;
|
var uniqueId = content.id;
|
||||||
var result = content.result;
|
|
||||||
|
|
||||||
if (!sendIdStates[uniqueId]) {
|
if (!sendIdStates[uniqueId]) {
|
||||||
return;
|
return;
|
||||||
|
@ -43,7 +42,11 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
if (callbackMethod) {
|
if (callbackMethod) {
|
||||||
callbackMethod(result);
|
if (content.result) {
|
||||||
|
callbackMethod(content.result);
|
||||||
|
} else if (content.error) {
|
||||||
|
callbackMethod(content.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete sendIdStates[uniqueId];
|
delete sendIdStates[uniqueId];
|
||||||
|
|
Reference in a new issue