fix redirect back spatial plannings
This commit is contained in:
@@ -5,8 +5,6 @@ namespace App\Http\Controllers\Data;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\SpatialPlanning;
|
use App\Models\SpatialPlanning;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
|
|
||||||
class SpatialPlanningController extends Controller
|
class SpatialPlanningController extends Controller
|
||||||
{
|
{
|
||||||
@@ -15,42 +13,31 @@ class SpatialPlanningController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$menuId = $request->query('menu_id');
|
$menuId = $request->query('menu_id', 0);
|
||||||
$user = Auth::user();
|
$permissions = $this->permissions[$menuId] ?? []; // Avoid undefined index error
|
||||||
$userId = $user->id;
|
|
||||||
|
|
||||||
// Ambil role_id yang dimiliki user
|
$creator = $permissions['allow_create'] ?? 0;
|
||||||
$roleIds = DB::table('user_role')
|
$updater = $permissions['allow_update'] ?? 0;
|
||||||
->where('user_id', $userId)
|
$destroyer = $permissions['allow_destroy'] ?? 0;
|
||||||
->pluck('role_id');
|
|
||||||
|
|
||||||
// Ambil data akses berdasarkan role_id dan menu_id
|
return view('data.spatialPlannings.index', compact('creator', 'updater', 'destroyer','menuId'));
|
||||||
$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('data.spatialPlannings.index', compact('creator', 'updater', 'destroyer'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* show the form for creating a new resource.
|
* show the form for creating a new resource.
|
||||||
*/
|
*/
|
||||||
public function bulkCreate()
|
public function bulkCreate(Request $request)
|
||||||
{
|
{
|
||||||
return view('data.spatialPlannings.form-upload');
|
$menuId = $request->query('menu_id', 0);
|
||||||
|
return view('data.spatialPlannings.form-upload', compact('menuId'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create(Request $request)
|
||||||
{
|
{
|
||||||
|
$menuId = $request->query('menu_id', 0);
|
||||||
$title = 'Rencana Tata Ruang';
|
$title = 'Rencana Tata Ruang';
|
||||||
$subtitle = "Create Data";
|
$subtitle = "Create Data";
|
||||||
|
|
||||||
@@ -61,30 +48,15 @@ class SpatialPlanningController extends Controller
|
|||||||
$fieldTypes = $this->getFieldTypes();
|
$fieldTypes = $this->getFieldTypes();
|
||||||
|
|
||||||
$apiUrl = url('/api/spatial-plannings');
|
$apiUrl = url('/api/spatial-plannings');
|
||||||
return view('data.spatialPlannings.form', compact('title', 'subtitle', 'fields', 'fieldTypes', 'apiUrl', 'dropdownOptions'));
|
return view('data.spatialPlannings.form', compact('title', 'subtitle', 'fields', 'fieldTypes', 'apiUrl', 'dropdownOptions','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(Request $request,string $id)
|
||||||
{
|
{
|
||||||
|
$menuId = $request->query('menu_id', 0);
|
||||||
$title = 'Rencana Tata Ruang';
|
$title = 'Rencana Tata Ruang';
|
||||||
$subtitle = 'Update Data';
|
$subtitle = 'Update Data';
|
||||||
|
|
||||||
@@ -100,23 +72,7 @@ class SpatialPlanningController extends Controller
|
|||||||
$fieldTypes = $this->getFieldTypes();
|
$fieldTypes = $this->getFieldTypes();
|
||||||
|
|
||||||
$apiUrl = url('/api/spatial-plannings');
|
$apiUrl = url('/api/spatial-plannings');
|
||||||
return view('data.spatialPlannings.form', compact('title', 'subtitle', 'modelInstance', 'fields', 'fieldTypes', 'apiUrl', 'dropdownOptions'));
|
return view('data.spatialPlannings.form', compact('title', 'subtitle', 'modelInstance', 'fields', 'fieldTypes', 'apiUrl', 'dropdownOptions','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)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getFields()
|
private function getFields()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import GeneralTable from "../../table-generator.js";
|
|||||||
const tableElement = document.getElementById("spatial-planning-data-table");
|
const tableElement = document.getElementById("spatial-planning-data-table");
|
||||||
const canUpdate = tableElement.getAttribute("data-updater") === "1";
|
const canUpdate = tableElement.getAttribute("data-updater") === "1";
|
||||||
const canDelete = tableElement.getAttribute("data-destroyer") === "1";
|
const canDelete = tableElement.getAttribute("data-destroyer") === "1";
|
||||||
|
let menuId = document.getElementById("menuId").value;
|
||||||
|
|
||||||
const dataSpatialPlanningColumns = [
|
const dataSpatialPlanningColumns = [
|
||||||
"No",
|
"No",
|
||||||
@@ -23,7 +24,7 @@ const dataSpatialPlanningColumns = [
|
|||||||
widht: "120px",
|
widht: "120px",
|
||||||
formatter: function (cell, row) {
|
formatter: function (cell, row) {
|
||||||
const id = row.cells[8].data;
|
const id = row.cells[8].data;
|
||||||
const model = "data/spatial-plannings";
|
const model = "data/web-spatial-plannings";
|
||||||
|
|
||||||
let actionButtons = '<div class="d-flex justify-items-end gap-10">';
|
let actionButtons = '<div class="d-flex justify-items-end gap-10">';
|
||||||
let hasPrivilege = false;
|
let hasPrivilege = false;
|
||||||
@@ -34,7 +35,8 @@ const dataSpatialPlanningColumns = [
|
|||||||
actionButtons += `
|
actionButtons += `
|
||||||
<button class="btn btn-warning me-2 btn-edit"
|
<button class="btn btn-warning me-2 btn-edit"
|
||||||
data-id="${id}"
|
data-id="${id}"
|
||||||
data-model="${model}">
|
data-model="${model}"
|
||||||
|
data-menu="${menuId}">
|
||||||
<i class='bx bx-edit'></i>
|
<i class='bx bx-edit'></i>
|
||||||
</button>`;
|
</button>`;
|
||||||
}
|
}
|
||||||
@@ -49,10 +51,14 @@ const dataSpatialPlanningColumns = [
|
|||||||
</button>`;
|
</button>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
actionButtons += '</div>';
|
actionButtons += "</div>";
|
||||||
|
|
||||||
// Jika tidak memiliki akses, tampilkan teks "No Privilege"
|
// Jika tidak memiliki akses, tampilkan teks "No Privilege"
|
||||||
return gridjs.html(hasPrivilege ? actionButtons : '<span class="text-muted">No Privilege</span>');
|
return gridjs.html(
|
||||||
|
hasPrivilege
|
||||||
|
? actionButtons
|
||||||
|
: '<span class="text-muted">No Privilege</span>'
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
const modalButton = document.querySelector(".btn-modal");
|
const modalButton = document.querySelector(".btn-modal");
|
||||||
const form = document.querySelector("form#create-update-form");
|
const form = document.querySelector("form#create-update-form");
|
||||||
var authLogo = document.querySelector(".auth-logo");
|
var authLogo = document.querySelector(".auth-logo");
|
||||||
|
let menuId = document.getElementById("menuId").value;
|
||||||
|
|
||||||
if (!saveButton || !form) return;
|
if (!saveButton || !form) return;
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = "/data/web-spatial-plannings";
|
window.location.href = `/data/web-spatial-plannings?menu_id=${menuId}`;
|
||||||
}, 3000);
|
}, 3000);
|
||||||
} else {
|
} else {
|
||||||
if (authLogo) {
|
if (authLogo) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ console.log(dropzonePreviewNode);
|
|||||||
.getAttribute("content")}`,
|
.getAttribute("content")}`,
|
||||||
},
|
},
|
||||||
init: function () {
|
init: function () {
|
||||||
|
let menuId = document.getElementById("menuId").value;
|
||||||
// Listen for the success event
|
// 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("File successfully uploaded:", file);
|
||||||
@@ -39,7 +40,7 @@ console.log(dropzonePreviewNode);
|
|||||||
"Upload Files";
|
"Upload Files";
|
||||||
// Tunggu sebentar lalu reload halaman
|
// Tunggu sebentar lalu reload halaman
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = "/data/web-spatial-plannings";
|
window.location.href = `/data/web-spatial-plannings?menu_id=${menuId}`;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
});
|
});
|
||||||
// Listen for the error event
|
// Listen for the error event
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
@include('layouts.partials/page-title', ['title' => 'Form', 'subtitle' => 'File Uploads'])
|
@include('layouts.partials/page-title', ['title' => 'Form', 'subtitle' => 'File Uploads'])
|
||||||
|
<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">
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
@include('layouts.partials/page-title', ['title' => $title, 'subtitle' => $subtitle]) <!-- Menggunakan title dan subtitle dari controller -->
|
@include('layouts.partials/page-title', ['title' => $title, 'subtitle' => $subtitle]) <!-- Menggunakan title dan subtitle dari controller -->
|
||||||
|
<input type="hidden" id="menuId" value="{{ $menuId ?? 0 }}">
|
||||||
<div class="row d-flex justify-content-center">
|
<div class="row d-flex justify-content-center">
|
||||||
@if (session('error'))
|
@if (session('error'))
|
||||||
<div class="alert alert-danger">
|
<div class="alert alert-danger">
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
@include('layouts.partials/page-title', ['title' => 'Data', 'subtitle' => 'Rencana Tata Ruang'])
|
@include('layouts.partials/page-title', ['title' => 'Data', 'subtitle' => 'Rencana Tata Ruang'])
|
||||||
|
<input type="hidden" id="menuId" value="{{ $menuId ?? 0 }}">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h5 class="card-title">Daftar Rencana Tata Ruang</h5>
|
<h5 class="card-title">Daftar Rencana Tata Ruang</h5>
|
||||||
@@ -15,10 +15,10 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="d-flex justify-content-end gap-10 pb-3">
|
<div class="d-flex justify-content-end gap-10 pb-3">
|
||||||
@if ($creator)
|
@if ($creator)
|
||||||
<button class="btn btn-success me-2 width-lg btn-create" data-model="data/spatial-plannings">
|
<button class="btn btn-success me-2 width-lg btn-create" data-model="data/spatial-plannings" data-menu="{{ $menuId }}">
|
||||||
<i class='bx bxs-file-plus'></i>
|
<i class='bx bxs-file-plus'></i>
|
||||||
Create</button>
|
Create</button>
|
||||||
<button class="btn btn-primary width-lg btn-bulk-create" data-model="data/spatial-plannings">
|
<button class="btn btn-primary width-lg btn-bulk-create" data-model="data/spatial-plannings" data-menu="{{ $menuId }}">
|
||||||
<i class='bx bx-upload' ></i>
|
<i class='bx bx-upload' ></i>
|
||||||
Bulk Create
|
Bulk Create
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user