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

View file

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

View file

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

View file

@ -1,194 +1,212 @@
(function () {
(function () {
'use strict';
angular.module('ariaNg').constant('ariaNgFileTypes', {
video: [
'.3g2',
'.3gp',
'.3gp2',
'.3gpp',
'.asf',
'.asx',
'.avi',
'.dat',
'.divx',
'.flv',
'.m1v',
'.m2ts',
'.m2v',
'.m4v',
'.mkv',
'.mov',
'.mp4',
'.mpe',
'.mpeg',
'.mpg',
'.mts',
'.ogv',
'.qt',
'.ram',
'.rm',
'.rmvb',
'.ts',
'.vob',
'.wmv'
],
audio: [
'.aac',
'.ac3',
'.adts',
'.amr',
'.ape',
'.eac3',
'.flac',
'.m1a',
'.m2a',
'.m4a',
'.mid',
'.mka',
'.mp2',
'.mp3',
'.mpa',
'.mpc',
'.ogg',
'.ra',
'.tak',
'.vqf',
'.wm',
'.wav',
'.wma',
'.wv'
],
picture: [
'.abr',
'.bmp',
'.emf',
'.gif',
'.j2c',
'.j2k',
'.jfif',
'.jif',
'.jp2',
'.jpc',
'.jpe',
'.jpeg',
'.jpf',
'.jpg',
'.jpk',
'.jpx',
'.pcx',
'.pct',
'.pic',
'.pict',
'.png',
'.pns',
'.psd',
'.psdx',
'.raw',
'.svg',
'.svgz',
'.tga',
'.tif',
'.tiff',
'.wbm',
'.wbmp',
'.webp',
'.wmf',
'.xif'
],
document: [
'.csv',
'.doc',
'.docm',
'.docx',
'.dot',
'.dotm',
'.dotx',
'.key',
'.mpp',
'.numbers',
'.odp',
'.ods',
'.odt',
'.pages',
'.pdf',
'.pot',
'.potm',
'.potx',
'.pps',
'.ppsm',
'.ppsx',
'.ppt',
'.pptm',
'.pptx',
'.rtf',
'.txt',
'.vsd',
'.vsdx',
'.wk1',
'.wk2',
'.wk3',
'.wk4',
'.wks',
'.wpd',
'.wps',
'.xla',
'.xlam',
'.xll',
'.xlm',
'.xls',
'.xlsb',
'.xlsm',
'.xlsx',
'.xlt',
'.xltx',
'.xlw',
'.xps'
],
application: [
'.apk',
'.bat',
'.com',
'.deb',
'.dll',
'.dmg',
'.exe',
'.ipa',
'.jar',
'.msi',
'.rpm',
'.sh'
],
archive: [
'.001',
'.7z',
'.ace',
'.arj',
'.bz2',
'.cab',
'.cbr',
'.cbz',
'.gz',
'.img',
'.iso',
'.lzh',
'.qcow2',
'.r',
'.rar',
'.sef',
'.tar',
'.taz',
'.tbz',
'.tbz2',
'.uue',
'.vdi',
'.vhd',
'.vmdk',
'.wim',
'.xar',
'.xz',
'.z',
'.zip'
]
video: {
name: 'Videos',
extensions: [
'.3g2',
'.3gp',
'.3gp2',
'.3gpp',
'.asf',
'.asx',
'.avi',
'.dat',
'.divx',
'.flv',
'.m1v',
'.m2ts',
'.m2v',
'.m4v',
'.mkv',
'.mov',
'.mp4',
'.mpe',
'.mpeg',
'.mpg',
'.mts',
'.ogv',
'.qt',
'.ram',
'.rm',
'.rmvb',
'.ts',
'.vob',
'.wmv'
]
},
audio: {
name: 'Audios',
extensions: [
'.aac',
'.ac3',
'.adts',
'.amr',
'.ape',
'.eac3',
'.flac',
'.m1a',
'.m2a',
'.m4a',
'.mid',
'.mka',
'.mp2',
'.mp3',
'.mpa',
'.mpc',
'.ogg',
'.ra',
'.tak',
'.vqf',
'.wm',
'.wav',
'.wma',
'.wv'
]
},
picture: {
name: 'Pictures',
extensions: [
'.abr',
'.bmp',
'.emf',
'.gif',
'.j2c',
'.j2k',
'.jfif',
'.jif',
'.jp2',
'.jpc',
'.jpe',
'.jpeg',
'.jpf',
'.jpg',
'.jpk',
'.jpx',
'.pcx',
'.pct',
'.pic',
'.pict',
'.png',
'.pns',
'.psd',
'.psdx',
'.raw',
'.svg',
'.svgz',
'.tga',
'.tif',
'.tiff',
'.wbm',
'.wbmp',
'.webp',
'.wmf',
'.xif'
]
},
document: {
name: 'Documents',
extensions: [
'.csv',
'.doc',
'.docm',
'.docx',
'.dot',
'.dotm',
'.dotx',
'.key',
'.mpp',
'.numbers',
'.odp',
'.ods',
'.odt',
'.pages',
'.pdf',
'.pot',
'.potm',
'.potx',
'.pps',
'.ppsm',
'.ppsx',
'.ppt',
'.pptm',
'.pptx',
'.rtf',
'.txt',
'.vsd',
'.vsdx',
'.wk1',
'.wk2',
'.wk3',
'.wk4',
'.wks',
'.wpd',
'.wps',
'.xla',
'.xlam',
'.xll',
'.xlm',
'.xls',
'.xlsb',
'.xlsm',
'.xlsx',
'.xlt',
'.xltx',
'.xlw',
'.xps'
]
},
application: {
name: 'Applications',
extensions: [
'.apk',
'.bat',
'.com',
'.deb',
'.dll',
'.dmg',
'.exe',
'.ipa',
'.jar',
'.msi',
'.rpm',
'.sh'
]
},
archive: {
name: 'Archives',
extensions: [
'.001',
'.7z',
'.ace',
'.arj',
'.bz2',
'.cab',
'.cbr',
'.cbz',
'.gz',
'.img',
'.iso',
'.lzh',
'.qcow2',
'.r',
'.rar',
'.sef',
'.tar',
'.taz',
'.tbz',
'.tbz2',
'.uue',
'.vdi',
'.vhd',
'.vmdk',
'.wim',
'.xar',
'.xz',
'.z',
'.zip'
]
}
});
}());

View file

@ -194,6 +194,7 @@
currentTab: 'overview',
isEnableSpeedChart: ariaNgSettingService.getDownloadTaskRefreshInterval() > 0,
showChooseFilesToolbar: false,
fileExtensions: [],
collapsedDirs: {},
btPeers: [],
healthPercent: 0,
@ -342,7 +343,7 @@
}
var files = $scope.task.files;
var extensions = ariaNgFileTypes[type];
var extensions = ariaNgFileTypes[type].extensions;
var fileIndexes = [];
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) {
if (updateNodeSelectedStatus) {
updateAllDirNodesSelectedStatus();

View file

@ -235,6 +235,10 @@
<i class="fa fa-file-archive-o"></i>
<span translate>Archives</span>
</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-default" ng-click="cancelChooseFiles()" translate>Cancel</button>
</div>
@ -369,4 +373,32 @@
</li>
</ul>
</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>