Skip to content

Commit

Permalink
WebUI: clean up code
Browse files Browse the repository at this point in the history
Use proper function for finding match.
Use strict comparison operators.
  • Loading branch information
Chocobo1 committed Apr 19, 2024
1 parent d7cded5 commit 75e2ae2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/webui/www/private/newtag.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
const verifyTagName = function(name) {
if ((name === null) || (name === ""))
return false;
if (name.indexOf(",") >= 0) {
if (name.includes(",")) {
alert("QBT_TR(Invalid tag name)QBT_TR[CONTEXT=TagFilterWidget]");
return false;
}
Expand Down
41 changes: 21 additions & 20 deletions src/webui/www/private/scripts/dynamicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ window.qBittorrent.DynamicTable = (function() {
this.deselectAll();
this.selectedRows = rowIds.slice();
this.tableBody.getElements('tr').each(function(tr) {
if (rowIds.indexOf(tr.rowId) > -1)
if (rowIds.includes(tr.rowId))
tr.addClass('selected');
});
},
Expand Down Expand Up @@ -1021,7 +1021,7 @@ window.qBittorrent.DynamicTable = (function() {

if (td.getChildren('img').length > 0) {
const img = td.getChildren('img')[0];
if (img.src.indexOf(img_path) < 0) {
if (!img.src.includes(img_path)) {
img.set('src', img_path);
img.set('title', state);
}
Expand Down Expand Up @@ -1335,52 +1335,53 @@ window.qBittorrent.DynamicTable = (function() {
const state = row['full_data'].state;
const name = row['full_data'].name.toLowerCase();
let inactive = false;
let r;

switch (filterName) {
case 'downloading':
if ((state != 'downloading') && (state.indexOf('DL') === -1))
if ((state !== 'downloading') && !state.includes('DL'))
return false;
break;
case 'seeding':
if ((state != 'uploading') && (state != 'forcedUP') && (state != 'stalledUP') && (state != 'queuedUP') && (state != 'checkingUP'))
if ((state !== 'uploading') && (state !== 'forcedUP') && (state !== 'stalledUP') && (state !== 'queuedUP') && (state !== 'checkingUP'))
return false;
break;
case 'completed':
if ((state != 'uploading') && (state.indexOf('UP') === -1))
if ((state !== 'uploading') && !state.includes('UP'))
return false;
break;
case 'stopped':
if (state.indexOf('stopped') === -1)
if (!state.includes('stopped'))
return false;
break;
case 'running':
if (state.indexOf('stopped') > -1)
if (state.includes('stopped'))
return false;
break;
case 'stalled':
if ((state != 'stalledUP') && (state != 'stalledDL'))
if ((state !== 'stalledUP') && (state !== 'stalledDL'))
return false;
break;
case 'stalled_uploading':
if (state != 'stalledUP')
if (state !== 'stalledUP')
return false;
break;
case 'stalled_downloading':
if (state != 'stalledDL')
if (state !== 'stalledDL')
return false;
break;
case 'inactive':
inactive = true;
// fallthrough
case 'active':
if (state == 'stalledDL')
case 'active': {
let r;
if (state === 'stalledDL')
r = (row['full_data'].upspeed > 0);
else
r = (state == 'metaDL') || (state == 'forcedMetaDL') || (state == 'downloading') || (state == 'forcedDL') || (state == 'uploading') || (state == 'forcedUP');
if (r == inactive)
r = (state === 'metaDL') || (state === 'forcedMetaDL') || (state === 'downloading') || (state === 'forcedDL') || (state === 'uploading') || (state === 'forcedUP');
if (r === inactive)
return false;
break;
}
case 'checking':
if ((state !== 'checkingUP') && (state !== 'checkingDL') && (state !== 'checkingResumeData'))
return false;
Expand All @@ -1390,7 +1391,7 @@ window.qBittorrent.DynamicTable = (function() {
return false;
break;
case 'errored':
if ((state != 'error') && (state != 'unknown') && (state != 'missingFiles'))
if ((state !== 'error') && (state !== 'unknown') && (state !== 'missingFiles'))
return false;
break;
}
Expand Down Expand Up @@ -1533,7 +1534,7 @@ window.qBittorrent.DynamicTable = (function() {
this._this.selectRow(this.rowId);
const row = this._this.rows.get(this.rowId);
const state = row['full_data'].state;
if (state.indexOf('stopped') > -1)
if (state.includes('stopped'))
startFN();
else
stopFN();
Expand Down Expand Up @@ -2095,7 +2096,7 @@ window.qBittorrent.DynamicTable = (function() {
const that = this;
this.deselectAll();
this.tableBody.getElements('tr').each(function(tr) {
if (rowIds.indexOf(tr.rowId) > -1) {
if (rowIds.includes(tr.rowId)) {
const node = that.getNode(tr.rowId);
node.checked = 0;
node.full_data.checked = 0;
Expand Down Expand Up @@ -2704,7 +2705,7 @@ window.qBittorrent.DynamicTable = (function() {
}
if (td.getChildren('img').length > 0) {
const img = td.getChildren('img')[0];
if (img.src.indexOf(img_path) < 0) {
if (!img.src.includes(img_path)) {
img.set('src', img_path);
img.set('title', status);
}
Expand Down Expand Up @@ -3159,7 +3160,7 @@ window.qBittorrent.DynamicTable = (function() {
const logLevels = window.qBittorrent.Log.getSelectedLevels();
if ((filterTerms.length > 0) || (logLevels.length < 4)) {
for (let i = 0; i < rows.length; ++i) {
if (logLevels.indexOf(rows[i].full_data.type.toString()) == -1)
if (!logLevels.includes(rows[i].full_data.type.toString()))
continue;

if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(rows[i].full_data.message, filterTerms))
Expand Down

0 comments on commit 75e2ae2

Please sign in to comment.