mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 21:03:30 -07:00
refact: Improve JS priority change logic
This commit is contained in:
parent
32099095f7
commit
35b94986b3
3 changed files with 32 additions and 58 deletions
|
@ -3044,14 +3044,6 @@ window.qBittorrent.DynamicTable ??= (() => {
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
setIgnored(rowId, ignore) {
|
|
||||||
const row = this.rows.get(rowId.toString());
|
|
||||||
if (ignore)
|
|
||||||
row.full_data.remaining = 0;
|
|
||||||
else
|
|
||||||
row.full_data.remaining = (row.full_data.size * (1.0 - (row.full_data.progress / 100)));
|
|
||||||
}
|
|
||||||
|
|
||||||
setupCommonEvents() {
|
setupCommonEvents() {
|
||||||
super.setupCommonEvents();
|
super.setupCommonEvents();
|
||||||
this.dynamicTableDiv.addEventListener("keydown", (e) => {
|
this.dynamicTableDiv.addEventListener("keydown", (e) => {
|
||||||
|
|
|
@ -45,8 +45,7 @@ window.qBittorrent.FileTree ??= (() => {
|
||||||
Normal: 1,
|
Normal: 1,
|
||||||
High: 6,
|
High: 6,
|
||||||
Maximum: 7,
|
Maximum: 7,
|
||||||
Mixed: -1,
|
Mixed: -1
|
||||||
ByShownOrder: -2
|
|
||||||
};
|
};
|
||||||
Object.freeze(FilePriority);
|
Object.freeze(FilePriority);
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ window.qBittorrent.PropFiles ??= (() => {
|
||||||
const TriState = window.qBittorrent.FileTree.TriState;
|
const TriState = window.qBittorrent.FileTree.TriState;
|
||||||
let is_seed = true;
|
let is_seed = true;
|
||||||
let current_hash = "";
|
let current_hash = "";
|
||||||
|
const BY_SHOWN_ORDER = -2;
|
||||||
|
|
||||||
const normalizePriority = (priority) => {
|
const normalizePriority = (priority) => {
|
||||||
switch (priority) {
|
switch (priority) {
|
||||||
|
@ -105,7 +106,7 @@ window.qBittorrent.PropFiles ??= (() => {
|
||||||
|
|
||||||
const rows = getAllChildren(id, fileId);
|
const rows = getAllChildren(id, fileId);
|
||||||
|
|
||||||
setFilePriority(rows.rowIds, rows.fileIds, priority);
|
setFilePriority(rows.fileIds, priority);
|
||||||
updateGlobalCheckbox();
|
updateGlobalCheckbox();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -117,7 +118,7 @@ window.qBittorrent.PropFiles ??= (() => {
|
||||||
|
|
||||||
const rows = getAllChildren(id, fileId);
|
const rows = getAllChildren(id, fileId);
|
||||||
|
|
||||||
setFilePriority(rows.rowIds, rows.fileIds, priority);
|
setFilePriority(rows.fileIds, priority);
|
||||||
updateGlobalCheckbox();
|
updateGlobalCheckbox();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -241,7 +242,7 @@ window.qBittorrent.PropFiles ??= (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rowIds.length > 0)
|
if (rowIds.length > 0)
|
||||||
setFilePriority(rowIds, fileIds, priority);
|
setFilePriority(fileIds, priority);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateGlobalCheckbox = () => {
|
const updateGlobalCheckbox = () => {
|
||||||
|
@ -271,7 +272,7 @@ window.qBittorrent.PropFiles ??= (() => {
|
||||||
checkbox.indeterminate = true;
|
checkbox.indeterminate = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const setFilePriority = (ids, fileIds, priority) => {
|
const setFilePriority = (fileIds, priority) => {
|
||||||
if (current_hash === "")
|
if (current_hash === "")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -292,15 +293,6 @@ window.qBittorrent.PropFiles ??= (() => {
|
||||||
|
|
||||||
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(1000);
|
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
const ignore = (priority === FilePriority.Ignored);
|
|
||||||
ids.forEach((id) => {
|
|
||||||
torrentFilesTable.setIgnored(id, ignore);
|
|
||||||
|
|
||||||
const combobox = document.getElementById(`comboPrio${id}`);
|
|
||||||
if (combobox !== null)
|
|
||||||
selectComboboxPriority(combobox, priority);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let loadTorrentFilesDataTimer = -1;
|
let loadTorrentFilesDataTimer = -1;
|
||||||
|
@ -459,44 +451,40 @@ window.qBittorrent.PropFiles ??= (() => {
|
||||||
if (selectedRows.length === 0)
|
if (selectedRows.length === 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const rowIds = [];
|
|
||||||
const fileIds = [];
|
const fileIds = [];
|
||||||
selectedRows.forEach((rowId) => {
|
const fillInChildren = (rowId, fileId) => {
|
||||||
rowIds.push(rowId);
|
const children = getAllChildren(rowId, fileId);
|
||||||
fileIds.push(torrentFilesTable.getRowFileId(rowId));
|
children.fileIds.forEach((childFileId, index) => {
|
||||||
});
|
if (fileId === -1) {
|
||||||
|
fillInChildren(children.rowIds[index], childFileId);
|
||||||
const uniqueRowIds = {};
|
return;
|
||||||
const uniqueFileIds = {};
|
|
||||||
for (let i = 0; i < rowIds.length; ++i) {
|
|
||||||
const rows = getAllChildren(rowIds[i], fileIds[i]);
|
|
||||||
rows.rowIds.forEach((rowId) => {
|
|
||||||
uniqueRowIds[rowId] = true;
|
|
||||||
});
|
|
||||||
rows.fileIds.forEach((fileId) => {
|
|
||||||
uniqueFileIds[fileId] = true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
if (!fileIds.includes(childFileId))
|
||||||
|
fileIds.push(childFileId);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
selectedRows.forEach((rowId) => {
|
||||||
|
const fileId = torrentFilesTable.getRowFileId(rowId);
|
||||||
|
if (fileId !== -1)
|
||||||
|
fileIds.push(fileId);
|
||||||
|
fillInChildren(rowId, fileId);
|
||||||
|
});
|
||||||
|
|
||||||
// Will be used both in general case and ByShownOrder case
|
// Will be used both in general case and ByShownOrder case
|
||||||
const filesLen = Object.keys(uniqueFileIds).length;
|
|
||||||
const priorityList = {};
|
const priorityList = {};
|
||||||
Object.values(FilePriority).forEach((p) => {
|
Object.values(FilePriority).forEach((p) => {
|
||||||
priorityList[p] = [];
|
priorityList[p] = [];
|
||||||
});
|
});
|
||||||
const priorityGroupSize = Math.max(Math.floor(filesLen / 3), 1);
|
const groupsNum = 3;
|
||||||
const uniqueFileKeys = Object.keys(uniqueFileIds);
|
const priorityGroupSize = Math.max(Math.floor(fileIds.length / groupsNum), 1);
|
||||||
const uniqueRowKeys = Object.keys(uniqueRowIds);
|
|
||||||
|
|
||||||
// Will be altered only if we select ByShownOrder, use whatever is passed otherwise
|
// Will be altered only if we select ByShownOrder, use whatever is passed otherwise
|
||||||
let priorityGroup = priority;
|
let priorityGroup = priority;
|
||||||
let fileId = 0;
|
let fileId = 0;
|
||||||
let rowId = 0;
|
for (let i = 0; i < fileIds.length; ++i) {
|
||||||
for (let i = 0; i < filesLen; ++i) {
|
fileId = fileIds[i];
|
||||||
fileId = uniqueFileKeys[i];
|
if (priority === BY_SHOWN_ORDER) {
|
||||||
rowId = uniqueRowKeys[i];
|
|
||||||
// Calculate priority based on order
|
|
||||||
if (priority === FilePriority.ByShownOrder) {
|
|
||||||
switch (Math.floor(i / priorityGroupSize)) {
|
switch (Math.floor(i / priorityGroupSize)) {
|
||||||
case 0:
|
case 0:
|
||||||
priorityGroup = FilePriority.Maximum;
|
priorityGroup = FilePriority.Maximum;
|
||||||
|
@ -510,19 +498,14 @@ window.qBittorrent.PropFiles ??= (() => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Or if we use one of the simpler priorities, just push in the same group
|
priorityList[priorityGroup].push(fileId);
|
||||||
priorityList[priorityGroup].push({
|
|
||||||
fileId: fileId,
|
|
||||||
rowId: rowId
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.entries(priorityList).forEach(([groupPriority, groupedFileRowPair]) => {
|
Object.entries(priorityList).forEach(([groupPriority, groupedFiles]) => {
|
||||||
if (groupedFileRowPair.length === 0)
|
if (groupedFiles.length === 0)
|
||||||
return;
|
return;
|
||||||
setFilePriority(
|
setFilePriority(
|
||||||
groupedFileRowPair.map(pair => pair.rowId),
|
groupedFiles,
|
||||||
groupedFileRowPair.map(pair => pair.fileId),
|
|
||||||
groupPriority
|
groupPriority
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -602,7 +585,7 @@ window.qBittorrent.PropFiles ??= (() => {
|
||||||
filesPriorityMenuClicked(FilePriority.Maximum);
|
filesPriorityMenuClicked(FilePriority.Maximum);
|
||||||
},
|
},
|
||||||
FilePrioByShownOrder: (element, ref) => {
|
FilePrioByShownOrder: (element, ref) => {
|
||||||
filesPriorityMenuClicked(FilePriority.ByShownOrder);
|
filesPriorityMenuClicked(BY_SHOWN_ORDER);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
offsets: {
|
offsets: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue