Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/webui/www/private/rename_files.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,11 @@
document.getElementById("renameOptions").disabled = false;

// Recreate table
let selectedRows = bulkRenameFilesTable.getSelectedRows().map(row => row.rowId.toString());
for (const renamedRow of rows)
selectedRows = selectedRows.filter(selectedRow => selectedRow !== renamedRow.rowId.toString());
const selectedRows = bulkRenameFilesTable.getSelectedRows().map(row => row.rowId.toString());
for (const renamedRow of rows) {
const id = renamedRow.rowId.toString();
window.qBittorrent.Misc.filterInPlace(selectedRows, (row => row !== id));
}
bulkRenameFilesTable.clear();

// Adjust file enumeration count by 1 when replacing single files to prevent naming conflicts
Expand Down
11 changes: 3 additions & 8 deletions src/webui/www/private/scripts/dynamicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,13 +871,7 @@ window.qBittorrent.DynamicTable ??= (() => {

updateTable(fullUpdate = false) {
const rows = this.getFilteredAndSortedRows();

for (let i = 0; i < this.selectedRows.length; ++i) {
if (!(this.selectedRows[i] in rows)) {
this.selectedRows.splice(i, 1);
--i;
}
}
window.qBittorrent.Misc.filterInPlace(this.selectedRows, (selectedRow => selectedRow in rows));

if (this.useVirtualList) {
// rerender on table update
Expand Down Expand Up @@ -2832,7 +2826,8 @@ window.qBittorrent.DynamicTable ??= (() => {

getSelectedRows() {
const nodes = this.fileTree.toArray();
return nodes.filter(x => x.checked === 0);
window.qBittorrent.Misc.filterInPlace(nodes, (node => node.checked === 0));
return nodes;
}

initColumns() {
Expand Down
13 changes: 13 additions & 0 deletions src/webui/www/private/scripts/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ window.qBittorrent.Misc ??= (() => {
return {
getHost: getHost,
createDebounceHandler: createDebounceHandler,
filterInPlace: filterInPlace,
friendlyUnit: friendlyUnit,
friendlyDuration: friendlyDuration,
friendlyPercentage: friendlyPercentage,
Expand Down Expand Up @@ -90,6 +91,18 @@ window.qBittorrent.Misc ??= (() => {
};
};

const filterInPlace = (array, predicate) => {
let j = 0;
for (let i = 0; i < array.length; ++i) {
if (predicate(array[i])) {
if (i > j)
array[j] = array[i];
++j;
}
}
array.splice(j, (array.length - j));
};

/*
* JS counterpart of the function in src/misc.cpp
*/
Expand Down
10 changes: 5 additions & 5 deletions src/webui/www/private/views/rss.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
.map((rowID) => rssFeedTable.getRow(rowID).full_data.dataPath);
// filter children
const reducedDatapaths = selectedDatapaths.filter((path) =>
selectedDatapaths.filter((innerPath) => path.slice(0, innerPath.length) === innerPath).length === 1
selectedDatapaths.filter(innerPath => path.startsWith(innerPath)).length === 1
);
removeItem(reducedDatapaths);
},
Expand Down Expand Up @@ -428,7 +428,7 @@
childFeeds.add(row.full_data.dataUid);
}

let visibleArticles = [];
const visibleArticles = [];
for (const feedEntry in feedData) {
if (childFeeds.has(feedEntry)) {
visibleArticles.append(feedData[feedEntry]
Expand All @@ -440,12 +440,12 @@
}
// filter read articles if "Unread" feed is selected
if (path === "")
visibleArticles = visibleArticles.filter((a) => !a.isRead);
window.qBittorrent.Misc.filterInPlace(visibleArticles, (article => !article.isRead));

const rssFilterInput = document.getElementById("rssFilterInput");
if (rssFilterInput.value.length > 0) {
const lowerFilter = rssFilterInput.value.toLowerCase();
visibleArticles = visibleArticles.filter((a) => a.title.toLowerCase().includes(lowerFilter));
window.qBittorrent.Misc.filterInPlace(visibleArticles, (article => article.title.toLowerCase().includes(lowerFilter)));
}

let rowID = -1;
Expand Down Expand Up @@ -980,7 +980,7 @@
.map((sRow) => rssFeedTable.getRow(sRow).full_data.dataPath);
// filter children
const reducedDatapaths = selectedDatapaths.filter((path) =>
selectedDatapaths.filter(path.startsWith).length === 1
selectedDatapaths.filter(innerPath => path.startsWith(innerPath)).length === 1
);
for (const path of reducedDatapaths)
markItemAsRead(path);
Expand Down
13 changes: 13 additions & 0 deletions src/webui/www/test/private/misc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ import { expect, test, vi } from "vitest";

import "../../private/scripts/misc.js";

test("Test filterInPlace()", () => {
const filterInPlace = (array, predicate) => {
window.qBittorrent.Misc.filterInPlace(array, predicate);
return array;
};

expect(filterInPlace([], (() => true))).toStrictEqual([]);
expect(filterInPlace([], (() => false))).toStrictEqual([]);
expect(filterInPlace([1, 2, 3, 4], (() => true))).toStrictEqual([1, 2, 3, 4]);
expect(filterInPlace([1, 2, 3, 4], (() => false))).toStrictEqual([]);
expect(filterInPlace([1, 2, 3, 4], (x => (x % 2) === 0))).toStrictEqual([2, 4]);
});

test("Test toFixedPointString()", () => {
const toFixedPointString = window.qBittorrent.Misc.toFixedPointString;

Expand Down
Loading