Refactor penanganan menu pada sidebar
- Mengurutkan tampilan menu berdasarkan section priority. - Menambahkan validasi untuk memastikan `$menus` didefinisikan. - Merapikan logika iterasi dan heading dengan pendekatan yang lebih efisien.
This commit is contained in:
parent
091da9832e
commit
eae476b2ec
@ -39,33 +39,42 @@
|
||||
</div>
|
||||
</div>
|
||||
@php
|
||||
$headingSystem = 0;
|
||||
$headingOtorisasi = 0;
|
||||
$headingMain = 0;
|
||||
$headingMaster = 0;
|
||||
$headingSystem = 0;
|
||||
|
||||
// Ensure $menus is defined and is an object
|
||||
$menus = isset($menus) ? json_decode(json_encode($menus)) : new stdClass;
|
||||
|
||||
// Define the order of sections
|
||||
$sectionOrder = ['main','otorisator', 'master', 'system'];
|
||||
@endphp
|
||||
@php $menus = json_decode(json_encode($menus)); @endphp
|
||||
@foreach($menus as $key => $value)
|
||||
@foreach($value as $menu)
|
||||
@if($key=='main')
|
||||
@if($headingMain == 0)
|
||||
|
||||
@foreach($sectionOrder as $section)
|
||||
@if(!empty($menus->$section))
|
||||
@if($section == 'otorisator' && $headingOtorisasi == 0)
|
||||
<div class="menu-item pt-2.25 pb-px">
|
||||
<span class="menu-heading uppercase text-2sm font-semibold text-gray-500 pl-[10px] pr-[10px]">
|
||||
Otorisator
|
||||
</span>
|
||||
</div>
|
||||
@php $headingOtorisasi = 1; @endphp
|
||||
@elseif($section == 'main' && $headingMain == 0)
|
||||
<div class="menu-item pt-2.25 pb-px">
|
||||
<span class="menu-heading uppercase text-2sm font-semibold text-gray-500 pl-[10px] pr-[10px]">
|
||||
Apps
|
||||
</span>
|
||||
</div>
|
||||
@php $headingMain = 1; @endphp
|
||||
@endif
|
||||
@elseif($key=='master')
|
||||
@if($headingMaster == 0)
|
||||
@elseif($section == 'master' && $headingMaster == 0)
|
||||
<div class="menu-item pt-2.25 pb-px">
|
||||
<span class="menu-heading uppercase text-2sm font-semibold text-gray-500 pl-[10px] pr-[10px]">
|
||||
Master Data
|
||||
</span>
|
||||
</div>
|
||||
@php $headingMaster = 1; @endphp
|
||||
@endif
|
||||
@elseif($key=='system')
|
||||
@if($headingSystem == 0)
|
||||
@elseif($section == 'system' && $headingSystem == 0)
|
||||
<div class="menu-item pt-2.25 pb-px">
|
||||
<span class="menu-heading uppercase text-2sm font-semibold text-gray-500 pl-[10px] pr-[10px]">
|
||||
Systems
|
||||
@ -73,7 +82,8 @@
|
||||
</div>
|
||||
@php $headingSystem = 1; @endphp
|
||||
@endif
|
||||
@endif
|
||||
|
||||
@foreach($menus->$section as $menu)
|
||||
@if(auth()->user()->hasRole($menu->roles))
|
||||
@if(isset($menu->sub))
|
||||
<div class="menu-item {{ request()->routeIs($menu->path) || request()->routeIs($menu->path.'.*') ? 'show' : '' }}" data-menu-item-toggle="accordion" data-menu-item-trigger="click">
|
||||
@ -128,6 +138,7 @@
|
||||
@endif
|
||||
@endif
|
||||
@endforeach
|
||||
@endif
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user