diff --git a/database/seeders/UsersRoleMenuSeeder.php b/database/seeders/UsersRoleMenuSeeder.php index 6cdc016..867922d 100644 --- a/database/seeders/UsersRoleMenuSeeder.php +++ b/database/seeders/UsersRoleMenuSeeder.php @@ -195,7 +195,7 @@ class UsersRoleMenuSeeder extends Seeder ], [ "name" => "Tata Ruang", - "url" => "spatial-plannings.index", + "url" => "web-spatial-plannings.index", "icon" => null, "parent_id" => $data->id, "sort_order" => 6, diff --git a/resources/js/data/spatialPlannings/form-create-update.js b/resources/js/data/spatialPlannings/form-create-update.js index f65687e..5ff395e 100644 --- a/resources/js/data/spatialPlannings/form-create-update.js +++ b/resources/js/data/spatialPlannings/form-create-update.js @@ -73,7 +73,7 @@ document.addEventListener("DOMContentLoaded", function () { }, 3000); setTimeout(() => { - window.location.href = "/data/spatial-plannings"; + window.location.href = "/data/web-spatial-plannings"; }, 3000); } else { if (authLogo) { diff --git a/resources/js/data/spatialPlannings/form-upload.js b/resources/js/data/spatialPlannings/form-upload.js index 4383f54..10bb5bc 100644 --- a/resources/js/data/spatialPlannings/form-upload.js +++ b/resources/js/data/spatialPlannings/form-upload.js @@ -18,58 +18,61 @@ console.log(dropzonePreviewNode); url: `${GlobalConfig.apiHost}/api/spatial-plannings/import`, // url: "https://httpbin.org/post", method: "post", - acceptedFiles: ".xls,.xlsx", // Use acceptedFiles for better validation + acceptedFiles: ".xls,.xlsx", // Use acceptedFiles for better validation previewTemplate: previewTemplate, previewsContainer: "#dropzone-preview", - autoProcessQueue: false, // Disable auto post + autoProcessQueue: false, // Disable auto post headers: { Authorization: `Bearer ${document .querySelector('meta[name="api-token"]') - .getAttribute("content")}` + .getAttribute("content")}`, }, - init: function() { + init: function () { // Listen for the success event - this.on("success", function(file, response) { + this.on("success", function (file, response) { console.log("File successfully uploaded:", file); console.log("API Response:", response); - + // Show success toast - showToast('bxs-check-square', 'green', response.message); - document.getElementById("submit-upload").innerHTML = "Upload Files"; + showToast("bxs-check-square", "green", response.message); + document.getElementById("submit-upload").innerHTML = + "Upload Files"; // Tunggu sebentar lalu reload halaman setTimeout(() => { - window.location.href = "/data/spatial-plannings"; + window.location.href = "/data/web-spatial-plannings"; }, 2000); }); // Listen for the error event - this.on("error", function(file, errorMessage) { + this.on("error", function (file, errorMessage) { console.error("Error uploading file:", file); console.error("Error message:", errorMessage); // Handle the error response // Show error toast - showToast('bxs-error-alt', 'red', errorMessage.message); - document.getElementById("submit-upload").innerHTML = "Upload Files"; + showToast("bxs-error-alt", "red", errorMessage.message); + document.getElementById("submit-upload").innerHTML = + "Upload Files"; }); - } + }, }))); // Add event listener to control the submission manually -document.querySelector("#submit-upload").addEventListener("click", function() { +document.querySelector("#submit-upload").addEventListener("click", function () { console.log("Ini adalah value dropzone", dropzone.files[0]); - const formData = new FormData() - console.log("Dropzonefiles",dropzone.files); + const formData = new FormData(); + console.log("Dropzonefiles", dropzone.files); - this.innerHTML = 'Loading...'; + this.innerHTML = + 'Loading...'; // Pastikan ada file dalam queue sebelum memprosesnya if (dropzone.files.length > 0) { - formData.append('file', dropzone.files[0]) + formData.append("file", dropzone.files[0]); console.log("ini adalah form data on submit", ...formData); - dropzone.processQueue(); // Ini akan manual memicu upload + dropzone.processQueue(); // Ini akan manual memicu upload } else { // Show error toast when no file is selected - showToast('bxs-error-alt', 'red', "Please add a file first."); + showToast("bxs-error-alt", "red", "Please add a file first."); document.getElementById("submit-upload").innerHTML = "Upload Files"; } }); @@ -82,63 +85,69 @@ dropzone.on("addedfile", function (file) { console.log("Ukuran File:", (file.size / 1024).toFixed(2) + " KB"); }); -dropzone.on("complete", function(file) { +dropzone.on("complete", function (file) { dropzone.removeFile(file); }); // Add event listener to download file template -document.getElementById('downloadtempspatialPlannings').addEventListener('click', function() { - var url = `${GlobalConfig.apiHost}/api/download-template-spatialPlannings`; - fetch(url, { - method: 'GET', - headers: { - Authorization: `Bearer ${document - .querySelector('meta[name="api-token"]') - .getAttribute("content")}` - }, - }) - .then(response => { - if (response.ok) { - return response.blob(); // Jika respons OK, konversi menjadi blob - } else { - return response.json(); // Jika respons gagal, konversi menjadi JSON untuk menangani pesan error - } - }) - .then((blob) => { - console.log(blob); - const url = window.URL.createObjectURL(blob); - const a = document.createElement('a'); - a.style.display = 'none'; - a.href = url; - a.download = 'template_rencana_tata_ruang.xlsx'; - document.body.appendChild(a); - a.click(); - window.URL.revokeObjectURL(url); - }) - .catch((error) => { - console.error("Gagal mendownload file:", error); - showToast('bxs-error-alt', 'red', "Template file is not already exist."); - }) -}) +document + .getElementById("downloadtempspatialPlannings") + .addEventListener("click", function () { + var url = `${GlobalConfig.apiHost}/api/download-template-spatialPlannings`; + fetch(url, { + method: "GET", + headers: { + Authorization: `Bearer ${document + .querySelector('meta[name="api-token"]') + .getAttribute("content")}`, + }, + }) + .then((response) => { + if (response.ok) { + return response.blob(); // Jika respons OK, konversi menjadi blob + } else { + return response.json(); // Jika respons gagal, konversi menjadi JSON untuk menangani pesan error + } + }) + .then((blob) => { + console.log(blob); + const url = window.URL.createObjectURL(blob); + const a = document.createElement("a"); + a.style.display = "none"; + a.href = url; + a.download = "template_rencana_tata_ruang.xlsx"; + document.body.appendChild(a); + a.click(); + window.URL.revokeObjectURL(url); + }) + .catch((error) => { + console.error("Gagal mendownload file:", error); + showToast( + "bxs-error-alt", + "red", + "Template file is not already exist." + ); + }); + }); // Function to show toast function showToast(iconClass, iconColor, message) { - const toastElement = document.getElementById('toastUploadSpatialPlannings'); - const toastBody = toastElement.querySelector('.toast-body'); - const toastHeader = toastElement.querySelector('.toast-header'); + const toastElement = document.getElementById("toastUploadSpatialPlannings"); + const toastBody = toastElement.querySelector(".toast-body"); + const toastHeader = toastElement.querySelector(".toast-header"); // Remove existing icon (if any) before adding the new one - const existingIcon = toastHeader.querySelector('.bx'); + const existingIcon = toastHeader.querySelector(".bx"); if (existingIcon) { - toastHeader.querySelector('.auth-logo').removeChild(existingIcon); // Remove the existing icon + toastHeader.querySelector(".auth-logo").removeChild(existingIcon); // Remove the existing icon } // Add the new icon to the toast header - const icon = document.createElement('i'); - icon.classList.add('bx', iconClass); - icon.style.fontSize = '25px'; + const icon = document.createElement("i"); + icon.classList.add("bx", iconClass); + icon.style.fontSize = "25px"; icon.style.color = iconColor; - toastHeader.querySelector('.auth-logo').appendChild(icon); + toastHeader.querySelector(".auth-logo").appendChild(icon); // Set the toast message toastBody.textContent = message; @@ -147,4 +156,3 @@ function showToast(iconClass, iconColor, message) { const toast = new bootstrap.Toast(toastElement); // Inisialisasi Bootstrap Toast toast.show(); } - diff --git a/routes/web.php b/routes/web.php index 7a74358..38a5813 100755 --- a/routes/web.php +++ b/routes/web.php @@ -97,7 +97,7 @@ Route::group(['middleware' => 'auth'], function(){ Route::get('/tourisms/bulk-create', [TourismController::class, 'bulkCreate'])->name('tourisms.bulk-create'); // Resource route, kecuali create karena dibuat terpisah - Route::resource('/spatial-plannings', SpatialPlanningController::class)->except(['create', 'show']); + Route::resource('/we-spatial-plannings', SpatialPlanningController::class)->except(['create', 'show']); // Rute khusus untuk create dan bulk-create Route::get('/spatial-plannings/create', [SpatialPlanningController::class, 'create'])->name('tourisms.create'); Route::get('/spatial-plannings/bulk-create', [SpatialPlanningController::class, 'bulkCreate'])->name('tourisms.bulk-create');