feat(menu): update logic sidebar menu

This commit is contained in:
Daeng Deni Mardaeni 2025-03-20 14:13:42 +07:00
parent 485a2f560e
commit 78c1afb0a8

View File

@ -40,105 +40,94 @@
</div> </div>
</a> </a>
@php @php
$headingOtorisasi = 0;
$headingMain = 0;
$headingMaster = 0;
$headingSystem = 0;
// Ensure $menus is defined and is an object // Ensure $menus is defined and is an object
$menus = isset($menus) ? json_decode(json_encode($menus)) : new stdClass; $menus = isset($menus) ? json_decode(json_encode($menus)) : new stdClass;
// Define the order of sections // Define the order of sections
$sectionOrder = ['main','otorisator', 'master', 'system']; $sectionOrder = ['main', 'otorisator', 'master', 'system'];
$sectionTitles = [
'main' => 'Apps',
'otorisator' => 'Otorisator',
'master' => 'Master Data',
'system' => 'Systems'
];
@endphp @endphp
@foreach($sectionOrder as $section) @foreach($sectionOrder as $section)
@if(!empty($menus->$section)) @if(!empty($menus->$section))
@if($section == 'otorisator' && $headingOtorisasi == 0) @php
<div class="menu-item pt-2.25 pb-px"> $hasVisibleItems = false;
<span class="menu-heading uppercase text-2sm font-semibold text-gray-500 pl-[10px] pr-[10px]"> foreach($menus->$section as $menu) {
Otorisator if(auth()->user()->hasRole($menu->roles)) {
</span> $hasVisibleItems = true;
</div> break;
@php $headingOtorisasi = 1; @endphp }
@elseif($section == 'main' && $headingMain == 0) }
<div class="menu-item pt-2.25 pb-px"> @endphp
<span class="menu-heading uppercase text-2sm font-semibold text-gray-500 pl-[10px] pr-[10px]">
Apps
</span>
</div>
@php $headingMain = 1; @endphp
@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
@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
</span>
</div>
@php $headingSystem = 1; @endphp
@endif
@foreach($menus->$section as $menu) @if($hasVisibleItems)
@if(auth()->user()->hasRole($menu->roles)) <div class="menu-item pt-2.25 pb-px">
@if(isset($menu->sub)) <span class="menu-heading uppercase text-2sm font-semibold text-gray-500 pl-[10px] pr-[10px]">
<div class="menu-item {{ request()->routeIs($menu->path) || request()->routeIs($menu->path.'.*') ? 'show' : '' }}" data-menu-item-toggle="accordion" data-menu-item-trigger="click"> {{ $sectionTitles[$section] }}
<div </span>
class="menu-link flex items-center grow cursor-pointer border border-transparent gap-[10px] pl-[10px] pr-[10px] py-[6px]" </div>
tabindex="0">
<span class="menu-icon items-start text-gray-500 dark:text-gray-400 w-[20px]"> @foreach($menus->$section as $menu)
<i class="{{ $menu->icon ?? 'ki-filled ki-element-11 text-lg' }}"></i> @if(auth()->user()->hasRole($menu->roles))
</span> @if(isset($menu->sub))
<span class="menu-title text-sm font-semibold text-gray-700 menu-item-active:text-primary menu-link-hover:!text-primary"> <div class="menu-item {{ request()->routeIs($menu->path) || request()->routeIs($menu->path.'.*') ? 'show' : '' }}" data-menu-item-toggle="accordion" data-menu-item-trigger="click">
{{ $menu->title }} <div
</span> class="menu-link flex items-center grow cursor-pointer border border-transparent gap-[10px] pl-[10px] pr-[10px] py-[6px]"
<span class="menu-arrow text-gray-400 w-[20px] shrink-0 justify-end ml-1 mr-[-10px]"> tabindex="0">
<i class="ki-filled ki-plus text-2xs menu-item-show:hidden"> <span class="menu-icon items-start text-gray-500 dark:text-gray-400 w-[20px]">
</i> <i class="{{ $menu->icon ?? 'ki-filled ki-element-11 text-lg' }}"></i>
<i class="ki-filled ki-minus text-2xs hidden menu-item-show:inline-flex"> </span>
</i> <span class="menu-title text-sm font-semibold text-gray-700 menu-item-active:text-primary menu-link-hover:!text-primary">
</span> {{ $menu->title }}
</div> </span>
@if(is_array($menu->sub)) <span class="menu-arrow text-gray-400 w-[20px] shrink-0 justify-end ml-1 mr-[-10px]">
<div class="menu-accordion gap-0.5 pl-[10px] relative before:absolute before:left-[20px] before:top-0 before:bottom-0 before:border-l before:border-gray-200"> <i class="ki-filled ki-plus text-2xs menu-item-show:hidden">
@foreach($menu->sub as $sub) </i>
@if(auth()->user()->hasRole($sub->roles)) <i class="ki-filled ki-minus text-2xs hidden menu-item-show:inline-flex">
<div class="menu-item {{ request()->routeIs($sub->path.'.*') && in_array(request()->route()->getName(), [$sub->path.'.index', $sub->path.'.create', $sub->path.'.edit', $sub->path.'.restore']) ? 'active' : '' }}"> </i>
<a class="menu-link gap-[14px] pl-[10px] pr-[10px] py-[8px] border border-transparent items-center grow menu-item-active:bg-secondary-active dark:menu-item-active:bg-coal-300 dark:menu-item-active:border-gray-100 menu-item-active:rounded-lg hover:bg-secondary-active dark:hover:bg-coal-300 dark:hover:border-gray-100 hover:rounded-lg" </span>
href="{{ $sub->path ? route($sub->path.'.index') : '' }}" tabindex="0">
<span
class="menu-bullet flex w-[6px] relative before:absolute before:top-0 before:size-[6px] before:rounded-full before:-translate-x-1/2 before:-translate-y-1/2 menu-item-active:before:bg-primary menu-item-hover:before:bg-primary">
</span>
<span
class="menu-title text-2sm font-medium text-gray-700 menu-item-active:text-primary menu-item-active:font-semibold menu-link-hover:!text-primary">
{{ $sub->title }}
</span>
</a>
</div>
@endif
@endforeach
</div> </div>
@endif @if(is_array($menu->sub))
</div> <div class="menu-accordion gap-0.5 pl-[10px] relative before:absolute before:left-[20px] before:top-0 before:bottom-0 before:border-l before:border-gray-200">
@else @foreach($menu->sub as $sub)
<div class="menu-item {{ request()->routeIs($menu->path.'.*') ? 'active' : '' }}"> @if(auth()->user()->hasRole($sub->roles))
<a class="menu-link flex items-center grow cursor-pointer border border-transparent gap-[10px] pl-[10px] pr-[10px] py-[6px]" href="{{ $menu->path ? route($menu->path.'.index') : '' }}"> <div class="menu-item {{ request()->routeIs($sub->path.'.*') && in_array(request()->route()->getName(), [$sub->path.'.index', $sub->path.'.create', $sub->path.'.edit', $sub->path.'.restore']) ? 'active' : '' }}">
<span class="menu-icon items-start text-gray-500 dark:text-gray-400 w-[20px] menu-item-active:text-primary menu-link-hover:!text-primary"> <a class="menu-link gap-[14px] pl-[10px] pr-[10px] py-[8px] border border-transparent items-center grow menu-item-active:bg-secondary-active dark:menu-item-active:bg-coal-300 dark:menu-item-active:border-gray-100 menu-item-active:rounded-lg hover:bg-secondary-active dark:hover:bg-coal-300 dark:hover:border-gray-100 hover:rounded-lg"
<i class="{{ $menu->icon ?? 'ki-filled ki-element-11 text-lg' }}"></i> href="{{ $sub->path ? route($sub->path.'.index') : '' }}" tabindex="0">
</span> <span
<span class="menu-title text-sm font-semibold text-gray-700 menu-item-active:text-primary menu-link-hover:!text-primary"> class="menu-bullet flex w-[6px] relative before:absolute before:top-0 before:size-[6px] before:rounded-full before:-translate-x-1/2 before:-translate-y-1/2 menu-item-active:before:bg-primary menu-item-hover:before:bg-primary">
{{ $menu->title }} </span>
</span> <span
</a> class="menu-title text-2sm font-medium text-gray-700 menu-item-active:text-primary menu-item-active:font-semibold menu-link-hover:!text-primary">
</div> {{ $sub->title }}
</span>
</a>
</div>
@endif
@endforeach
</div>
@endif
</div>
@else
<div class="menu-item {{ request()->routeIs($menu->path.'.*') ? 'active' : '' }}">
<a class="menu-link flex items-center grow cursor-pointer border border-transparent gap-[10px] pl-[10px] pr-[10px] py-[6px]" href="{{ $menu->path ? route($menu->path.'.index') : '' }}">
<span class="menu-icon items-start text-gray-500 dark:text-gray-400 w-[20px] menu-item-active:text-primary menu-link-hover:!text-primary">
<i class="{{ $menu->icon ?? 'ki-filled ki-element-11 text-lg' }}"></i>
</span>
<span class="menu-title text-sm font-semibold text-gray-700 menu-item-active:text-primary menu-link-hover:!text-primary">
{{ $menu->title }}
</span>
</a>
</div>
@endif
@endif @endif
@endif @endforeach
@endforeach @endif
@endif @endif
@endforeach @endforeach
</div> </div>