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