Skip to content

Commit f30c2b0

Browse files
committed
Refactor Prowlarr status handling and indexers display
- Updated the loadProwlarrStatus method to streamline the display logic for the Prowlarr status card, ensuring it only shows when configured and enabled. - Introduced a new loadProwlarrStats method to fetch detailed indexer statistics and update the indexers list accordingly. - Enhanced the updateIndexersList method to handle error messages and display indexer statuses more effectively. - Removed the outdated status legend from the home section to simplify the UI.
1 parent 8df99b4 commit f30c2b0

File tree

2 files changed

+98
-173
lines changed

2 files changed

+98
-173
lines changed

frontend/static/js/new-main.js

Lines changed: 97 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,13 +2320,14 @@ let huntarrUI = {
23202320

23212321
// Load and update Prowlarr status card
23222322
loadProwlarrStatus: function() {
2323+
const prowlarrCard = document.getElementById('prowlarrStatusCard');
2324+
if (!prowlarrCard) return;
2325+
2326+
// First check if Prowlarr is configured and enabled
23232327
HuntarrUtils.fetchWithTimeout('./api/prowlarr/status')
23242328
.then(response => response.json())
23252329
.then(statusData => {
2326-
const prowlarrCard = document.getElementById('prowlarrStatusCard');
2327-
if (!prowlarrCard) return;
2328-
2329-
// Show/hide card based on whether Prowlarr is configured and enabled
2330+
// Only show card if Prowlarr is configured and enabled
23302331
if (statusData.configured && statusData.enabled) {
23312332
prowlarrCard.style.display = 'block';
23322333

@@ -2335,7 +2336,7 @@ let huntarrUI = {
23352336
if (statusElement) {
23362337
if (statusData.connected) {
23372338
statusElement.textContent = '🟢 Connected';
2338-
statusElement.className = 'status-badge success';
2339+
statusElement.className = 'status-badge connected';
23392340
} else {
23402341
statusElement.textContent = '🔴 Disconnected';
23412342
statusElement.className = 'status-badge error';
@@ -2346,29 +2347,23 @@ let huntarrUI = {
23462347
if (statusData.connected) {
23472348
this.loadProwlarrStats();
23482349
} else {
2349-
// Show disconnected state
2350-
this.updateProwlarrStatsDisplay({
2351-
active_indexers: '--',
2352-
total_api_calls: '--',
2353-
throttled_indexers: '--',
2354-
failed_indexers: '--',
2355-
health_status: 'Disconnected'
2356-
});
2350+
// Show disconnected state in indexers list
2351+
this.updateIndexersList(null, 'Prowlarr is disconnected');
23572352
}
23582353

23592354
// Setup refresh button
23602355
this.setupProwlarrRefreshButton();
23612356

23622357
} else {
2358+
// Hide card if not configured or disabled
23632359
prowlarrCard.style.display = 'none';
2360+
console.log('[huntarrUI] Prowlarr card hidden - configured:', statusData.configured, 'enabled:', statusData.enabled);
23642361
}
23652362
})
23662363
.catch(error => {
23672364
console.error('Error loading Prowlarr status:', error);
2368-
const prowlarrCard = document.getElementById('prowlarrStatusCard');
2369-
if (prowlarrCard) {
2370-
prowlarrCard.style.display = 'none';
2371-
}
2365+
// Hide card on error
2366+
prowlarrCard.style.display = 'none';
23722367
});
23732368
},
23742369

@@ -2435,6 +2430,91 @@ let huntarrUI = {
24352430
}
24362431
},
24372432

2433+
// Load detailed Prowlarr statistics
2434+
loadProwlarrStats: function() {
2435+
HuntarrUtils.fetchWithTimeout('./api/prowlarr/stats')
2436+
.then(response => response.json())
2437+
.then(data => {
2438+
if (data.success && data.stats) {
2439+
// Update indexers list with detailed stats
2440+
this.updateIndexersList(data.stats.indexer_details);
2441+
} else {
2442+
console.error('Failed to load Prowlarr stats:', data.error);
2443+
this.updateIndexersList(null, data.error || 'Failed to load stats');
2444+
}
2445+
})
2446+
.catch(error => {
2447+
console.error('Error loading Prowlarr stats:', error);
2448+
this.updateIndexersList(null, 'Connection error');
2449+
});
2450+
},
2451+
2452+
// Update indexers list display
2453+
updateIndexersList: function(indexerDetails, errorMessage = null) {
2454+
const indexersList = document.getElementById('prowlarr-indexers-list');
2455+
if (!indexersList) return;
2456+
2457+
if (errorMessage) {
2458+
// Show error state
2459+
indexersList.innerHTML = `<div class="loading-text" style="color: #ef4444;">${errorMessage}</div>`;
2460+
return;
2461+
}
2462+
2463+
if (!indexerDetails || (!indexerDetails.active && !indexerDetails.throttled && !indexerDetails.failed)) {
2464+
// No indexers found
2465+
indexersList.innerHTML = '<div class="loading-text">No indexers configured</div>';
2466+
return;
2467+
}
2468+
2469+
// Combine all indexers and sort alphabetically
2470+
let allIndexers = [];
2471+
2472+
// Add active indexers
2473+
if (indexerDetails.active) {
2474+
allIndexers = allIndexers.concat(
2475+
indexerDetails.active.map(idx => ({ ...idx, status: 'active' }))
2476+
);
2477+
}
2478+
2479+
// Add throttled indexers
2480+
if (indexerDetails.throttled) {
2481+
allIndexers = allIndexers.concat(
2482+
indexerDetails.throttled.map(idx => ({ ...idx, status: 'throttled' }))
2483+
);
2484+
}
2485+
2486+
// Add failed indexers
2487+
if (indexerDetails.failed) {
2488+
allIndexers = allIndexers.concat(
2489+
indexerDetails.failed.map(idx => ({ ...idx, status: 'failed' }))
2490+
);
2491+
}
2492+
2493+
// Sort alphabetically by name
2494+
allIndexers.sort((a, b) => a.name.localeCompare(b.name));
2495+
2496+
if (allIndexers.length === 0) {
2497+
indexersList.innerHTML = '<div class="loading-text">No indexers found</div>';
2498+
return;
2499+
}
2500+
2501+
// Build the HTML for indexers list
2502+
const indexersHtml = allIndexers.map(indexer => {
2503+
const statusText = indexer.status === 'active' ? 'Active' :
2504+
indexer.status === 'throttled' ? 'Throttled' :
2505+
'Failed';
2506+
2507+
return `
2508+
<div class="indexer-item">
2509+
<span class="indexer-name">${indexer.name}</span>
2510+
<span class="indexer-status ${indexer.status}">${statusText}</span>
2511+
</div>
2512+
`;
2513+
}).join('');
2514+
2515+
indexersList.innerHTML = indexersHtml;
2516+
},
2517+
24382518
// Setup Prowlarr refresh button
24392519
setupProwlarrRefreshButton: function() {
24402520
const refreshButton = document.getElementById('refresh-prowlarr-data');
@@ -4669,145 +4749,7 @@ let huntarrUI = {
46694749
}
46704750
},
46714751

4672-
// Load and update Prowlarr status card
4673-
loadProwlarrStatus: function() {
4674-
console.log('[huntarrUI] Loading Prowlarr status');
4675-
4676-
HuntarrUtils.fetchWithTimeout('./api/prowlarr/stats')
4677-
.then(response => response.json())
4678-
.then(data => {
4679-
console.log('[huntarrUI] Prowlarr stats received:', data);
4680-
4681-
const prowlarrCard = document.getElementById('prowlarrStatusCard');
4682-
if (!prowlarrCard) {
4683-
console.log('[huntarrUI] Prowlarr card not found in DOM');
4684-
return;
4685-
}
46864752

4687-
if (data.success && data.stats) {
4688-
const stats = data.stats;
4689-
4690-
// Show the card since we have data
4691-
prowlarrCard.style.display = 'block';
4692-
4693-
// Update connection status
4694-
const connectionStatus = document.getElementById('prowlarrConnectionStatus');
4695-
if (connectionStatus) {
4696-
if (stats.connected) {
4697-
connectionStatus.textContent = '🟢 Connected';
4698-
connectionStatus.className = 'status-badge connected';
4699-
} else {
4700-
connectionStatus.textContent = '🔴 Disconnected';
4701-
connectionStatus.className = 'status-badge disconnected';
4702-
}
4703-
}
4704-
4705-
// Update indexers list
4706-
this.updateIndexersList(stats.indexer_details)
4707-
4708-
} else {
4709-
// Handle error case
4710-
console.log('[huntarrUI] Error in Prowlarr stats:', data.message || 'Unknown error');
4711-
4712-
// Still show the card but with error states
4713-
prowlarrCard.style.display = 'block';
4714-
4715-
const connectionStatus = document.getElementById('prowlarrConnectionStatus');
4716-
if (connectionStatus) {
4717-
connectionStatus.textContent = '🔴 Error';
4718-
connectionStatus.className = 'status-badge error';
4719-
}
4720-
4721-
// Show error in indexers list
4722-
this.updateIndexersList(null, data.message || 'Connection error');
4723-
}
4724-
})
4725-
.catch(error => {
4726-
console.error('[huntarrUI] Error loading Prowlarr status:', error);
4727-
4728-
// Show the card with error state
4729-
const prowlarrCard = document.getElementById('prowlarrStatusCard');
4730-
if (prowlarrCard) {
4731-
prowlarrCard.style.display = 'block';
4732-
4733-
// Update connection status to error
4734-
const connectionStatus = document.getElementById('prowlarrConnectionStatus');
4735-
if (connectionStatus) {
4736-
connectionStatus.textContent = '🔴 Error';
4737-
connectionStatus.className = 'status-badge error';
4738-
}
4739-
4740-
// Show error in indexers list
4741-
this.updateIndexersList(null, 'Failed to load Prowlarr data');
4742-
}
4743-
});
4744-
},
4745-
4746-
// Update indexers list display
4747-
updateIndexersList: function(indexerDetails, errorMessage = null) {
4748-
const indexersList = document.getElementById('prowlarr-indexers-list');
4749-
if (!indexersList) return;
4750-
4751-
if (errorMessage) {
4752-
// Show error state
4753-
indexersList.innerHTML = `<div class="loading-text" style="color: #ef4444;">${errorMessage}</div>`;
4754-
return;
4755-
}
4756-
4757-
if (!indexerDetails || (!indexerDetails.active && !indexerDetails.throttled && !indexerDetails.failed)) {
4758-
// No indexers found
4759-
indexersList.innerHTML = '<div class="loading-text">No indexers configured</div>';
4760-
return;
4761-
}
4762-
4763-
// Combine all indexers and sort alphabetically
4764-
let allIndexers = [];
4765-
4766-
// Add active indexers
4767-
if (indexerDetails.active) {
4768-
allIndexers = allIndexers.concat(
4769-
indexerDetails.active.map(idx => ({ ...idx, status: 'active' }))
4770-
);
4771-
}
4772-
4773-
// Add throttled indexers
4774-
if (indexerDetails.throttled) {
4775-
allIndexers = allIndexers.concat(
4776-
indexerDetails.throttled.map(idx => ({ ...idx, status: 'throttled' }))
4777-
);
4778-
}
4779-
4780-
// Add failed indexers
4781-
if (indexerDetails.failed) {
4782-
allIndexers = allIndexers.concat(
4783-
indexerDetails.failed.map(idx => ({ ...idx, status: 'failed' }))
4784-
);
4785-
}
4786-
4787-
// Sort alphabetically by name
4788-
allIndexers.sort((a, b) => a.name.localeCompare(b.name));
4789-
4790-
if (allIndexers.length === 0) {
4791-
indexersList.innerHTML = '<div class="loading-text">No indexers found</div>';
4792-
return;
4793-
}
4794-
4795-
// Build the HTML for indexers list
4796-
const indexersHtml = allIndexers.map(indexer => {
4797-
const statusText = indexer.status === 'active' ? 'Active' :
4798-
indexer.status === 'throttled' ? 'Throttled' :
4799-
'Failed';
4800-
4801-
return `
4802-
<div class="indexer-item">
4803-
<span class="indexer-name">${indexer.name}</span>
4804-
<span class="indexer-status ${indexer.status}">${statusText}</span>
4805-
</div>
4806-
`;
4807-
}).join('');
4808-
4809-
indexersList.innerHTML = indexersHtml;
4810-
}
48114753
};
48124754

48134755
// Note: redirectToSwaparr function removed - Swaparr now has its own dedicated section

frontend/templates/components/home_section.html

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -834,24 +834,7 @@ <h5><i class="fas fa-clock"></i> Statistics</h5>
834834
</div>
835835
</div>
836836

837-
<!-- Status Legend -->
838-
<div class="prowlarr-legend">
839-
<div class="legend-title">Status Legend:</div>
840-
<div class="legend-items">
841-
<div class="legend-item">
842-
<span class="indexer-status active">Active</span>
843-
<span class="legend-description">Indexer is working normally</span>
844-
</div>
845-
<div class="legend-item">
846-
<span class="indexer-status throttled">Throttled</span>
847-
<span class="legend-description">Rate limited - reduce search frequency</span>
848-
</div>
849-
<div class="legend-item">
850-
<span class="indexer-status failed">Failed</span>
851-
<span class="legend-description">Disabled or not responding</span>
852-
</div>
853-
</div>
854-
</div>
837+
855838
</div>
856839

857840
</div>

0 commit comments

Comments
 (0)