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

@@ -37,7 +37,9 @@ class UsersTable {
url: `${GlobalConfig.apiHost}/api/users`,
credentials: "include",
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
Authorization: `Bearer ${document
.querySelector('meta[name="api-token"]')
.getAttribute("content")}`,
"Content-Type": "application/json",
},
then: (data) =>

View File

@@ -11,15 +11,15 @@ class RequestAssignment {
new Grid({
columns: [
"ID",
"Name",
"Condition",
{name: "Name", width: "15%"},
{name: "Condition", width: "7%"},
"Registration Number",
"Document Number",
"Address",
{name: "Address", width: "30%"},
"Status",
"Function Type",
"Consultation Type",
"Due Date",
{name: "Due Date", width: "7%"},
],
search: {
server: {
@@ -40,7 +40,9 @@ class RequestAssignment {
url: `${GlobalConfig.apiHost}/api/request-assignments`,
credentials: "include",
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
Authorization: `Bearer ${document
.querySelector('meta[name="api-token"]')
.getAttribute("content")}`,
"Content-Type": "application/json",
},
then: (data) =>

View File

@@ -22,8 +22,8 @@ class SyncronizeTask {
console.log("cell data", cell);
return gridjs.html(`
<div class="d-flex justify-items-end gap-10">
<a href="/settings/general/${cell}/edit" class="btn btn-warning me-2">Update</a>
<button class="btn btn-delete btn-delete-global-settings" data-id="${cell}">Delete</button>
<a href="/settings/general/${cell}/edit" class="btn btn-yellow me-2">Update</a>
<button class="btn btn-red btn-delete btn-delete-global-settings" data-id="${cell}">Delete</button>
</div>
`);
},

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) {