copy downlaod link and magnet link supports multi tasks

This commit is contained in:
MaysWind 2019-05-25 19:47:52 +08:00
parent 00c9668ece
commit a500500b9a
2 changed files with 47 additions and 17 deletions

View file

@ -69,24 +69,36 @@
return $rootScope.taskContext.getSelectedTaskIds().length > 0;
};
$scope.isSingleUrlTaskSelected = function () {
$scope.isSelectedTasksAllHaveUrl = function () {
var selectedTasks = $rootScope.taskContext.getSelectedTasks();
if (selectedTasks.length !== 1) {
if (selectedTasks.length < 1) {
return false;
}
return !!selectedTasks[0].singleUrl;
for (var i = 0; i < selectedTasks.length; i++) {
if (!selectedTasks[i].singleUrl) {
return false;
}
}
return true;
};
$scope.isSingleBittorrentHasInfoHashTaskSelected = function () {
$scope.isSelectedTasksAllHaveInfoHash = function () {
var selectedTasks = $rootScope.taskContext.getSelectedTasks();
if (selectedTasks.length !== 1) {
if (selectedTasks.length < 1) {
return false;
}
return !!selectedTasks[0].bittorrent && !!selectedTasks[0].infoHash;
for (var i = 0; i < selectedTasks.length; i++) {
if (!selectedTasks[i].bittorrent || !selectedTasks[i].infoHash) {
return false;
}
}
return true;
};
$scope.isSpecifiedTaskSelected = function () {
@ -335,19 +347,37 @@
$rootScope.taskContext.selectAllCompleted();
};
$scope.copySelectedOneTaskDownloadLink = function () {
$scope.copySelectedTasksDownloadLink = function () {
var selectedTasks = $rootScope.taskContext.getSelectedTasks();
var result = '';
if (selectedTasks.length === 1) {
clipboard.copyText(selectedTasks[0].singleUrl);
for (var i = 0; i < selectedTasks.length; i++) {
if (i > 0) {
result += '\n';
}
result += selectedTasks[i].singleUrl;
}
if (result.length > 0) {
clipboard.copyText(result);
}
};
$scope.copySelectedOneTaskMagnetLink = function () {
$scope.copySelectedTasksMagnetLink = function () {
var selectedTasks = $rootScope.taskContext.getSelectedTasks();
var result = '';
if (selectedTasks.length === 1) {
clipboard.copyText('magnet:?xt=urn:btih:' + selectedTasks[0].infoHash);
for (var i = 0; i < selectedTasks.length; i++) {
if (i > 0) {
result += '\n';
}
result += 'magnet:?xt=urn:btih:' + selectedTasks[i].infoHash;
}
if (result.length > 0) {
clipboard.copyText(result);
}
};

View file

@ -176,15 +176,15 @@
<span translate>Select All</span>
</a>
</li>
<li class="divider" ng-if="isSingleUrlTaskSelected() || isSingleBittorrentHasInfoHashTaskSelected()"></li>
<li ng-if="isSingleUrlTaskSelected()">
<a tabindex="-1" class="pointer-cursor" title="{{'Copy Download Url' | translate}}" ng-click="copySelectedOneTaskDownloadLink()">
<li class="divider" ng-if="isSelectedTasksAllHaveUrl() || isSelectedTasksAllHaveInfoHash()"></li>
<li ng-if="isSelectedTasksAllHaveUrl()">
<a tabindex="-1" class="pointer-cursor" title="{{'Copy Download Url' | translate}}" ng-click="copySelectedTasksDownloadLink()">
<i class="fa fa-copy fa-fw"></i>
<span translate>Copy Download Url</span>
</a>
</li>
<li ng-if="isSingleBittorrentHasInfoHashTaskSelected()">
<a tabindex="-1" class="pointer-cursor" title="{{'Copy Magnet Link' | translate}}" ng-click="copySelectedOneTaskMagnetLink()">
<li ng-if="isSelectedTasksAllHaveInfoHash()">
<a tabindex="-1" class="pointer-cursor" title="{{'Copy Magnet Link' | translate}}" ng-click="copySelectedTasksMagnetLink()">
<i class="fa fa-copy fa-fw"></i>
<span translate>Copy Magnet Link</span>
</a>