Skip to content

Commit

Permalink
support selecting all completed tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Apr 22, 2019
1 parent b066fc2 commit e117d83
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/langs/zh_Hans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Select All=全部选中
Select None=全部不选
Select Invert=反向选择
Select All Failed Task=全选失败任务
Select All Completed Tasks=全选已完成任务
Display Order=显示顺序
Copy Download Url=复制下载链接
Copy Magnet Link=复制磁力链接
Expand Down
1 change: 1 addition & 0 deletions src/langs/zh_Hant.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Select All=全部選中
Select None=全部不選
Select Invert=反向選擇
Select All Failed Task=全選失敗工作
Select All Completed Tasks=全選已完成工作
Display Order=顯示順序
Copy Download Url=複製下載連結
Copy Magnet Link=複製磁力連結
Expand Down
1 change: 1 addition & 0 deletions src/scripts/config/defaultLanguage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'Select None': 'Select None',
'Select Invert': 'Select Invert',
'Select All Failed Task': 'Select All Failed Task',
'Select All Completed Tasks': 'Select All Completed Tasks',
'Display Order': 'Display Order',
'Copy Download Url': 'Copy Download Url',
'Copy Magnet Link': 'Copy Magnet Link',
Expand Down
8 changes: 8 additions & 0 deletions src/scripts/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@
return $rootScope.taskContext.hasRetryableTask();
};

$scope.hasCompletedTask = function () {
return $rootScope.taskContext.hasCompletedTask();
};

$scope.isSelectedTaskRetryable = function () {
var selectedTasks = $rootScope.taskContext.getSelectedTasks();

Expand Down Expand Up @@ -327,6 +331,10 @@
$rootScope.taskContext.selectAllFailed();
};

$scope.selectAllCompletedTasks = function () {
$rootScope.taskContext.selectAllCompleted();
};

$scope.copySelectedOneTaskDownloadLink = function () {
var selectedTasks = $rootScope.taskContext.getSelectedTasks();

Expand Down
57 changes: 57 additions & 0 deletions src/scripts/core/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@

return false;
},
hasCompletedTask: function () {
for (var i = 0; i < this.list.length; i++) {
var task = this.list[i];

if (!$rootScope.filterTask(task)) {
continue;
}

if (task.status === 'complete') {
return true;
}
}

return false;
},
selectAll: function () {
if (!this.list || !this.selected || this.list.length < 1) {
return;
Expand Down Expand Up @@ -226,6 +241,48 @@
continue;
}

this.selected[task.gid] = !isAllFailedSelected;
}
},
selectAllCompleted: function () {
if (!this.list || !this.selected || this.list.length < 1) {
return;
}

if (!this.enableSelectAll) {
return;
}

var isAllFailedSelected = true;

for (var i = 0; i < this.list.length; i++) {
var task = this.list[i];

if (!$rootScope.filterTask(task)) {
continue;
}

if (task.status !== 'complete') {
continue;
}

if (!this.selected[task.gid]) {
isAllFailedSelected = false;
}
}

for (var i = 0; i < this.list.length; i++) {
var task = this.list[i];

if (!$rootScope.filterTask(task)) {
continue;
}

if (task.status !== 'complete') {
this.selected[task.gid] = false;
continue;
}

this.selected[task.gid] = !isAllFailedSelected;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/views/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@
<span translate>Select All Failed Task</span>
</a>
</li>
<li ng-if="hasCompletedTask()">
<a tabindex="-1" class="pointer-cursor" title="{{'Select All Completed Tasks' | translate}}" ng-click="selectAllCompletedTasks()">
<i class="fa fa-fw"></i>
<span translate>Select All Completed Tasks</span>
</a>
</li>
<li>
<a tabindex="-1" class="pointer-cursor" title="{{'Select All' | translate}}" ng-click="selectAllTasks()">
<i class="fa fa-th-large fa-fw"></i>
Expand Down

0 comments on commit e117d83

Please sign in to comment.