增加 文件列表过滤,修复 校验进度条 (#398)

* 增加 文件列表过滤

* 改进一处判断

* 修复 显示校验进度

fix #235 #387

* 调整 校验进度条表示方式

transmission API接口校验进度范围为 0%-100%,显示时调整为按已完成进度为基数的百分比。
This commit is contained in:
imebeh 2020-04-16 22:27:37 +08:00 committed by GitHub
parent 74310fcdfb
commit 94cc3b089d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 119 additions and 9 deletions

View File

@ -399,6 +399,11 @@
"1": "High",
"-1": "Low"
},
"filter-template-text": {
"1": "All",
"2": "BitComet padding file",
"3": "Unnecessary files"
},
"label": {
"name": "Name:",
"addedDate": "Added date:",
@ -430,6 +435,7 @@
"button-allow": "Download checked file(s)",
"button-deny": "Skip checked file(s)",
"button-priority": "Set priority",
"button-filter": "Type in regular expressions and click the paging button to refresh",
"button-tracker-add": "Add New Tracker",
"button-tracker-edit": "Edit Tracker",
"button-tracker-remove": "Remove Tracker"

View File

@ -400,6 +400,11 @@
"1": "高",
"-1": "低"
},
"filter-template-text": {
"1": "全部",
"2": "BitComet 填充文件",
"3": "不需要的文件"
},
"label": {
"name": "名称:",
"addedDate": "添加时间:",
@ -431,6 +436,7 @@
"button-allow": "下载已选择的文件",
"button-deny": "忽略已选择的文件",
"button-priority": "设置优先级别",
"button-filter": "输入正则表达式后点左侧分页工具按钮以刷新",
"button-tracker-add": "增加新的 Tracker",
"button-tracker-edit": "修改已选中的 Tracker 地址",
"button-tracker-remove": "删除已选中的 Tracker 地址"

View File

@ -385,6 +385,11 @@
"1": "高",
"-1": "低"
},
"filter-template-text": {
"1": "全部",
"2": "BitComet 填充檔案",
"3": "不需要的檔案"
},
"label": {
"name": "名稱:",
"addedDate": "新增時間:",
@ -416,6 +421,7 @@
"button-allow": "下載已選取的檔案",
"button-deny": "忽略已選取的檔案",
"button-priority": "設定優先順序",
"button-filter": "輸入規則運算式後點左側分頁工具按鈕以刷新",
"button-tracker-add": "新增 Tracker",
"button-tracker-edit": "修改已選取的 Tracker",
"button-tracker-remove": "刪除已選取的 Tracker"

View File

@ -2194,11 +2194,11 @@ var system = {
return;
}
var status = this.lang.torrent["status-text"][torrents[index].status];
var percentDone = parseFloat(torrents[index].percentDone * 100).toFixed(2);
// Checksum, the use of verification progress
if (status == transmission._status.check) {
percentDone = parseFloat(torrents[index].recheckProgress * 100).toFixed(2);
}
// var percentDone = parseFloat(torrents[index].percentDone * 100).toFixed(2);
// // Checksum, the use of verification progress
// if (status == transmission._status.check) {
// percentDone = parseFloat(torrents[index].recheckProgress * 100).toFixed(2);
// }
if (torrents[index].error != 0) {
status = "<span class='text-status-error'>" + status + "</span>";
@ -2432,7 +2432,6 @@ var system = {
},
// Gets the progress bar for the specified torrent
getTorrentProgressBar: function (progress, torrent) {
progress = progress + "%";
var className = "";
var status = 0;
if (typeof (torrent) == "object") {
@ -2468,6 +2467,18 @@ var system = {
className = "torrent-progress-error";
}
}
if (status==transmission._status.check) {
// 目前只有status==_status.download时 torrent 不是对象
// 检查进度条长度保持在已完成的范围内
var percentCheckText = parseFloat(torrent.recheckProgress * 100).toFixed(2);
var percentCheckView = parseFloat(progress * 100 * torrent.recheckProgress).toFixed(2);
return '<div class="torrent-progress" title="' + progress + '%">'+
'<div class="torrent-progress-text" style="z-index:2;">' + percentCheckText + '%</div>'+
'<div class="torrent-progress-bar torrent-progress-seed" style="width:' + percentCheckView + '%;z-index:1;opacity:0.7;"></div>'+
'<div class="torrent-progress-bar ' + className + '" style="width:' + progress + '%;"></div>'+
'</div>';
}
progress = progress + "%";
return '<div class="torrent-progress" title="' + progress + '"><div class="torrent-progress-text">' + progress + '</div><div class="torrent-progress-bar ' + className + '" style="width:' + progress + ';"></div></div>';
},
// Add torrent
@ -2628,7 +2639,14 @@ var system = {
datas = datas.sort(arrayObjectSort(orderField, _options.sortOrder));
}
if (rows.length == 0 || (datas.length != sourceTable.datagrid("getData").total)) {
var isFileTable = (sourceTable.selector.indexOf("#torrent-files-table")!=-1);
var tableData = sourceTable.datagrid("getData");
var isFileFilterMode = isFileTable && !!tableData.filterString && tableData.torrentId==system.currentTorrentId;
if (isFileFilterMode){
datas = fileFilter(datas, tableData.filterString);
}
if (isFileFilterMode==false && (rows.length == 0 || (datas.length != tableData.total))) {
sourceTable.datagrid({
loadFilter: pagerFilter,
pageNumber: 1,
@ -3318,13 +3336,75 @@ $(document).ready(function () {
});
});
function fileFilter(dataRows, filterString) {
var filter = new RegExp(filterString || ".*");
var rawDataFiltered = new Array;
for (var j=0;j<dataRows.length;++j){
if (filter.test(dataRows[j].name)){
rawDataFiltered.push(dataRows[j]);
}
}
return rawDataFiltered;
}
function restoreFileFilterInputbox(defaultFilter) {
var langText = system.lang.torrent.attribute["filter-template-text"];
var filterTemplate =[{
"id":1,
"text": langText ? langText["1"] : "All",
"desc":".*"
},{
"id":2,
"text": langText ? langText["2"] : "BitComet padding file",
"desc":"____padding_file"
},{
"id":3,
"text": langText ? langText["3"] : "Unnecessary files",
"desc":"(.*\\.(url|lnk)$)|(RARBG_DO_NOT_MIRROR\\.exe)|(____padding_file)"
}];
$('<input id="torrent-files-filter-string" style="width:300px;">').insertAfter("#torrent-files-filter").combobox({
valueField: 'desc',
textField: 'desc',
panelWidth: 400,
panelHeight: 'auto',
formatter: function(row){
var s = '<span style="font-weight:bold; padding:3px;">'+row.text+'</span><br/>'+
'<span style="padding-left:10px;">'+row.desc+'</span>';
return s;
}
}).combobox("loadData", filterTemplate).combobox("setValue", defaultFilter);
}
function pagerFilter(data) {
var isFileData = false;
var filterChanged = false;
if (typeof data.length == 'number' && typeof data.splice == 'function') { // is array
data = {
total: data.length,
rows: data
}
}
isFileData = this.id=="torrent-files-table";
if (isFileData) {
var fileFilterString = $("#torrent-files-filter-string").val();
filterChanged = ( (data.filterString!==fileFilterString) ||
(data.filterString && data.originalRows.length==data.unfilteredRows.length)
);
if (filterChanged) {
data.torrentId = system.currentTorrentId;
var rawData = (data.unfilteredRows) || (data.originalRows) || (data.rows);
var rawDataFiltered = fileFilter(rawData, fileFilterString);
data.originalRows = rawDataFiltered;
data.total = rawDataFiltered.length;
if (!data.unfilteredRows) {
data.unfilteredRows = (rawData);
}
data.filterString = fileFilterString;
}
}
var dg = $(this);
var opts = dg.datagrid('options');
var pager = dg.datagrid('getPager');
@ -3345,7 +3425,7 @@ function pagerFilter(data) {
if (!data.originalRows) {
data.originalRows = (data.rows);
}
var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
var start = filterChanged ? 0 : (opts.pageNumber - 1) * parseInt(opts.pageSize);
var end = start + parseInt(opts.pageSize);
data.rows = (data.originalRows.slice(start, end));
@ -3358,5 +3438,9 @@ function pagerFilter(data) {
}
}
if (isFileData) {
restoreFileFilterInputbox(fileFilterString);
}
return data;
}

View File

@ -16,7 +16,7 @@ transmission.torrents = {
pausedTorrentCount: 0,
fields: {
base: "id,name,status,hashString,totalSize,percentDone,addedDate,trackerStats,leftUntilDone,rateDownload,rateUpload,recheckProgress" + ",rateDownload,rateUpload,peersGettingFromUs,peersSendingToUs,uploadRatio,uploadedEver,downloadedEver,downloadDir,error,errorString,doneDate,queuePosition,activityDate",
status: "id,name,status,totalSize,percentDone,trackerStats,leftUntilDone,rateDownload,rateUpload" + ",rateDownload,rateUpload,peersGettingFromUs,peersSendingToUs,uploadRatio,uploadedEver,downloadedEver,error,errorString,doneDate,queuePosition,activityDate",
status: "id,name,status,totalSize,percentDone,trackerStats,leftUntilDone,rateDownload,rateUpload,recheckProgress" + ",rateDownload,rateUpload,peersGettingFromUs,peersSendingToUs,uploadRatio,uploadedEver,downloadedEver,error,errorString,doneDate,queuePosition,activityDate",
config: "downloadLimit,downloadLimited,peer-limit,seedIdleLimit,seedIdleMode,seedRatioLimit,seedRatioMode,uploadLimit,uploadLimited"
},
// List of all the torrents that have been acquired

View File

@ -36,4 +36,7 @@
}
.icon-chart{
background:url('icons/chart.png') no-repeat;
}
.icon-filter{
background:url('icons/filter.png') no-repeat center center;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

View File

@ -263,6 +263,11 @@
handler:function(){
priorityMenu.menu("show",$(this).offset());
}
},'-',{
id:"torrent-files-filter",
iconCls:"icon-filter",
title: system.lang.torrent.attribute["tip"]["button-filter"],
disabled:'true'
}];
var priorityMenu = $("<div/>").attr("id","priorityMenu").appendTo(thisLayout.find("#torrent-attribute-files"));
priorityMenu.menu({