fix handle token login when loop and fix width column on task fix color default danger success scss, fix add timeout on php.ini, add scraping for execute from api, add check api for handle disabled button sync

This commit is contained in:
arifal
2025-01-31 18:01:27 +07:00
parent d70fefb12d
commit dae0cd481d
15 changed files with 233 additions and 90 deletions

View File

@@ -6,7 +6,7 @@ import GlobalConfig from "../../global-config.js";
class SyncronizeTask {
init() {
this.initTableImportDatasources();
this.onSyncSubmit();
this.handleSubmitSync();
}
initTableImportDatasources() {
new Grid({
@@ -46,20 +46,71 @@ class SyncronizeTask {
},
}).render(document.getElementById("table-import-datasources"));
}
onSyncSubmit() {
const form = document.getElementById("sync-form");
if (form) {
form.addEventListener("submit", function (event) {
event.preventDefault(); // Prevent the default form submission
const button = document.getElementById("btn-sync-submit");
if (button) {
button.disabled = true;
button.innerText = "Processing...";
}
form.submit();
});
}
handleSubmitSync() {
const button = document.getElementById("btn-sync-submit");
// Check if the button should be enabled or disabled based on the status
fetch(`${GlobalConfig.apiHost}/api/import-datasource/check-datasource`, {
method: "GET",
headers: {
Authorization: `Bearer ${document
.querySelector('meta[name="api-token"]')
.getAttribute("content")}`,
"Content-Type": "application/json",
}
})
.then(response => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
})
.then(data => {
console.log("data check button sync", data.can_execute);
button.disabled = !data.can_execute;
// If the button is enabled, add click event to trigger sync
if (!button.disabled) {
button.addEventListener("click", function(e) {
button.disabled = true; // Disable button to prevent multiple clicks
button.textContent = "Syncing..."; // Change button text to show syncing
// Trigger the scraping API call
fetch(`${GlobalConfig.apiHost}/api/scraping`, {
method: "GET",
headers: {
Authorization: `Bearer ${document
.querySelector('meta[name="api-token"]')
.getAttribute("content")}`,
"Content-Type": "application/json",
}
})
.then(response => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
})
.then(data => {
console.log("data sync button", data);
alert("Synchronization executed successfully");
window.location.reload();
})
.catch(err => {
console.error("Fetch error:", err);
alert("An error occurred during synchronization");
})
.finally(() => {
button.disabled = false; // Re-enable the button after the request is complete
button.textContent = "Sync Data"; // Reset button text
});
});
}
})
.catch(err => {
console.error("Fetch error:", err);
alert("An error occurred while checking the datasource");
});
}
}
document.addEventListener("DOMContentLoaded", function (e) {