support select files by file extension

This commit is contained in:
MaysWind 2018-11-11 20:27:32 +08:00
parent c21c77ff99
commit e42884a50f
6 changed files with 390 additions and 190 deletions

View file

@ -5,6 +5,7 @@ Error=错误
OK=确定 OK=确定
Confirm=确认 Confirm=确认
Cancel=取消 Cancel=取消
Close=关闭
True=是 True=是
False=否 False=否
Connecting=连接中 Connecting=连接中
@ -100,6 +101,9 @@ Pictures=图片
Documents=文档 Documents=文档
Applications=应用程序 Applications=应用程序
Archives=存档文件 Archives=存档文件
Other=其他
Custom=自定义
Custom Choose File=自定义选择文件
Address=地址 Address=地址
Client=客户端 Client=客户端
Status=状态 Status=状态

View file

@ -5,6 +5,7 @@ Error=錯誤
OK=確定 OK=確定
Confirm=確認 Confirm=確認
Cancel=取消 Cancel=取消
Close=關閉
True=是 True=是
False=否 False=否
Connecting=連線中 Connecting=連線中
@ -100,6 +101,9 @@ Pictures=圖片
Documents=文件 Documents=文件
Applications=應用程式 Applications=應用程式
Archives=封存檔案 Archives=封存檔案
Other=其他
Custom=自訂
Custom Choose File=自訂選擇檔案
Address=位址 Address=位址
Client=客戶端 Client=客戶端
Status=狀態 Status=狀態

View file

@ -9,6 +9,7 @@
'OK': 'OK', 'OK': 'OK',
'Confirm': 'Confirm', 'Confirm': 'Confirm',
'Cancel': 'Cancel', 'Cancel': 'Cancel',
'Close': 'Close',
'True': 'True', 'True': 'True',
'False': 'False', 'False': 'False',
'Connecting': 'Connecting', 'Connecting': 'Connecting',
@ -104,6 +105,9 @@
'Documents': 'Documents', 'Documents': 'Documents',
'Applications': 'Applications', 'Applications': 'Applications',
'Archives': 'Archives', 'Archives': 'Archives',
'Other': 'Other',
'Custom': 'Custom',
'Custom Choose File': 'Custom Choose File',
'Address': 'Address', 'Address': 'Address',
'Client': 'Client', 'Client': 'Client',
'Status': 'Status', 'Status': 'Status',

View file

@ -2,7 +2,9 @@
'use strict'; 'use strict';
angular.module('ariaNg').constant('ariaNgFileTypes', { angular.module('ariaNg').constant('ariaNgFileTypes', {
video: [ video: {
name: 'Videos',
extensions: [
'.3g2', '.3g2',
'.3gp', '.3gp',
'.3gp2', '.3gp2',
@ -32,8 +34,11 @@
'.ts', '.ts',
'.vob', '.vob',
'.wmv' '.wmv'
], ]
audio: [ },
audio: {
name: 'Audios',
extensions: [
'.aac', '.aac',
'.ac3', '.ac3',
'.adts', '.adts',
@ -58,8 +63,11 @@
'.wav', '.wav',
'.wma', '.wma',
'.wv' '.wv'
], ]
picture: [ },
picture: {
name: 'Pictures',
extensions: [
'.abr', '.abr',
'.bmp', '.bmp',
'.emf', '.emf',
@ -95,8 +103,11 @@
'.webp', '.webp',
'.wmf', '.wmf',
'.xif' '.xif'
], ]
document: [ },
document: {
name: 'Documents',
extensions: [
'.csv', '.csv',
'.doc', '.doc',
'.docm', '.docm',
@ -144,8 +155,11 @@
'.xltx', '.xltx',
'.xlw', '.xlw',
'.xps' '.xps'
], ]
application: [ },
application: {
name: 'Applications',
extensions: [
'.apk', '.apk',
'.bat', '.bat',
'.com', '.com',
@ -158,8 +172,11 @@
'.msi', '.msi',
'.rpm', '.rpm',
'.sh' '.sh'
], ]
archive: [ },
archive: {
name: 'Archives',
extensions: [
'.001', '.001',
'.7z', '.7z',
'.ace', '.ace',
@ -190,5 +207,6 @@
'.z', '.z',
'.zip' '.zip'
] ]
}
}); });
}()); }());

View file

