|
1 | | -<div class="sub-menu-wrapper"> |
2 | | - <a class="{{ request()->routeIs('server.proxy') ? 'sub-menu-item menu-item-active' : 'sub-menu-item' }}" {{ wireNavigate() }} |
3 | | - href="{{ route('server.proxy', $parameters) }}"> |
4 | | - <span class="menu-item-label">Configuration</span> |
5 | | - </a> |
6 | | - @if ($server->proxySet()) |
7 | | - <a class="{{ request()->routeIs('server.proxy.dynamic-confs') ? 'sub-menu-item menu-item-active' : 'sub-menu-item' }}" {{ wireNavigate() }} |
8 | | - href="{{ route('server.proxy.dynamic-confs', $parameters) }}"> |
9 | | - <span class="menu-item-label">Dynamic Configurations</span> |
10 | | - </a> |
11 | | - <a class="{{ request()->routeIs('server.proxy.logs') ? 'sub-menu-item menu-item-active' : 'sub-menu-item' }}" |
12 | | - href="{{ route('server.proxy.logs', $parameters) }}"> |
13 | | - <span class="menu-item-label">Logs</span> |
14 | | - </a> |
15 | | - @endif |
| 1 | +@php |
| 2 | + $serverPageItems = [ |
| 3 | + [ |
| 4 | + 'label' => 'Configuration', |
| 5 | + 'route' => 'server.show', |
| 6 | + 'active' => request()->routeIs('server.show', 'server.advanced', 'server.private-key', 'server.cloud-provider-token', 'server.ca-certificate', 'server.cloudflare-tunnel', 'server.docker-cleanup', 'server.destinations', 'server.log-drains', 'server.metrics', 'server.swarm', 'server.delete'), |
| 7 | + ], |
| 8 | + [ |
| 9 | + 'label' => 'Proxy', |
| 10 | + 'route' => 'server.proxy', |
| 11 | + 'active' => request()->routeIs('server.proxy', 'server.proxy.*'), |
| 12 | + 'visible' => ! $server->isSwarmWorker() && ! $server->settings->is_build_server, |
| 13 | + ], |
| 14 | + [ |
| 15 | + 'label' => 'Sentinel', |
| 16 | + 'route' => 'server.sentinel', |
| 17 | + 'active' => request()->routeIs('server.sentinel', 'server.sentinel.*'), |
| 18 | + 'visible' => $server->isFunctional() && ! $server->isSwarm() && ! $server->settings->is_build_server && auth()->user()?->can('viewSentinel', $server), |
| 19 | + ], |
| 20 | + [ |
| 21 | + 'label' => 'Resources', |
| 22 | + 'route' => 'server.resources', |
| 23 | + 'active' => request()->routeIs('server.resources'), |
| 24 | + ], |
| 25 | + [ |
| 26 | + 'label' => 'Terminal', |
| 27 | + 'route' => 'server.command', |
| 28 | + 'active' => request()->routeIs('server.command'), |
| 29 | + 'navigate' => false, |
| 30 | + 'visible' => auth()->user()?->can('canAccessTerminal'), |
| 31 | + ], |
| 32 | + [ |
| 33 | + 'label' => 'Security', |
| 34 | + 'route' => 'server.security.patches', |
| 35 | + 'active' => request()->routeIs('server.security.patches'), |
| 36 | + 'visible' => auth()->user()?->can('update', $server), |
| 37 | + ], |
| 38 | + ]; |
| 39 | + $proxyMenuItems = [ |
| 40 | + [ |
| 41 | + 'label' => 'Configuration', |
| 42 | + 'route' => 'server.proxy', |
| 43 | + 'active' => request()->routeIs('server.proxy'), |
| 44 | + ], |
| 45 | + [ |
| 46 | + 'label' => 'Dynamic Configurations', |
| 47 | + 'route' => 'server.proxy.dynamic-confs', |
| 48 | + 'active' => request()->routeIs('server.proxy.dynamic-confs'), |
| 49 | + 'visible' => $server->proxySet(), |
| 50 | + ], |
| 51 | + [ |
| 52 | + 'label' => 'Logs', |
| 53 | + 'route' => 'server.proxy.logs', |
| 54 | + 'active' => request()->routeIs('server.proxy.logs'), |
| 55 | + 'visible' => $server->proxySet(), |
| 56 | + 'navigate' => false, |
| 57 | + ], |
| 58 | + ]; |
| 59 | +
|
| 60 | + $serverPageItems = array_values(array_filter( |
| 61 | + $serverPageItems, |
| 62 | + fn (array $item): bool => $item['visible'] ?? true, |
| 63 | + )); |
| 64 | + $proxyMenuItems = array_values(array_filter( |
| 65 | + $proxyMenuItems, |
| 66 | + fn (array $item): bool => $item['visible'] ?? true, |
| 67 | + )); |
| 68 | + $activeProxyMenuItem = collect($proxyMenuItems)->firstWhere('active', true) ?? $proxyMenuItems[0]; |
| 69 | + $activeProxyMenuValue = (($activeProxyMenuItem['navigate'] ?? true) ? 'navigate' : 'location').'|proxy|'.route($activeProxyMenuItem['route'], $parameters); |
| 70 | +@endphp |
| 71 | + |
| 72 | +<div class="w-full md:w-auto"> |
| 73 | + <div class="mb-4 w-full border-b-2 border-solid border-neutral-200 pb-6 md:hidden dark:border-coolgray-200"> |
| 74 | + <label id="server-mobile-section-label" for="server-mobile-section" class="mb-1 block text-xs font-semibold uppercase tracking-wide text-neutral-500 dark:text-neutral-400">Section</label> |
| 75 | + <select id="server-mobile-section" class="select w-full" aria-label="Proxy menu" |
| 76 | + data-current-value="{{ $activeProxyMenuValue }}" |
| 77 | + x-data="{ |
| 78 | + init() { |
| 79 | + this.syncFromLocation(); |
| 80 | + window.Livewire?.hook?.('morphed', ({ el }) => { |
| 81 | + if (el.contains(this.$el)) { |
| 82 | + queueMicrotask(() => this.syncFromLocation()); |
| 83 | + } |
| 84 | + }); |
| 85 | + }, |
| 86 | + selected: $el.dataset.currentValue, |
| 87 | + syncFromLocation() { |
| 88 | + const currentUrl = new URL(window.location.href); |
| 89 | + const matchingOptions = Array.from(this.$el.options).filter((option) => { |
| 90 | + const optionUrl = new URL(option.value.split('|').slice(2).join('|'), window.location.origin); |
| 91 | +
|
| 92 | + return optionUrl.pathname === currentUrl.pathname; |
| 93 | + }); |
| 94 | + const selectedOption = matchingOptions.find((option) => option.value.startsWith('navigate|proxy|') || option.value.startsWith('location|proxy|')) || matchingOptions[0]; |
| 95 | +
|
| 96 | + if (selectedOption) { |
| 97 | + this.selected = selectedOption.value; |
| 98 | + } |
| 99 | + }, |
| 100 | + }" |
| 101 | + x-on:livewire:navigated.window="syncFromLocation()" |
| 102 | + x-model="selected" |
| 103 | + x-on:change=" |
| 104 | + const value = $event.target.value; |
| 105 | + const url = value.split('|').slice(2).join('|'); |
| 106 | +
|
| 107 | + if (value.startsWith('navigate|')) { |
| 108 | + window.Livewire?.navigate ? window.Livewire.navigate(url) : window.location.href = url; |
| 109 | + return; |
| 110 | + } |
| 111 | +
|
| 112 | + window.location.href = url; |
| 113 | + "> |
| 114 | + <optgroup label="Server"> |
| 115 | + @foreach ($serverPageItems as $menuItem) |
| 116 | + <option value="{{ ($menuItem['navigate'] ?? true) ? 'navigate' : 'location' }}|server|{{ route($menuItem['route'], $parameters) }}"> |
| 117 | + {{ $menuItem['label'] }} |
| 118 | + </option> |
| 119 | + @endforeach |
| 120 | + </optgroup> |
| 121 | + <optgroup label="Proxy"> |
| 122 | + @foreach ($proxyMenuItems as $menuItem) |
| 123 | + <option value="{{ ($menuItem['navigate'] ?? true) ? 'navigate' : 'location' }}|proxy|{{ route($menuItem['route'], $parameters) }}"> |
| 124 | + {{ $menuItem['label'] }} |
| 125 | + </option> |
| 126 | + @endforeach |
| 127 | + </optgroup> |
| 128 | + </select> |
| 129 | + </div> |
| 130 | + |
| 131 | + <div class="sub-menu-wrapper hidden md:flex"> |
| 132 | + @foreach ($proxyMenuItems as $menuItem) |
| 133 | + <a class="{{ $menuItem['active'] ? 'sub-menu-item menu-item-active' : 'sub-menu-item' }}" @if ($menuItem['navigate'] ?? true) {{ wireNavigate() }} @endif |
| 134 | + href="{{ route($menuItem['route'], $parameters) }}"> |
| 135 | + <span class="menu-item-label">{{ $menuItem['label'] }}</span> |
| 136 | + </a> |
| 137 | + @endforeach |
| 138 | + </div> |
16 | 139 | </div> |
0 commit comments