mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 05:43:32 -07:00
feat: Introduce 'By Shown File Order' priority in WebUI
This commit is contained in:
parent
794310dca9
commit
32099095f7
3 changed files with 54 additions and 2 deletions
|
@ -269,6 +269,7 @@
|
|||
<li><a href="#FilePrioNormal"><span style="display: inline-block; width: 16px;"></span> QBT_TR(Normal)QBT_TR[CONTEXT=PropListDelegate]</a></li>
|
||||
<li><a href="#FilePrioHigh"><span style="display: inline-block; width: 16px;"></span> QBT_TR(High)QBT_TR[CONTEXT=PropListDelegate]</a></li>
|
||||
<li><a href="#FilePrioMaximum"><span style="display: inline-block; width: 16px;"></span> QBT_TR(Maximum)QBT_TR[CONTEXT=PropListDelegate]</a></li>
|
||||
<li><a href="#FilePrioByShownOrder"><span style="display: inline-block; width: 16px;"></span> QBT_TR(By shown file order)QBT_TR[CONTEXT=PropListDelegate]</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -45,7 +45,8 @@ window.qBittorrent.FileTree ??= (() => {
|
|||
Normal: 1,
|
||||
High: 6,
|
||||
Maximum: 7,
|
||||
Mixed: -1
|
||||
Mixed: -1,
|
||||
ByShownOrder: -2
|
||||
};
|
||||
Object.freeze(FilePriority);
|
||||
|
||||
|
|
|
@ -478,7 +478,54 @@ window.qBittorrent.PropFiles ??= (() => {
|
|||
});
|
||||
}
|
||||
|
||||
setFilePriority(Object.keys(uniqueRowIds), Object.keys(uniqueFileIds), priority);
|
||||
// Will be used both in general case and ByShownOrder case
|
||||
const filesLen = Object.keys(uniqueFileIds).length;
|
||||
const priorityList = {};
|
||||
Object.values(FilePriority).forEach((p) => {
|
||||
priorityList[p] = [];
|
||||
});
|
||||
const priorityGroupSize = Math.max(Math.floor(filesLen / 3), 1);
|
||||
const uniqueFileKeys = Object.keys(uniqueFileIds);
|
||||
const uniqueRowKeys = Object.keys(uniqueRowIds);
|
||||
|
||||
// Will be altered only if we select ByShownOrder, use whatever is passed otherwise
|
||||
let priorityGroup = priority;
|
||||
let fileId = 0;
|
||||
let rowId = 0;
|
||||
for (let i = 0; i < filesLen; ++i) {
|
||||
fileId = uniqueFileKeys[i];
|
||||
rowId = uniqueRowKeys[i];
|
||||
// Calculate priority based on order
|
||||
if (priority === FilePriority.ByShownOrder) {
|
||||
switch (Math.floor(i / priorityGroupSize)) {
|
||||
case 0:
|
||||
priorityGroup = FilePriority.Maximum;
|
||||
break;
|
||||
case 1:
|
||||
priorityGroup = FilePriority.High;
|
||||
break;
|
||||
default:
|
||||
case 2:
|
||||
priorityGroup = FilePriority.Normal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Or if we use one of the simpler priorities, just push in the same group
|
||||
priorityList[priorityGroup].push({
|
||||
fileId: fileId,
|
||||
rowId: rowId
|
||||
});
|
||||
}
|
||||
|
||||
Object.entries(priorityList).forEach(([groupPriority, groupedFileRowPair]) => {
|
||||
if (groupedFileRowPair.length === 0)
|
||||
return;
|
||||
setFilePriority(
|
||||
groupedFileRowPair.map(pair => pair.rowId),
|
||||
groupedFileRowPair.map(pair => pair.fileId),
|
||||
groupPriority
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const singleFileRename = (hash) => {
|
||||
|
@ -553,6 +600,9 @@ window.qBittorrent.PropFiles ??= (() => {
|
|||
},
|
||||
FilePrioMaximum: (element, ref) => {
|
||||
filesPriorityMenuClicked(FilePriority.Maximum);
|
||||
},
|
||||
FilePrioByShownOrder: (element, ref) => {
|
||||
filesPriorityMenuClicked(FilePriority.ByShownOrder);
|
||||
}
|
||||
},
|
||||
offsets: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue