fix handle retry button
This commit is contained in:
@@ -27,6 +27,7 @@ class BigdataResume {
|
||||
this.table = new Grid({
|
||||
columns: [
|
||||
{ name: "ID" },
|
||||
{ name: "Year" },
|
||||
{ name: "Jumlah Potensi" },
|
||||
{ name: "Total Potensi" },
|
||||
{ name: "Jumlah Berkas Belum Terverifikasi" },
|
||||
@@ -79,6 +80,7 @@ class BigdataResume {
|
||||
then: (data) => {
|
||||
return data.data.map((item) => [
|
||||
item.id,
|
||||
item.year,
|
||||
item.potention_count,
|
||||
addThousandSeparators(item.potention_sum),
|
||||
item.non_verified_count,
|
||||
|
||||
@@ -28,6 +28,19 @@ class SyncronizeTask {
|
||||
"Duration",
|
||||
"Finished",
|
||||
"Created",
|
||||
{
|
||||
name: "Action",
|
||||
formatter: (cell) => {
|
||||
if (cell.status === "failed") {
|
||||
return gridjs.html(`
|
||||
<button data-id="${cell.id}" class="btn btn-sm btn-warning d-flex align-items-center gap-1 btn-retry">
|
||||
<iconify-icon icon="mingcute:refresh-3-line" width="15" height="15"></iconify-icon>
|
||||
<span>Retry</span>
|
||||
</button>
|
||||
`);
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
search: {
|
||||
server: {
|
||||
@@ -62,10 +75,20 @@ class SyncronizeTask {
|
||||
item.duration,
|
||||
item.finish_time,
|
||||
item.created_at,
|
||||
item,
|
||||
]),
|
||||
total: (data) => data.meta.total,
|
||||
},
|
||||
}).render(tableContainer);
|
||||
|
||||
tableContainer.addEventListener("click", (event) => {
|
||||
let btn = event.target.closest(".btn-retry");
|
||||
if (btn) {
|
||||
const id = btn.getAttribute("data-id");
|
||||
btn.disabled = true;
|
||||
this.handleRetrySync(id, btn);
|
||||
}
|
||||
});
|
||||
}
|
||||
handleSubmitSync() {
|
||||
const button = document.getElementById("btn-sync-submit");
|
||||
@@ -117,6 +140,48 @@ class SyncronizeTask {
|
||||
});
|
||||
}
|
||||
|
||||
handleRetrySync(id, btn) {
|
||||
const apiToken = document
|
||||
.querySelector('meta[name="api-token"]')
|
||||
.getAttribute("content");
|
||||
|
||||
fetch(`${GlobalConfig.apiHost}/api/retry-scraping/${id}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then(async (response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
console.log("API Response:", data); // Debugging
|
||||
|
||||
// Show success message
|
||||
const message =
|
||||
data?.data?.message ||
|
||||
data?.message ||
|
||||
"Synchronization successful!";
|
||||
this.toastMessage.innerText = message;
|
||||
this.toast.show();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Fetch error:", err);
|
||||
|
||||
// Show error message
|
||||
this.toastMessage.innerText =
|
||||
err.message ||
|
||||
"Failed to synchronize, something went wrong!";
|
||||
this.toast.show();
|
||||
|
||||
// Re-enable button on failure
|
||||
btn.disabled = false;
|
||||
});
|
||||
}
|
||||
handleSyncClick() {
|
||||
const button = document.getElementById("btn-sync-submit");
|
||||
const spinner = document.getElementById("spinner");
|
||||
|
||||
Reference in New Issue
Block a user