A free open source IT asset/license management system
Added components
snipe148f1bbe1823
diff --git a/app/Livewire/CheckoutTargetPanel.php b/app/Livewire/CheckoutTargetPanel.phpindex 5238391fbc..c3fffa5ca1 100644--- a/app/Livewire/CheckoutTargetPanel.php+++ b/app/Livewire/CheckoutTargetPanel.php@@ -30,7 +30,7 @@ use Livewire\Component;*/class CheckoutTargetPanel extends Component{- private const TYPES = ['assets', 'licenses', 'accessories', 'consumables'];+ private const TYPES = ['assets', 'licenses', 'accessories', 'consumables', 'components'];private const TARGET_TYPES = ['user', 'asset', 'location'];@@ -42,17 +42,31 @@ class CheckoutTargetPanel extends Component#[Locked]public string $type;+ /**+ * Fallback target type for pages that don't render the checkout-selector+ * radio group (components go only to assets, consumables only to users).+ * The bridge script uses this as the assumed target when it can't find+ * an `input[name="checkout_to_type"]:checked`.+ */+ #[Locked]+ public string $defaultTargetType = 'user';+public ?string $targetType = null;public ?int $targetId = null;- public function mount(string $type): void+ public function mount(string $type, string $defaultTargetType = 'user'): void{if (! in_array($type, self::TYPES, true)) {throw new \InvalidArgumentException("Unknown checkout-target-panel type: {$type}");}+ if (! in_array($defaultTargetType, self::TARGET_TYPES, true)) {+ throw new \InvalidArgumentException("Unknown checkout-target-panel defaultTargetType: {$defaultTargetType}");+ }+$this->type = $type;+ $this->defaultTargetType = $defaultTargetType;}/**@@ -115,6 +129,8 @@ class CheckoutTargetPanel extends Component->where('assigned_to', $this->targetId);})->get(),+ 'components:asset' => $target->components,+default => collect(),};}@@ -136,6 +152,7 @@ class CheckoutTargetPanel extends Component'licenses' => trans('general.licenses'),'accessories' => trans('general.accessories'),'consumables' => trans('general.consumables'),+ 'components' => trans('general.components'),};}diff --git a/resources/views/components/checkout.blade.php b/resources/views/components/checkout.blade.phpindex 034a0532ed..97236c3e0a 100644--- a/resources/views/components/checkout.blade.php+++ b/resources/views/components/checkout.blade.php@@ -9,11 +9,12 @@{{-- Page content --}}@section('content')-<x-container class="col-md-8">+<x-container columns="2">+ <x-page-column class="col-md-7">- <x-form route="{{ route('components.checkout.store', $snipe_component->id) }}" id="checkout_form">+ <x-form route="{{ route('components.checkout.store', $snipe_component->id) }}" id="checkout_form">- <x-box header="{{ $snipe_component->name }} ({{ $snipe_component->numRemaining() }} {{ trans('admin/components/general.remaining') }})">+ <x-box header="{{ $snipe_component->name }} ({{ $snipe_component->numRemaining() }} {{ trans('admin/components/general.remaining') }})">@if ($snipe_component->company)<x-form.static :label="trans('general.company')">{!! $snipe_component->company->present()->formattedNameLink !!}</x-form.static>@@ -73,9 +74,13 @@/></x-slot:customfooter>- </x-box>+ </x-box>- </x-form>+ </x-form>++ </x-page-column>++ <livewire:checkout-target-panel type="components" defaultTargetType="asset" /></x-container>diff --git a/resources/views/livewire/checkout-target-panel.blade.php b/resources/views/livewire/checkout-target-panel.blade.phpindex a674d78fd8..f39c9aca8c 100644--- a/resources/views/livewire/checkout-target-panel.blade.php+++ b/resources/views/livewire/checkout-target-panel.blade.php@@ -109,6 +109,25 @@</tbody>@break+ @case('components')+ <thead>+ <tr>+ <th scope="col">{{ trans('general.name') }}</th>+ <th scope="col">{{ trans('general.qty') }}</th>+ </tr>+ </thead>+ <tbody>+ @forelse ($items as $component)+ <tr>+ <td><a href="{{ route('components.show', $component->id) }}">{{ $component->name }}</a></td>+ <td>{{ $component->pivot->assigned_qty ?? 1 }}</td>+ </tr>+ @empty+ <tr><td colspan="2">{{ trans('admin/users/message.nothing_currently_assigned') }}</td></tr>+ @endforelse+ </tbody>+ @break+@endswitch</table></div>@@ -122,14 +141,15 @@// plus the checkout-selector radio toggle to this component. On// any change we resolve the currently-active target (based on the// radio) + its select value and dispatch. Pages that don't have- // the radio (consumables/checkout is user-only for now) fall back to- // 'user' as the assumed target type.+ // the radio (consumables/checkout is user-only, components/checkout+ // is asset-only) fall back to the server-supplied defaultTargetType+ // baked into the component's mount config.//// The surrounding Livewire directive runs once per component// INSTANCE, so binding at this level doesn't accumulate handlers.var dispatchTarget = function () {var radioVal = $('input[name="checkout_to_type"]:checked').val();- var targetType = radioVal || 'user';+ var targetType = radioVal || @json($defaultTargetType);var selectSelectors = {'user': '#assigned_user_select','asset': '#assigned_asset_select',