fix route umkm
This commit is contained in:
@@ -60,7 +60,7 @@ class UmkmController extends Controller
|
||||
$modelInstance = Umkm::find($id);
|
||||
// Pastikan model ditemukan
|
||||
if (!$modelInstance) {
|
||||
return redirect()->route('umkm.index')->with('error', 'Umkm not found');
|
||||
return redirect()->route('web-umkm.index')->with('error', 'Umkm not found');
|
||||
}
|
||||
|
||||
// Mengambil dan memetakan village_name dan district_name
|
||||
|
||||
@@ -181,7 +181,7 @@ class UsersRoleMenuSeeder extends Seeder
|
||||
],
|
||||
[
|
||||
"name" => "UMKM",
|
||||
"url" => "umkm.index",
|
||||
"url" => "web-umkm.index",
|
||||
"icon" => null,
|
||||
"parent_id" => $data->id,
|
||||
"sort_order" => 4,
|
||||
|
||||
@@ -14,7 +14,7 @@ npm ci --no-audit --no-fund
|
||||
npm run build
|
||||
|
||||
echo "📦 Installing composer dependencies..."
|
||||
composer install --no-interaction --optimize-autoloader
|
||||
COMPOSER_ALLOW_SUPERUSER=1 composer install --no-interaction --optimize-autoloader
|
||||
|
||||
echo "🗄️ Running migrations..."
|
||||
php artisan migrate --force
|
||||
|
||||
@@ -16,10 +16,10 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
Loading...
|
||||
`;
|
||||
const isEdit = saveButton.classList.contains("btn-edit");
|
||||
const formData = new FormData(form)
|
||||
const toast = document.getElementById('toastEditUpdate');
|
||||
const toastBody = toast.querySelector('.toast-body');
|
||||
const toastHeader = toast.querySelector('.toast-header small');
|
||||
const formData = new FormData(form);
|
||||
const toast = document.getElementById("toastEditUpdate");
|
||||
const toastBody = toast.querySelector(".toast-body");
|
||||
const toastHeader = toast.querySelector(".toast-header small");
|
||||
|
||||
const data = {};
|
||||
|
||||
@@ -40,53 +40,88 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
.querySelector('meta[name="api-token"]')
|
||||
.getAttribute("content")}`,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
},
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log("Response data:", data);
|
||||
if (!data.errors) {
|
||||
// Remove existing icon (if any) before adding the new one
|
||||
if (authLogo) {
|
||||
// Hapus ikon yang sudah ada jika ada
|
||||
const existingIcon = authLogo.querySelector('.bx');
|
||||
if (existingIcon) {
|
||||
authLogo.removeChild(existingIcon);
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
console.log("Response data:", data);
|
||||
if (!data.errors) {
|
||||
// Remove existing icon (if any) before adding the new one
|
||||
if (authLogo) {
|
||||
// Hapus ikon yang sudah ada jika ada
|
||||
const existingIcon = authLogo.querySelector(".bx");
|
||||
if (existingIcon) {
|
||||
authLogo.removeChild(existingIcon);
|
||||
}
|
||||
|
||||
// Buat ikon baru
|
||||
const icon = document.createElement("i");
|
||||
icon.classList.add("bx", "bxs-check-square");
|
||||
icon.style.fontSize = "25px";
|
||||
icon.style.color = "green"; // Pastikan 'green' dalam bentuk string
|
||||
|
||||
// Tambahkan ikon ke dalam auth-logo
|
||||
authLogo.appendChild(icon);
|
||||
}
|
||||
|
||||
// Buat ikon baru
|
||||
const icon = document.createElement('i');
|
||||
icon.classList.add('bx', 'bxs-check-square');
|
||||
icon.style.fontSize = '25px';
|
||||
icon.style.color = 'green'; // Pastikan 'green' dalam bentuk string
|
||||
// Set success message for the toast
|
||||
toastBody.textContent = isEdit
|
||||
? "Data updated successfully!"
|
||||
: "Data created successfully!";
|
||||
toast.classList.add("show"); // Show the toast
|
||||
setTimeout(() => {
|
||||
toast.classList.remove("show"); // Hide the toast after 3 seconds
|
||||
}, 2000);
|
||||
|
||||
// Tambahkan ikon ke dalam auth-logo
|
||||
authLogo.appendChild(icon);
|
||||
setTimeout(() => {
|
||||
window.location.href = "/data/web-umkm";
|
||||
}, 1000);
|
||||
} else {
|
||||
if (authLogo) {
|
||||
// Hapus ikon yang sudah ada jika ada
|
||||
const existingIcon = authLogo.querySelector(".bx");
|
||||
if (existingIcon) {
|
||||
authLogo.removeChild(existingIcon);
|
||||
}
|
||||
|
||||
// Buat ikon baru
|
||||
const icon = document.createElement("i");
|
||||
icon.classList.add("bx", "bxs-error-alt");
|
||||
icon.style.fontSize = "25px";
|
||||
icon.style.color = "red"; // Pastikan 'green' dalam bentuk string
|
||||
|
||||
// Tambahkan ikon ke dalam auth-logo
|
||||
authLogo.appendChild(icon);
|
||||
}
|
||||
|
||||
// Enable button and reset its text on error
|
||||
modalButton.disabled = false;
|
||||
modalButton.innerHTML = isEdit ? "Update" : "Create";
|
||||
|
||||
// Set error message for the toast
|
||||
toastBody.textContent =
|
||||
"Error: " + (data.message || "Something went wrong");
|
||||
toast.classList.add("show"); // Show the toast
|
||||
|
||||
setTimeout(() => {
|
||||
toast.classList.remove("show"); // Hide the toast after 3 seconds
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
// Set success message for the toast
|
||||
toastBody.textContent = isEdit ? "Data updated successfully!" : "Data created successfully!";
|
||||
toast.classList.add('show'); // Show the toast
|
||||
setTimeout(() => {
|
||||
toast.classList.remove('show'); // Hide the toast after 3 seconds
|
||||
}, 2000);
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = '/data/umkm';
|
||||
}, 1000);
|
||||
} else {
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error);
|
||||
if (authLogo) {
|
||||
// Hapus ikon yang sudah ada jika ada
|
||||
const existingIcon = authLogo.querySelector('.bx');
|
||||
const existingIcon = authLogo.querySelector(".bx");
|
||||
if (existingIcon) {
|
||||
authLogo.removeChild(existingIcon);
|
||||
}
|
||||
|
||||
// Buat ikon baru
|
||||
const icon = document.createElement('i');
|
||||
icon.classList.add('bx', 'bxs-error-alt');
|
||||
icon.style.fontSize = '25px';
|
||||
icon.style.color = 'red'; // Pastikan 'green' dalam bentuk string
|
||||
const icon = document.createElement("i");
|
||||
icon.classList.add("bx", "bxs-error-alt");
|
||||
icon.style.fontSize = "25px";
|
||||
icon.style.color = "red"; // Pastikan 'green' dalam bentuk string
|
||||
|
||||
// Tambahkan ikon ke dalam auth-logo
|
||||
authLogo.appendChild(icon);
|
||||
@@ -96,47 +131,15 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
modalButton.disabled = false;
|
||||
modalButton.innerHTML = isEdit ? "Update" : "Create";
|
||||
|
||||
|
||||
// Set error message for the toast
|
||||
toastBody.textContent = "Error: " + (data.message || "Something went wrong");
|
||||
toast.classList.add('show'); // Show the toast
|
||||
toastBody.textContent =
|
||||
"An error occurred while processing your request.";
|
||||
toast.classList.add("show"); // Show the toast
|
||||
|
||||
setTimeout(() => {
|
||||
toast.classList.remove('show'); // Hide the toast after 3 seconds
|
||||
toast.classList.remove("show"); // Hide the toast after 3 seconds
|
||||
}, 3000);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error:", error);
|
||||
if (authLogo) {
|
||||
// Hapus ikon yang sudah ada jika ada
|
||||
const existingIcon = authLogo.querySelector('.bx');
|
||||
if (existingIcon) {
|
||||
authLogo.removeChild(existingIcon);
|
||||
}
|
||||
|
||||
// Buat ikon baru
|
||||
const icon = document.createElement('i');
|
||||
icon.classList.add('bx', 'bxs-error-alt');
|
||||
icon.style.fontSize = '25px';
|
||||
icon.style.color = 'red'; // Pastikan 'green' dalam bentuk string
|
||||
|
||||
// Tambahkan ikon ke dalam auth-logo
|
||||
authLogo.appendChild(icon);
|
||||
}
|
||||
|
||||
// Enable button and reset its text on error
|
||||
modalButton.disabled = false;
|
||||
modalButton.innerHTML = isEdit ? "Update" : "Create";
|
||||
|
||||
// Set error message for the toast
|
||||
toastBody.textContent = "An error occurred while processing your request.";
|
||||
toast.classList.add('show'); // Show the toast
|
||||
|
||||
setTimeout(() => {
|
||||
toast.classList.remove('show'); // Hide the toast after 3 seconds
|
||||
}, 3000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Fungsi fetchOptions untuk autocomplete server-side
|
||||
@@ -145,7 +148,11 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
if (inputValue.length < 2) return;
|
||||
let districtValue = document.getElementById("district_name").value; // Ambil kecamatan terpilih
|
||||
|
||||
let url = `${GlobalConfig.apiHost}/api/combobox/search-options?query=${encodeURIComponent(inputValue)}&field=${field}`;
|
||||
let url = `${
|
||||
GlobalConfig.apiHost
|
||||
}/api/combobox/search-options?query=${encodeURIComponent(
|
||||
inputValue
|
||||
)}&field=${field}`;
|
||||
|
||||
// Jika field desa, tambahkan kecamatan sebagai filter
|
||||
if (field === "village_name") {
|
||||
@@ -153,30 +160,30 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
}
|
||||
|
||||
fetch(url, {
|
||||
method: 'GET',
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${document
|
||||
.querySelector('meta[name="api-token"]')
|
||||
.getAttribute("content")}`,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
},
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
let dataList = document.getElementById(field + "Options");
|
||||
dataList.innerHTML = "";
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
let dataList = document.getElementById(field + "Options");
|
||||
dataList.innerHTML = "";
|
||||
|
||||
data.forEach(item => {
|
||||
let option = document.createElement("option");
|
||||
option.value = item.name;
|
||||
option.dataset.code = item.code;
|
||||
dataList.appendChild(option);
|
||||
});
|
||||
})
|
||||
.catch(error => console.error("Error fetching options:", error));
|
||||
data.forEach((item) => {
|
||||
let option = document.createElement("option");
|
||||
option.value = item.name;
|
||||
option.dataset.code = item.code;
|
||||
dataList.appendChild(option);
|
||||
});
|
||||
})
|
||||
.catch((error) => console.error("Error fetching options:", error));
|
||||
};
|
||||
|
||||
document.querySelector('.btn-back').addEventListener('click', function() {
|
||||
document.querySelector(".btn-back").addEventListener("click", function () {
|
||||
window.history.back();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,58 +18,61 @@ console.log(dropzonePreviewNode);
|
||||
url: `${GlobalConfig.apiHost}/api/umkm/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/umkm";
|
||||
window.location.href = "/data/web-umkm";
|
||||
}, 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 = '<span class="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true"></span>Loading...';
|
||||
this.innerHTML =
|
||||
'<span class="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true"></span>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,62 +85,68 @@ 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('downloadtempumkm').addEventListener('click', function() {
|
||||
var url = `${GlobalConfig.apiHost}/api/download-template-umkm`;
|
||||
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) => {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = url;
|
||||
a.download = 'template_umkm.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("downloadtempumkm")
|
||||
.addEventListener("click", function () {
|
||||
var url = `${GlobalConfig.apiHost}/api/download-template-umkm`;
|
||||
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) => {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.style.display = "none";
|
||||
a.href = url;
|
||||
a.download = "template_umkm.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('toastUploadUmkm');
|
||||
const toastBody = toastElement.querySelector('.toast-body');
|
||||
const toastHeader = toastElement.querySelector('.toast-header');
|
||||
const toastElement = document.getElementById("toastUploadUmkm");
|
||||
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;
|
||||
@@ -146,4 +155,3 @@ function showToast(iconClass, iconColor, message) {
|
||||
const toast = new bootstrap.Toast(toastElement); // Inisialisasi Bootstrap Toast
|
||||
toast.show();
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ Route::group(['middleware' => 'auth'], function(){
|
||||
Route::get('/advertisements/bulk-create', [AdvertisementController::class, 'bulkCreate'])->name('advertisements.bulk-create');
|
||||
|
||||
// Resource route, kecuali create karena dibuat terpisah
|
||||
Route::resource('/umkm', UmkmController::class)->except(['create', 'show']);
|
||||
Route::resource('/web-umkm', UmkmController::class)->except(['create', 'show']);
|
||||
|
||||
// Rute khusus untuk create dan bulk-create
|
||||
Route::get('/umkm/create', [UmkmController::class, 'create'])->name('umkm.create');
|
||||
|
||||
Reference in New Issue
Block a user