This commit is contained in:
Michael Beck 2025-06-11 23:48:46 +02:00
parent 8f84774880
commit 793f6f9a7e

View File

@ -8,7 +8,6 @@ class PaperProcessor {
this.searchForm = document.getElementById("searchPaperForm");
this.searchInput = document.getElementById("paperSearchInput");
this.searchResults = document.getElementById("searchResults");
this.processingStatus = document.getElementById("processingStatus");
this.paperSearchResults = document.getElementById("paperSearchResults");
this.scraperSelect = document.getElementById("scraperSelect");
@ -153,16 +152,15 @@ class PaperProcessor {
* @param {string} paperId - The ID of the paper to process
*/
async processSinglePaper(paperId) {
if (!this.processingStatus || !this.scraperSelect) return;
if (!this.scraperSelect) return;
// Disable all process buttons to prevent multiple clicks
document.querySelectorAll(".process-paper-btn").forEach((btn) => {
btn.disabled = true;
});
// Show processing status
this.processingStatus.textContent = "Processing paper...";
this.processingStatus.classList.remove("d-none");
// Show processing status via flash message
showFlashMessage("Processing paper...", "info");
// Get selected scraper
const selectedScraper = this.scraperSelect.value;
@ -176,9 +174,6 @@ class PaperProcessor {
});
if (data.success) {
this.processingStatus.textContent = data.message;
this.processingStatus.className = "alert alert-success mt-3";
// Update status in the search results
const row = document
.querySelector(`.process-paper-btn[data-paper-id="${paperId}"]`)
@ -190,20 +185,16 @@ class PaperProcessor {
}
}
// Show notification
// Show success notification
showFlashMessage(data.message, "success");
// Set up polling to check paper status and refresh activity
this.pollPaperStatus(paperId, 3000, 20);
} else {
this.processingStatus.textContent = data.message;
this.processingStatus.className = "alert alert-danger mt-3";
showFlashMessage(data.message, "error");
}
} catch (error) {
console.error("Error processing paper:", error);
this.processingStatus.textContent = "Error: Could not process paper";
this.processingStatus.className = "alert alert-danger mt-3";
showFlashMessage("Error processing paper", "error");
} finally {
// Re-enable the process buttons after a short delay
@ -257,13 +248,11 @@ class PaperProcessor {
// Update processing status message if status changed
if (paper.status !== "Pending") {
if (paper.status === "Done") {
this.processingStatus.textContent = `Paper processed successfully: ${paper.title}`;
this.processingStatus.className = "alert alert-success mt-3";
showFlashMessage(`Paper processed successfully: ${paper.title}`, "success");
} else if (paper.status === "Failed") {
this.processingStatus.textContent = `Paper processing failed: ${
showFlashMessage(`Paper processing failed: ${
paper.error_msg || "Unknown error"
}`;
this.processingStatus.className = "alert alert-danger mt-3";
}`, "error");
}
}
}
@ -282,23 +271,12 @@ class PaperProcessor {
this.onChartRefresh();
}
// Show notification if status changed
if (paper.status !== "Pending") {
const status = paper.status === "Done" ? "success" : "error";
const message =
paper.status === "Done"
? `Paper processed successfully: ${paper.title}`
: `Paper processing failed: ${
paper.error_msg || "Unknown error"
}`;
showFlashMessage(message, status);
}
// If we hit max attempts but status is still pending, show a message
if (paper.status === "Pending" && attempts >= maxAttempts) {
this.processingStatus.textContent =
"Paper is still being processed. Check the activity log for updates.";
this.processingStatus.className = "alert alert-info mt-3";
showFlashMessage(
"Paper is still being processed. Check the activity log for updates.",
"info"
);
}
}
}