Browse Source

Merge pull request #9981 from Piccirello/webui-torrent-filter

Add torrent name filtering to WebUI
adaptive-webui-19844
Mike Tzou 6 years ago committed by GitHub
parent
commit
eebbf3b1ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/webui/www/private/css/style.css
  2. 3
      src/webui/www/private/index.html
  3. 16
      src/webui/www/private/scripts/client.js
  4. 41
      src/webui/www/private/scripts/dynamicTable.js

15
src/webui/www/private/css/style.css

@ -344,6 +344,21 @@ a.propButton img {
margin: 4px 5px 0 0; margin: 4px 5px 0 0;
} }
#torrentsFilterToolbar {
float: right;
margin-right: 30px;
margin-right: 30px;
}
#torrentsFilterInput {
width: 160px;
padding-left: 2em;
background-image: url("../images/qbt-theme/edit-find.svg");
background-repeat: no-repeat;
background-size: 1.5em;
background-position: left;
}
/* Tri-state checkbox */ /* Tri-state checkbox */
label.tristate { label.tristate {

3
src/webui/www/private/index.html

@ -107,6 +107,9 @@
</ul> </ul>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div id="torrentsFilterToolbar">
<input type="text" id="torrentsFilterInput" placeholder="QBT_TR(Filter torrent list...)QBT_TR[CONTEXT=MainWindow]" autocorrect="off" autocapitalize="none" />
</div>
</div> </div>
</div> </div>
<div id="pageWrapper"> <div id="pageWrapper">

16
src/webui/www/private/scripts/client.js

@ -348,6 +348,7 @@ window.addEvent('load', function() {
onSuccess: function(response) { onSuccess: function(response) {
$('error_div').set('html', ''); $('error_div').set('html', '');
if (response) { if (response) {
clearTimeout(torrentsFilterInputTimer);
var torrentsTableSelectedRows; var torrentsTableSelectedRows;
var update_categories = false; var update_categories = false;
var full_update = (response['full_update'] === true); var full_update = (response['full_update'] === true);
@ -773,11 +774,24 @@ window.addEvent('load', function() {
height: prop_h height: prop_h
}); });
var prevTorrentsFilterValue;
var torrentsFilterInputTimer = null;
// listen for changes to torrentsFilterInput
$('torrentsFilterInput').addEvent('input', function() {
var value = $('torrentsFilterInput').get("value");
if (value !== prevTorrentsFilterValue) {
prevTorrentsFilterValue = value;
clearTimeout(torrentsFilterInputTimer);
torrentsFilterInputTimer = setTimeout(function() {
torrentsTable.updateTable(false);
}, 400);
}
});
if (showSearchEngine) { if (showSearchEngine) {
addMainWindowTabsEventListener(); addMainWindowTabsEventListener();
addSearchPanel(); addSearchPanel();
} }
}); });
function closeWindows() { function closeWindows() {

41
src/webui/www/private/scripts/dynamicTable.js

@ -1139,8 +1139,9 @@ var TorrentsTable = new Class({
}; };
}, },
applyFilter: function(row, filterName, categoryHash) { applyFilter: function(row, filterName, categoryHash, filterTerms) {
var state = row['full_data'].state; var state = row['full_data'].state;
var name = row['full_data'].name.toLowerCase();
var inactive = false; var inactive = false;
var r; var r;
@ -1182,14 +1183,27 @@ var TorrentsTable = new Class({
break; break;
} }
if (categoryHash == CATEGORIES_ALL) var categoryHashInt = parseInt(categoryHash);
return true; if (!isNaN(categoryHashInt)) {
switch (categoryHashInt) {
if (categoryHash == CATEGORIES_UNCATEGORIZED && row['full_data'].category.length === 0) case CATEGORIES_ALL:
return true; break; // do nothing
case CATEGORIES_UNCATEGORIZED:
if (row['full_data'].category.length !== 0)
return false
break; // do nothing
default:
if (categoryHashInt !== genHash(row['full_data'].category))
return false;
}
}
if (categoryHash != genHash(row['full_data'].category)) if (filterTerms) {
return false; for (var i = 0; i < filterTerms.length; ++i) {
if (name.indexOf(filterTerms[i]) === -1)
return false;
}
}
return true; return true;
}, },
@ -1199,7 +1213,7 @@ var TorrentsTable = new Class({
var rows = this.rows.getValues(); var rows = this.rows.getValues();
for (var i = 0; i < rows.length; ++i) for (var i = 0; i < rows.length; ++i)
if (this.applyFilter(rows[i], filterName, categoryHash)) ++cnt; if (this.applyFilter(rows[i], filterName, categoryHash, null)) ++cnt;
return cnt; return cnt;
}, },
@ -1208,7 +1222,7 @@ var TorrentsTable = new Class({
var rows = this.rows.getValues(); var rows = this.rows.getValues();
for (var i = 0; i < rows.length; ++i) for (var i = 0; i < rows.length; ++i)
if (this.applyFilter(rows[i], filterName, categoryHash)) if (this.applyFilter(rows[i], filterName, categoryHash, null))
rowsHashes.push(rows[i]['rowId']); rowsHashes.push(rows[i]['rowId']);
return rowsHashes; return rowsHashes;
@ -1218,12 +1232,15 @@ var TorrentsTable = new Class({
var filteredRows = []; var filteredRows = [];
var rows = this.rows.getValues(); var rows = this.rows.getValues();
var filterText = $('torrentsFilterInput').value.trim().toLowerCase();
var filterTerms = (filterText.length > 0) ? filterText.split(" ") : null;
for (var i = 0; i < rows.length; ++i) for (var i = 0; i < rows.length; ++i) {
if (this.applyFilter(rows[i], selected_filter, selected_category)) { if (this.applyFilter(rows[i], selected_filter, selected_category, filterTerms)) {
filteredRows.push(rows[i]); filteredRows.push(rows[i]);
filteredRows[rows[i].rowId] = rows[i]; filteredRows[rows[i].rowId] = rows[i];
} }
}
filteredRows.sort(function(row1, row2) { filteredRows.sort(function(row1, row2) {
var column = this.columns[this.sortedColumn]; var column = this.columns[this.sortedColumn];

Loading…
Cancel
Save