@ -194,6 +194,7 @@
currentTab: 'overview', currentTab: 'overview',
isEnableSpeedChart: ariaNgSettingService.getDownloadTaskRefreshInterval() > 0, isEnableSpeedChart: ariaNgSettingService.getDownloadTaskRefreshInterval() > 0,
showChooseFilesToolbar: false, showChooseFilesToolbar: false,
fileExtensions: [],
collapsedDirs: {}, collapsedDirs: {},
btPeers: [], btPeers: [],
healthPercent: 0, healthPercent: 0,
@ -342,7 +343,7 @@
} }
var files = $scope.task.files; var files = $scope.task.files;
var extensions = ariaNgFileTypes[type]; var extensions = ariaNgFileTypes[type].extensions;
var fileIndexes = []; var fileIndexes = [];
var isAllSelected = true; var isAllSelected = true;
@ -395,6 +396,143 @@
} }
}; };
$scope.showCustomChooseFileModal = function () {
if (!$scope.task || !$scope.task.files) {
return;
}
var files = $scope.task.files;
var extensionsMap = {};
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (file.isDir) {
continue;
}
var extension = ariaNgCommonService.getFileExtension(file.fileName);
if (extension) {
extension = extension.toLowerCase();
}
var extensionInfo = extensionsMap[extension];
if (!extensionInfo) {
var extensionName = extension;
if (extensionName.length > 0 && extensionName.charAt(0) === '.') {
extensionName = extensionName.substring(1);
}
extensionInfo = {
extension: extensionName,
classified: false,
selected: false,
selectedCount: 0,
unSelectedCount: 0
};
extensionsMap[extension] = extensionInfo;
}
if (file.selected) {
extensionInfo.selected = true;
extensionInfo.selectedCount++;
} else {
extensionInfo.unSelectedCount++;
}
}
var allClassifiedExtensions = {};
for (var type in ariaNgFileTypes) {
if (!ariaNgFileTypes.hasOwnProperty(type)) {
continue;
}
var extensionTypeName = ariaNgFileTypes[type].name;
var allExtensions = ariaNgFileTypes[type].extensions;
var extensions = [];
for (var i = 0; i < allExtensions.length; i++) {
var extension = allExtensions[i];
var extensionInfo = extensionsMap[extension];
if (extensionInfo) {
extensionInfo.classified = true;
extensions.push(extensionInfo);
}
}
if (extensions.length > 0) {
allClassifiedExtensions[type] = {
name: extensionTypeName,
extensions: extensions
};
}
}
var unClassifiedExtensions = [];
for (var extension in extensionsMap) {
if (!extensionsMap.hasOwnProperty(extension)) {
continue;
}
var extensionInfo = extensionsMap[extension];
if (!extensionInfo.classified) {
unClassifiedExtensions.push(extensionInfo);
}
}
if (unClassifiedExtensions.length > 0) {
allClassifiedExtensions.other = {
name: 'Other',
extensions: unClassifiedExtensions
};
}
$scope.context.fileExtensions = allClassifiedExtensions;
angular.element('#custom-choose-file-modal').modal();
};
$scope.setSelectedExtension = function (selectedExtension, selected) {
if (!$scope.task || !$scope.task.files) {
return;
}
var files = $scope.task.files;
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (file.isDir) {
continue;
}
var extension = ariaNgCommonService.getFileExtension(file.fileName);
if (extension) {
extension = extension.toLowerCase();
}
if (extension !== '.' + selectedExtension) {
continue;
}
file.selected = selected;
}
updateAllDirNodesSelectedStatus();
};
$('#custom-choose-file-modal').on('hide.bs.modal', function (e) {
$scope.context.fileExtensions = null;
});
$scope.setSelectedFile = function (updateNodeSelectedStatus) { $scope.setSelectedFile = function (updateNodeSelectedStatus) {
if (updateNodeSelectedStatus) { if (updateNodeSelectedStatus) {
updateAllDirNodesSelectedStatus(); updateAllDirNodesSelectedStatus();

View file

@ -235,6 +235,10 @@
<i class="fa fa-file-archive-o"></i> <i class="fa fa-file-archive-o"></i>
<span translate>Archives</span> <span translate>Archives</span>
</button> </button>
<button class="btn btn-xs btn-default" ng-click="showCustomChooseFileModal()">
<i class="fa fa-filter"></i>
<span translate>Custom</span>
</button>
<button class="btn btn-xs btn-success" ng-click="saveChoosedFiles()" ng-disabled="!isAnyFileSelected()" translate>Confirm</button> <button class="btn btn-xs btn-success" ng-click="saveChoosedFiles()" ng-disabled="!isAnyFileSelected()" translate>Confirm</button>
<button class="btn btn-xs btn-default" ng-click="cancelChooseFiles()" translate>Cancel</button> <button class="btn btn-xs btn-default" ng-click="cancelChooseFiles()" translate>Cancel</button>
</div> </div>
@ -369,4 +373,32 @@
</li> </li>
</ul> </ul>
</div> </div>
<div id="custom-choose-file-modal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" translate>Custom Choose File</h4>
</div>
<div class="modal-body no-padding">
<div class="settings-table striped hoverable">
<div class="row" ng-repeat="(extensionTypeName, extensionTypeInfo) in context.fileExtensions">
<div class="setting-key setting-key-without-desc col-sm-4" ng-bind="extensionTypeInfo.name | translate"></div>
<div class="setting-value col-sm-8">
<div class="checkbox checkbox-primary checkbox-inline" ng-repeat="info in extensionTypeInfo.extensions">
<input id="{{info.extension}}" type="checkbox" ng-model="info.selected"
ng-indeterminate="info.selectedCount > 0 && info.unSelectedCount > 0"
ng-change="setSelectedExtension(info.extension, info.selected)">
<label for="{{info.extension}}" ng-bind="info.extension"></label>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" translate>Close</button>
</div>
</div>
</div>
</div>
</section> </section>