From e117d83e93f8f711b17736048daa2477b146c239 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Tue, 23 Apr 2019 00:15:17 +0800 Subject: [PATCH] support selecting all completed tasks --- src/langs/zh_Hans.txt | 1 + src/langs/zh_Hant.txt | 1 + src/scripts/config/defaultLanguage.js | 1 + src/scripts/controllers/main.js | 8 ++++ src/scripts/core/root.js | 57 +++++++++++++++++++++++++++ src/views/list.html | 6 +++ 6 files changed, 74 insertions(+) diff --git a/src/langs/zh_Hans.txt b/src/langs/zh_Hans.txt index c8ec178..6096537 100644 --- a/src/langs/zh_Hans.txt +++ b/src/langs/zh_Hans.txt @@ -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=复制磁力链接 diff --git a/src/langs/zh_Hant.txt b/src/langs/zh_Hant.txt index 64ef76c..b61e740 100644 --- a/src/langs/zh_Hant.txt +++ b/src/langs/zh_Hant.txt @@ -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=複製磁力連結 diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index fc7bd7d..298bd62 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -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', diff --git a/src/scripts/controllers/main.js b/src/scripts/controllers/main.js index 2824e07..cd4973f 100644 --- a/src/scripts/controllers/main.js +++ b/src/scripts/controllers/main.js @@ -202,6 +202,10 @@ return $rootScope.taskContext.hasRetryableTask(); }; + $scope.hasCompletedTask = function () { + return $rootScope.taskContext.hasCompletedTask(); + }; + $scope.isSelectedTaskRetryable = function () { var selectedTasks = $rootScope.taskContext.getSelectedTasks(); @@ -327,6 +331,10 @@ $rootScope.taskContext.selectAllFailed(); }; + $scope.selectAllCompletedTasks = function () { + $rootScope.taskContext.selectAllCompleted(); + }; + $scope.copySelectedOneTaskDownloadLink = function () { var selectedTasks = $rootScope.taskContext.getSelectedTasks(); diff --git a/src/scripts/core/root.js b/src/scripts/core/root.js index ac1bcda..6db1c19 100644 --- a/src/scripts/core/root.js +++ b/src/scripts/core/root.js @@ -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; @@ -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; } } diff --git a/src/views/list.html b/src/views/list.html index fcdcff7..6a97438 100644 --- a/src/views/list.html +++ b/src/views/list.html @@ -164,6 +164,12 @@ Select All Failed Task +
  • + + + Select All Completed Tasks + +