diff --git a/src/langs/zh_CN.json b/src/langs/zh_CN.json index 6b2c70d..6013eef 100644 --- a/src/langs/zh_CN.json +++ b/src/langs/zh_CN.json @@ -3,12 +3,15 @@ "Operation Succeeded": "操作成功", "Error": "错误", "OK": "确定", + "Confirm": "确认", "Cancel": "取消", "New": "新建", "Start": "开始下载任务", "Pause": "暂停下载任务", "Delete": "删除下载任务", "Select All": "全选", + "Select None": "不选", + "Select Invert": "反选", "Display Order": "显示顺序", "Search": "搜索", "Default": "默认", @@ -64,6 +67,13 @@ "Connections": "连接数", "Seed Creation Time": "种子创建时间", "Download Dir": "下载路径", + "(Choose Files)": "(选择文件)", + "Videos": "视频", + "Audios": "音频", + "Pictures": "图片", + "Documents": "文档", + "Applications": "应用程序", + "Archives": "存档文件", "Address": "地址", "Status": "状态", "Percent": "完成度", diff --git a/src/scripts/config/constants.js b/src/scripts/config/constants.js index 2887565..c38927c 100644 --- a/src/scripts/config/constants.js +++ b/src/scripts/config/constants.js @@ -9,6 +9,103 @@ taskStatStorageCapacity: 300, lazySaveTimeout: 500, errorTooltipDelay: 200 + }).constant('ariaNgFileTypes', { + video: [ + '.3gp', + '.3gpp', + '.asf', + '.asx', + '.avi', + '.dat', + '.flv', + '.m4v', + '.mkv', + '.mov', + '.mp4', + '.mpe', + '.mpeg', + '.mpg', + '.rm', + '.rmvb', + '.vob', + '.wmv' + ], + audio: [ + '.aac', + '.amr', + '.ape', + '.flac', + '.m4a', + '.mid', + '.mp3', + '.ogg', + '.ra', + '.vqf', + '.wav', + '.wma' + ], + picture: [ + '.bmp', + '.emf', + '.gif', + '.jp2', + '.jpeg', + '.jpg', + '.png', + '.psd', + '.raw', + '.tga', + '.tif', + '.tiff', + '.wmf' + ], + document: [ + '.doc', + '.docx', + '.key', + '.numbers', + '.odp', + '.ods', + '.odt', + '.pages', + '.pdf', + '.ppt', + '.pptx', + '.rtf', + '.txt', + '.vsd', + '.vsdx', + '.wps', + '.xls', + '.xlsx' + ], + application: [ + '.apk', + '.bat', + '.com', + '.deb', + '.dll', + '.dmg', + '.exe', + '.ipa', + '.jar', + '.rpm', + '.sh' + ], + archive: [ + '.7z', + '.arj', + '.bz2', + '.cab', + '.gz', + '.iso', + '.r', + '.rar', + '.tar', + '.tar', + '.z', + '.zip' + ] }).constant('ariaNgDefaultOptions', { language: 'en', rpcHost: '', diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index 2f93681..a115e00 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -7,12 +7,15 @@ 'Operation Succeeded': 'Operation Succeeded', 'Error': 'Error', 'OK': 'OK', + 'Confirm': 'Confirm', 'Cancel': 'Cancel', 'New': 'New', 'Start': 'Start', 'Pause': 'Pause', 'Delete': 'Delete', 'Select All': 'Select All', + 'Select None': 'Select None', + 'Select Invert': 'Select Invert', 'Display Order': 'Display Order', 'Search': 'Search', 'Default': 'Default', @@ -68,6 +71,13 @@ 'Connections': 'Connections', 'Seed Creation Time': 'Seed Creation Time', 'Download Dir': 'Download Dir', + '(Choose Files)': '(Choose Files)', + 'Videos': 'Videos', + 'Audios': 'Audios', + 'Pictures': 'Pictures', + 'Documents': 'Documents', + 'Applications': 'Applications', + 'Archives': 'Archives', 'Address': 'Address', 'Status': 'Status', 'Percent': 'Percent', diff --git a/src/scripts/controllers/task-detail.js b/src/scripts/controllers/task-detail.js index f677fd5..f5ea8d9 100644 --- a/src/scripts/controllers/task-detail.js +++ b/src/scripts/controllers/task-detail.js @@ -1,7 +1,7 @@ (function () { 'use strict'; - angular.module('ariaNg').controller('TaskDetailController', ['$rootScope', '$scope', '$routeParams', '$interval', 'aria2RpcErrors', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgMonitorService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $routeParams, $interval, aria2RpcErrors, ariaNgCommonService, ariaNgSettingService, ariaNgMonitorService, aria2TaskService, aria2SettingService) { + angular.module('ariaNg').controller('TaskDetailController', ['$rootScope', '$scope', '$routeParams', '$interval', 'aria2RpcErrors', 'ariaNgFileTypes', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgMonitorService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $routeParams, $interval, aria2RpcErrors, ariaNgFileTypes, ariaNgCommonService, ariaNgSettingService, ariaNgMonitorService, aria2TaskService, aria2SettingService) { var tabOrders = ['overview', 'blocks', 'filelist', 'btpeers']; var downloadTaskRefreshPromise = null; var pauseDownloadTaskRefresh = false; @@ -74,8 +74,36 @@ }, silent); }; + var setSelectFiles = function (silent) { + if (!$scope.task || !$scope.task.files) { + return; + } + + var gid = $scope.task.gid; + var selectedFileIndex = []; + + for (var i = 0; i < $scope.task.files.length; i++) { + var file = $scope.task.files[i]; + + if (file && file.selected) { + selectedFileIndex.push(file.index); + } + } + + pauseDownloadTaskRefresh = true; + + return aria2TaskService.selectTaskFile(gid, selectedFileIndex, function (response) { + pauseDownloadTaskRefresh = false; + + if (response.success) { + refreshDownloadTask(false); + } + }, silent); + }; + $scope.context = { currentTab: 'overview', + showChooseFilesToolbar: false, btPeers: [], healthPercent: 0, statusData: ariaNgMonitorService.getEmptyStatsData($routeParams.gid), @@ -135,31 +163,83 @@ return ariaNgSettingService.getFileListDisplayOrder(); }; - $scope.setSelectedFile = function () { + $scope.showChooseFilesToolbar = function () { + pauseDownloadTaskRefresh = true; + $scope.context.showChooseFilesToolbar = true; + }; + + $scope.getSelectedFileCount = function () { + var count = 0; + + for (var i = 0; i < $scope.task.files.length; i++) { + count += $scope.task.files[i].selected ? 1 : 0; + } + + return count; + }; + + $scope.selectFiles = function (type) { if (!$scope.task || !$scope.task.files) { return; } - var gid = $scope.task.gid; - var selectedFileIndex = []; + for (var i = 0; i < $scope.task.files.length; i++) { + if (type == 'all') { + $scope.task.files[i].selected = true; + } else if (type == 'none') { + $scope.task.files[i].selected = false; + } else if (type == 'reverse') { + $scope.task.files[i].selected = !$scope.task.files[i].selected; + } + } + }; + + $scope.chooseSpecifiedFiles = function (type) { + if (!$scope.task || !$scope.task.files || !ariaNgFileTypes[type]) { + return; + } + + var extensions = ariaNgFileTypes[type]; + var fileIndexes = []; + var isAllSelected = true; for (var i = 0; i < $scope.task.files.length; i++) { - var file = $scope.task.files[i]; + var extension = ariaNgCommonService.getFileExtension($scope.task.files[i].fileName); - if (file && file.selected) { - selectedFileIndex.push(file.index); + if (extensions.indexOf(extension) >= 0) { + fileIndexes.push(i); + + if (!$scope.task.files[i].selected) { + isAllSelected = false; + } } } - pauseDownloadTaskRefresh = true; + for (var i = 0; i < fileIndexes.length; i++) { + var index = fileIndexes[i]; + $scope.task.files[index].selected = !isAllSelected; + } + }; - return aria2TaskService.selectTaskFile(gid, selectedFileIndex, function (response) { + $scope.saveChoosedFiles = function () { + if ($scope.context.showChooseFilesToolbar) { + $rootScope.loadPromise = setSelectFiles(false); + $scope.context.showChooseFilesToolbar = false; + } + }; + + $scope.cancelChooseFiles = function () { + if ($scope.context.showChooseFilesToolbar) { pauseDownloadTaskRefresh = false; + refreshDownloadTask(true); + $scope.context.showChooseFilesToolbar = false; + } + }; - if (response.success) { - refreshDownloadTask(false); - } - }, true); + $scope.setSelectedFile = function () { + if (!$scope.context.showChooseFilesToolbar) { + setSelectFiles(true); + } }; $scope.changePeerListDisplayOrder = function (type, autoSetReverse) { diff --git a/src/scripts/services/ariaNgCommonService.js b/src/scripts/services/ariaNgCommonService.js index 60999e4..f550dbc 100644 --- a/src/scripts/services/ariaNgCommonService.js +++ b/src/scripts/services/ariaNgCommonService.js @@ -51,6 +51,13 @@ } }); }, + getFileExtension: function (filePath) { + if (!filePath || filePath.lastIndexOf('.') < 0) { + return filePath; + } + + return filePath.substring(filePath.lastIndexOf('.')); + }, extendArray: function (sourceArray, targetArray, keyProperty) { if (!targetArray || !sourceArray || sourceArray.length != targetArray.length) { return false; diff --git a/src/views/task-detail.html b/src/views/task-detail.html index def6963..52673c7 100644 --- a/src/views/task-detail.html +++ b/src/views/task-detail.html @@ -157,6 +157,7 @@
File Name + (Choose Files)
Completed Percent @@ -168,6 +169,41 @@
+
+
+
+ + + + + + + + + + + +
+
+