fix redirect back business or industries
This commit is contained in:
@@ -14,74 +14,30 @@ class BusinessOrIndustriesController extends Controller
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$menuId = $request->query('menu_id');
|
||||
$user = Auth::user();
|
||||
$userId = $user->id;
|
||||
|
||||
// Ambil role_id yang dimiliki user
|
||||
$roleIds = DB::table('user_role')
|
||||
->where('user_id', $userId)
|
||||
->pluck('role_id');
|
||||
|
||||
// Ambil data akses berdasarkan role_id dan menu_id
|
||||
$roleAccess = DB::table('role_menu')
|
||||
->whereIn('role_id', $roleIds)
|
||||
->where('menu_id', $menuId)
|
||||
->first();
|
||||
|
||||
// Pastikan roleAccess tidak null sebelum mengakses properti
|
||||
$creator = $roleAccess->allow_create ?? 0;
|
||||
$updater = $roleAccess->allow_update ?? 0;
|
||||
$destroyer = $roleAccess->allow_destroy ?? 0;
|
||||
return view('business-industries.index', compact('creator', 'updater', 'destroyer'));
|
||||
$menuId = $request->query('menu_id') ?? $request->input('menu_id');
|
||||
$permissions = $this->permissions[$menuId]?? []; // Avoid undefined index error
|
||||
$creator = $permissions['allow_create'] ?? 0;
|
||||
$updater = $permissions['allow_update'] ?? 0;
|
||||
$destroyer = $permissions['allow_destroy'] ?? 0;
|
||||
return view('business-industries.index', compact('creator', 'updater', 'destroyer','menuId'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
public function create(Request $request)
|
||||
{
|
||||
return view("business-industries.create");
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
$menuId = $request->query('menu_id') ?? $request->input('menu_id');
|
||||
return view("business-industries.create", compact('menuId'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
public function edit(string $id, Request $request)
|
||||
{
|
||||
$menuId = $request->query('menu_id') ?? $request->input('menu_id');
|
||||
$data = BusinessOrIndustry::findOrFail($id);
|
||||
return view('business-industries.edit', compact('data'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
return view('business-industries.edit', compact('data', 'menuId'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ const spinner = document.getElementById("spinner");
|
||||
const toastNotification = document.getElementById("toastNotification");
|
||||
const toast = new bootstrap.Toast(toastNotification);
|
||||
|
||||
let menuId = document.getElementById("menuId").value;
|
||||
|
||||
(dropzonePreviewNode.id = ""),
|
||||
dropzonePreviewNode &&
|
||||
((previewTemplate = dropzonePreviewNode.parentNode.innerHTML),
|
||||
@@ -34,7 +36,7 @@ const toast = new bootstrap.Toast(toastNotification);
|
||||
response.message;
|
||||
toast.show();
|
||||
setTimeout(() => {
|
||||
window.location.href = "/data/business-industries";
|
||||
window.location.href = `/data/business-industries?menu_id=${menuId}`;
|
||||
}, 2000);
|
||||
});
|
||||
this.on("error", function (file, errorMessage) {
|
||||
|
||||
@@ -35,7 +35,8 @@ class BusinessIndustries {
|
||||
tableContainer.innerHTML = "";
|
||||
let canUpdate = tableContainer.getAttribute("data-updater") === "1";
|
||||
let canDelete = tableContainer.getAttribute("data-destroyer") === "1";
|
||||
|
||||
let menuId = tableContainer.getAttribute("data-menuId");
|
||||
|
||||
// Create a new Grid.js instance only if it doesn't exist
|
||||
this.table = new Grid({
|
||||
columns: [
|
||||
@@ -56,17 +57,16 @@ class BusinessIndustries {
|
||||
{
|
||||
name: "Action",
|
||||
formatter: (cell) => {
|
||||
|
||||
let buttons = `<div class="d-flex justify-content-center gap-2">`;
|
||||
|
||||
|
||||
if (canUpdate) {
|
||||
buttons += `
|
||||
<a href="/data/business-industries/${cell}/edit" class="btn btn-yellow btn-sm d-inline-flex align-items-center justify-content-center">
|
||||
<a href="/data/business-industries/${cell}/edit?menu_id=${menuId}" class="btn btn-yellow btn-sm d-inline-flex align-items-center justify-content-center">
|
||||
<i class='bx bx-edit'></i>
|
||||
</a>
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
if (canDelete) {
|
||||
buttons += `
|
||||
<button data-id="${cell}" class="btn btn-sm btn-red btn-delete-business-industry d-inline-flex align-items-center justify-content-center">
|
||||
@@ -74,9 +74,9 @@ class BusinessIndustries {
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
buttons += `</div>`;
|
||||
|
||||
|
||||
return gridjs.html(buttons);
|
||||
},
|
||||
},
|
||||
|
||||
@@ -13,6 +13,8 @@ class UpdateBusinessIndustries {
|
||||
const spinner = document.getElementById("spinner");
|
||||
const toast = new bootstrap.Toast(toastNotification);
|
||||
|
||||
let menuId = document.getElementById("menuId").value;
|
||||
|
||||
if (!submitButton) {
|
||||
console.error("Error: Submit button not found!");
|
||||
return;
|
||||
@@ -53,7 +55,7 @@ class UpdateBusinessIndustries {
|
||||
data.message;
|
||||
toast.show();
|
||||
setTimeout(() => {
|
||||
window.location.href = "/data/business-industries";
|
||||
window.location.href = `/data/business-industries?menu_id=${menuId}`;
|
||||
}, 2000);
|
||||
} else {
|
||||
// Show error toast with message from API
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
@include('layouts.partials/page-title', ['title' => 'Data', 'subtitle' => 'Business Industries'])
|
||||
|
||||
<x-toast-notification />
|
||||
<input type="hidden" id="menuId" value="{{ $menuId ?? 0 }}">
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="card">
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
@include('layouts.partials/page-title', ['title' => 'Data Settings', 'subtitle' => 'Setting Dashboard'])
|
||||
|
||||
<x-toast-notification />
|
||||
<input type="hidden" id="menuId" value="{{ $menuId ?? 0 }}">
|
||||
<div class="row d-flex justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<div class="card">
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
<div class="card-body">
|
||||
<div class="d-flex flex-wrap justify-content-end align-items-center mb-2">
|
||||
@if ($creator)
|
||||
<a href="{{ route('business-industries.create')}}" class="btn btn-success btn-sm d-block d-sm-inline w-auto">Upload</a>
|
||||
<a href="{{ route('business-industries.create', ['menu_id' => $menuId])}}" class="btn btn-success btn-sm d-block d-sm-inline w-auto">Upload</a>
|
||||
@endif
|
||||
</div>
|
||||
<div id="table-business-industries"
|
||||
data-updater="{{ $updater }}"
|
||||
data-destroyer="{{ $destroyer }}">
|
||||
data-destroyer="{{ $destroyer }}"
|
||||
data-menuId="{{ $menuId }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user