WebUI: Prefix private properties with # in dynamic table classes

This commit is contained in:
skomerko 2025-04-29 19:58:23 +02:00
commit bb68a39b53

View file

@ -293,7 +293,7 @@ window.qBittorrent.DynamicTable ??= (() => {
if (width < 16) if (width < 16)
width = 16; width = 16;
this._setColumnWidth(this.resizeTh.columnName, width); this.#setColumnWidth(this.resizeTh.columnName, width);
} }
}.bind(this); }.bind(this);
@ -393,7 +393,7 @@ window.qBittorrent.DynamicTable ??= (() => {
this.columns[columnName].onVisibilityChange?.(columnName); this.columns[columnName].onVisibilityChange?.(columnName);
} }
_calculateColumnBodyWidth(column) { #calculateColumnBodyWidth(column) {
const columnIndex = this.getColumnPos(column.name); const columnIndex = this.getColumnPos(column.name);
const bodyColumn = document.getElementById(this.dynamicTableDivId).querySelectorAll("tr>th")[columnIndex]; const bodyColumn = document.getElementById(this.dynamicTableDivId).querySelectorAll("tr>th")[columnIndex];
const canvas = document.createElement("canvas"); const canvas = document.createElement("canvas");
@ -417,7 +417,7 @@ window.qBittorrent.DynamicTable ??= (() => {
return longestTd.width + 10; return longestTd.width + 10;
} }
_setColumnWidth(columnName, width) { #setColumnWidth(columnName, width) {
const column = this.columns[columnName]; const column = this.columns[columnName];
column.width = width; column.width = width;
@ -438,7 +438,7 @@ window.qBittorrent.DynamicTable ??= (() => {
let width = column.staticWidth ?? 0; let width = column.staticWidth ?? 0;
if (column.staticWidth === null) { if (column.staticWidth === null) {
// check required min body width // check required min body width
const bodyTextWidth = this._calculateColumnBodyWidth(column); const bodyTextWidth = this.#calculateColumnBodyWidth(column);
// check required min header width // check required min header width
const columnIndex = this.getColumnPos(column.name); const columnIndex = this.getColumnPos(column.name);
@ -453,7 +453,7 @@ window.qBittorrent.DynamicTable ??= (() => {
width = Math.max(headTextWidth, bodyTextWidth); width = Math.max(headTextWidth, bodyTextWidth);
} }
this._setColumnWidth(column.name, width); this.#setColumnWidth(column.name, width);
this.saveColumnWidth(column.name); this.saveColumnWidth(column.name);
} }
@ -2195,11 +2195,11 @@ window.qBittorrent.DynamicTable ??= (() => {
populateTable(root) { populateTable(root) {
this.fileTree.setRoot(root); this.fileTree.setRoot(root);
root.children.each((node) => { root.children.each((node) => {
this._addNodeToTable(node, 0); this.#addNodeToTable(node, 0);
}); });
} }
_addNodeToTable(node, depth) { #addNodeToTable(node, depth) {
node.depth = depth; node.depth = depth;
if (node.isFolder) { if (node.isFolder) {
@ -2223,7 +2223,7 @@ window.qBittorrent.DynamicTable ??= (() => {
} }
node.children.each((child) => { node.children.each((child) => {
this._addNodeToTable(child, depth + 1); this.#addNodeToTable(child, depth + 1);
}); });
} }
@ -2431,7 +2431,7 @@ window.qBittorrent.DynamicTable ??= (() => {
this.updateGlobalCheckbox(); this.updateGlobalCheckbox();
} }
_sortNodesByColumn(nodes, column) { #sortNodesByColumn(nodes, column) {
nodes.sort((row1, row2) => { nodes.sort((row1, row2) => {
// list folders before files when sorting by name // list folders before files when sorting by name
if (column.name === "original") { if (column.name === "original") {
@ -2449,15 +2449,15 @@ window.qBittorrent.DynamicTable ??= (() => {
nodes.each((node) => { nodes.each((node) => {
if (node.children.length > 0) if (node.children.length > 0)
this._sortNodesByColumn(node.children, column); this.#sortNodesByColumn(node.children, column);
}); });
} }
_filterNodes(node, filterTerms, filteredRows) { #filterNodes(node, filterTerms, filteredRows) {
if (node.isFolder) { if (node.isFolder) {
const childAdded = node.children.reduce((acc, child) => { const childAdded = node.children.reduce((acc, child) => {
// we must execute the function before ORing w/ acc or we'll stop checking child nodes after the first successful match // we must execute the function before ORing w/ acc or we'll stop checking child nodes after the first successful match
return (this._filterNodes(child, filterTerms, filteredRows) || acc); return (this.#filterNodes(child, filterTerms, filteredRows) || acc);
}, false); }, false);
if (childAdded) { if (childAdded) {
@ -2506,7 +2506,7 @@ window.qBittorrent.DynamicTable ??= (() => {
const filteredRows = []; const filteredRows = [];
this.getRoot().children.each((child) => { this.getRoot().children.each((child) => {
this._filterNodes(child, this.filterTerms, filteredRows); this.#filterNodes(child, this.filterTerms, filteredRows);
}); });
filteredRows.reverse(); filteredRows.reverse();
return filteredRows; return filteredRows;
@ -2531,7 +2531,7 @@ window.qBittorrent.DynamicTable ??= (() => {
// sort, then filter // sort, then filter
const column = this.columns[this.sortedColumn]; const column = this.columns[this.sortedColumn];
this._sortNodesByColumn(this.getRoot().children, column); this.#sortNodesByColumn(this.getRoot().children, column);
const filteredRows = getFilteredRows(); const filteredRows = getFilteredRows();
this.prevFilterTerms = this.filterTerms; this.prevFilterTerms = this.filterTerms;
@ -2579,14 +2579,14 @@ window.qBittorrent.DynamicTable ??= (() => {
const state = this.collapseState.get(id); const state = this.collapseState.get(id);
if (state !== undefined) if (state !== undefined)
state.collapsed = false; state.collapsed = false;
this._updateNodeState(id, false); this.#updateNodeState(id, false);
} }
collapseNode(id) { collapseNode(id) {
const state = this.collapseState.get(id); const state = this.collapseState.get(id);
if (state !== undefined) if (state !== undefined)
state.collapsed = true; state.collapsed = true;
this._updateNodeState(id, true); this.#updateNodeState(id, true);
} }
expandAllNodes() { expandAllNodes() {
@ -2602,7 +2602,7 @@ window.qBittorrent.DynamicTable ??= (() => {
} }
} }
_updateNodeVisibility(node, shouldHide) { #updateNodeVisibility(node, shouldHide) {
const span = document.getElementById(`filesTablefileName${node.rowId}`); const span = document.getElementById(`filesTablefileName${node.rowId}`);
// span won't exist if row has been filtered out // span won't exist if row has been filtered out
if (span === null) if (span === null)
@ -2611,7 +2611,7 @@ window.qBittorrent.DynamicTable ??= (() => {
tr.classList.toggle("invisible", shouldHide); tr.classList.toggle("invisible", shouldHide);
} }
_updateNodeCollapseIcon(node, isCollapsed) { #updateNodeCollapseIcon(node, isCollapsed) {
const span = document.getElementById(`filesTablefileName${node.rowId}`); const span = document.getElementById(`filesTablefileName${node.rowId}`);
// span won't exist if row has been filtered out // span won't exist if row has been filtered out
if (span === null) if (span === null)
@ -2623,7 +2623,7 @@ window.qBittorrent.DynamicTable ??= (() => {
collapseIcon.classList.toggle("rotate", isCollapsed); collapseIcon.classList.toggle("rotate", isCollapsed);
} }
_updateNodeState(id, shouldCollapse) { #updateNodeState(id, shouldCollapse) {
// collapsed rows will be filtered out when using virtual list // collapsed rows will be filtered out when using virtual list
if (this.useVirtualList) if (this.useVirtualList)
return; return;
@ -2631,17 +2631,17 @@ window.qBittorrent.DynamicTable ??= (() => {
if (!node.isFolder) if (!node.isFolder)
return; return;
this._updateNodeCollapseIcon(node, shouldCollapse); this.#updateNodeCollapseIcon(node, shouldCollapse);
this._updateNodeChildVisibility(node, shouldCollapse); this.#updateNodeChildVisibility(node, shouldCollapse);
} }
_updateNodeChildVisibility(root, shouldHide) { #updateNodeChildVisibility(root, shouldHide) {
const stack = [...root.children]; const stack = [...root.children];
while (stack.length > 0) { while (stack.length > 0) {
const node = stack.pop(); const node = stack.pop();
this._updateNodeVisibility(node, (shouldHide ? shouldHide : this.isCollapsed(node.root.rowId))); this.#updateNodeVisibility(node, (shouldHide ? shouldHide : this.isCollapsed(node.root.rowId)));
stack.push(...node.children); stack.push(...node.children);
} }
@ -2680,11 +2680,11 @@ window.qBittorrent.DynamicTable ??= (() => {
populateTable(root) { populateTable(root) {
this.fileTree.setRoot(root); this.fileTree.setRoot(root);
root.children.each((node) => { root.children.each((node) => {
this._addNodeToTable(node, 0); this.#addNodeToTable(node, 0);
}); });
} }
_addNodeToTable(node, depth) { #addNodeToTable(node, depth) {
node.depth = depth; node.depth = depth;
if (node.isFolder) { if (node.isFolder) {
@ -2713,7 +2713,7 @@ window.qBittorrent.DynamicTable ??= (() => {
} }
node.children.each((child) => { node.children.each((child) => {
this._addNodeToTable(child, depth + 1); this.#addNodeToTable(child, depth + 1);
}); });
} }
@ -2881,7 +2881,7 @@ window.qBittorrent.DynamicTable ??= (() => {
this.columns["availability"].updateTd = displayPercentage; this.columns["availability"].updateTd = displayPercentage;
} }
_sortNodesByColumn(nodes, column) { #sortNodesByColumn(nodes, column) {
nodes.sort((row1, row2) => { nodes.sort((row1, row2) => {
// list folders before files when sorting by name // list folders before files when sorting by name
if (column.name === "name") { if (column.name === "name") {
@ -2899,15 +2899,15 @@ window.qBittorrent.DynamicTable ??= (() => {
nodes.each((node) => { nodes.each((node) => {
if (node.children.length > 0) if (node.children.length > 0)
this._sortNodesByColumn(node.children, column); this.#sortNodesByColumn(node.children, column);
}); });
} }
_filterNodes(node, filterTerms, filteredRows) { #filterNodes(node, filterTerms, filteredRows) {
if (node.isFolder && (!this.useVirtualList || !this.isCollapsed(node.rowId))) { if (node.isFolder && (!this.useVirtualList || !this.isCollapsed(node.rowId))) {
const childAdded = node.children.toReversed().reduce((acc, child) => { const childAdded = node.children.toReversed().reduce((acc, child) => {
// we must execute the function before ORing w/ acc or we'll stop checking child nodes after the first successful match // we must execute the function before ORing w/ acc or we'll stop checking child nodes after the first successful match
return (this._filterNodes(child, filterTerms, filteredRows) || acc); return (this.#filterNodes(child, filterTerms, filteredRows) || acc);
}, false); }, false);
if (childAdded) { if (childAdded) {
@ -2948,7 +2948,7 @@ window.qBittorrent.DynamicTable ??= (() => {
const getFilteredRows = function() { const getFilteredRows = function() {
const filteredRows = []; const filteredRows = [];
this.getRoot().children.each((child) => { this.getRoot().children.each((child) => {
this._filterNodes(child, this.filterTerms, filteredRows); this.#filterNodes(child, this.filterTerms, filteredRows);
}); });
filteredRows.reverse(); filteredRows.reverse();
return filteredRows; return filteredRows;
@ -2973,7 +2973,7 @@ window.qBittorrent.DynamicTable ??= (() => {
// sort, then filter // sort, then filter
const column = this.columns[this.sortedColumn]; const column = this.columns[this.sortedColumn];
this._sortNodesByColumn(this.getRoot().children, column); this.#sortNodesByColumn(this.getRoot().children, column);
const filteredRows = getFilteredRows(); const filteredRows = getFilteredRows();
this.prevFilterTerms = this.filterTerms; this.prevFilterTerms = this.filterTerms;