mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-06-27 17:09:53 -04:00
WebUI: Add ability to refresh search
WebUI equivalent of #22122. Refreshing maintains all existing filters. PR #22805.
This commit is contained in:
parent
526abdf7ce
commit
5dfb51a8d2
2 changed files with 67 additions and 0 deletions
|
@ -90,6 +90,7 @@ window.qBittorrent.Search ??= (() => {
|
|||
targets: ".searchTab",
|
||||
menu: "searchResultsTabsMenu",
|
||||
actions: {
|
||||
refreshTab: (tab) => { refreshSearch(tab); },
|
||||
closeTab: (tab) => { closeSearchTab(tab); },
|
||||
closeAllTabs: () => {
|
||||
for (const tab of document.querySelectorAll("#searchTabs .searchTab"))
|
||||
|
@ -233,6 +234,41 @@ window.qBittorrent.Search ??= (() => {
|
|||
updateSearchResultsData(searchId);
|
||||
};
|
||||
|
||||
const refreshSearchTab = (oldSearchId, searchId, pattern) => {
|
||||
fetch("api/v2/search/delete", {
|
||||
method: "POST",
|
||||
body: new URLSearchParams({
|
||||
id: oldSearchId
|
||||
})
|
||||
});
|
||||
|
||||
const searchJobs = JSON.parse(LocalPreferences.get("search_jobs", "[]"));
|
||||
const jobIndex = searchJobs.findIndex((job) => job.id === oldSearchId);
|
||||
if (jobIndex >= 0) {
|
||||
searchJobs[jobIndex].id = searchId;
|
||||
LocalPreferences.set("search_jobs", JSON.stringify(searchJobs));
|
||||
}
|
||||
|
||||
// update existing tab w/ new search id
|
||||
const tab = document.getElementById(`${searchTabIdPrefix}${oldSearchId}`);
|
||||
tab.id = `${searchTabIdPrefix}${searchId}`;
|
||||
|
||||
updateStatusIconElement(searchId, "QBT_TR(Searching...)QBT_TR[CONTEXT=SearchJobWidget]", "images/queued.svg");
|
||||
|
||||
// copy over relevant state
|
||||
const state = searchState.get(oldSearchId);
|
||||
state.rows = [];
|
||||
state.rowId = 0;
|
||||
state.selectedRowIds = [];
|
||||
state.running = true;
|
||||
state.loadResultsTimer = -1;
|
||||
searchState.set(searchId, state);
|
||||
searchState.delete(oldSearchId);
|
||||
|
||||
searchResultsTable.clear();
|
||||
updateSearchResultsData(searchId);
|
||||
};
|
||||
|
||||
const closeSearchTab = (el) => {
|
||||
const tab = el.closest("li.searchTab");
|
||||
if (!tab)
|
||||
|
@ -421,6 +457,36 @@ window.qBittorrent.Search ??= (() => {
|
|||
});
|
||||
};
|
||||
|
||||
const refreshSearch = (el) => {
|
||||
const tab = el.closest("li.searchTab");
|
||||
if (!tab)
|
||||
return;
|
||||
|
||||
const oldSearchId = getSearchIdFromTab(tab);
|
||||
const state = searchState.get(oldSearchId);
|
||||
const pattern = state.searchPattern;
|
||||
|
||||
searchPatternChanged = false;
|
||||
fetch("api/v2/search/start", {
|
||||
method: "POST",
|
||||
body: new URLSearchParams({
|
||||
pattern: state.searchPattern,
|
||||
category: document.getElementById("categorySelect").value,
|
||||
plugins: document.getElementById("pluginsSelect").value
|
||||
})
|
||||
})
|
||||
.then(async (response) => {
|
||||
if (!response.ok)
|
||||
return;
|
||||
|
||||
const responseJSON = await response.json();
|
||||
|
||||
document.getElementById("startSearchButton").lastChild.textContent = "QBT_TR(Stop)QBT_TR[CONTEXT=SearchEngineWidget]";
|
||||
const searchId = responseJSON.id;
|
||||
refreshSearchTab(oldSearchId, searchId, pattern);
|
||||
});
|
||||
};
|
||||
|
||||
const stopSearch = (searchId) => {
|
||||
fetch("api/v2/search/stop", {
|
||||
method: "POST",
|
||||
|
|
|
@ -215,6 +215,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
<ul id="searchResultsTabsMenu" class="contextMenu">
|
||||
<li><a href="#refreshTab">QBT_TR(Refresh tab)QBT_TR[CONTEXT=SearchJobWidget]</a></li>
|
||||
<li><a href="#closeTab">QBT_TR(Close tab)QBT_TR[CONTEXT=SearchJobWidget]</a></li>
|
||||
<li><a href="#closeAllTabs">QBT_TR(Close all tabs)QBT_TR[CONTEXT=SearchJobWidget]</a></li>
|
||||
</ul>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue