Skip to content

A free open source IT asset/license management system

I don’t like side-panel being a thing - revisit

snipe28375f8e1054
diff --git a/app/Livewire/CheckoutTargetPanel.php b/app/Livewire/CheckoutTargetPanel.php
index c3fffa5ca1..c5737d6402 100644
--- a/app/Livewire/CheckoutTargetPanel.php
+++ b/app/Livewire/CheckoutTargetPanel.php
@@ -51,11 +51,22 @@ class CheckoutTargetPanel extends Component
#[Locked]
public string $defaultTargetType = 'user';
+ /**
+ * Grid class applied to the component's root element. Defaults to
+ * `col-md-5` which matches the single-target checkout pages that host
+ * this panel directly next to a col-md-7 form. Pages that stack this
+ * panel with another box inside their own col-md-5 wrapper pass
+ * `col-md-12` so the component fills its parent instead of collapsing
+ * to a nested 5/12 width.
+ */
+ #[Locked]
+ public string $rootClass = 'col-md-5';
+
public ?string $targetType = null;
public ?int $targetId = null;
- public function mount(string $type, string $defaultTargetType = 'user'): void
+ public function mount(string $type, string $defaultTargetType = 'user', string $rootClass = 'col-md-5'): void
{
if (! in_array($type, self::TYPES, true)) {
throw new \InvalidArgumentException("Unknown checkout-target-panel type: {$type}");
@@ -67,6 +78,7 @@ class CheckoutTargetPanel extends Component
$this->type = $type;
$this->defaultTargetType = $defaultTargetType;
+ $this->rootClass = $rootClass;
}
/**
diff --git a/resources/views/blade/side-panel/removed-assets.blade.php b/resources/views/blade/side-panel/removed-assets.blade.php
new file mode 100644
index 0000000000..5f952a6874
--- /dev/null
+++ b/resources/views/blade/side-panel/removed-assets.blade.php
@@ -0,0 +1,96 @@
+@props([
+ 'items',
+ 'message',
+ 'title' => trans('general.notification_warning'),
+ // On bulk-checkout the checkout-target-panel Livewire component takes
+ // over the right column once the user picks a target, so this warning
+ // is only useful in the "picking assets, no target yet" phase — pass
+ // hideOnTargetSelected=true and the small script at the bottom will
+ // hide the box the moment a target select gets a value.
+ 'hideOnTargetSelected' => false,
+])
+
+{{-- Warning side-panel used by bulk checkin/checkout to explain which assets
+ were pulled from the selection (because they were already assigned on
+ checkout, or already unassigned on checkin) and can't be included in
+ the operation. Only renders when the caller has at least one item to
+ show. Component intentionally doesn't set a col-md-* on its root so the
+ caller can wrap it in whatever column width fits their page layout.
+ Table layout mirrors the sibling checkout-target-panel so the two side
+ panels read consistently when stacked in the same column. --}}
+@if ($items->isNotEmpty())
+ <div class="box box-warning" id="removed-assets-warning">
+ <div class="box-header with-border">
+ <h2 class="box-title">
+ <x-icon type="warning" /> {{ $title }}
+ </h2>
+ </div>
+ <div class="box-body">
+ <p>{{ $message }}</p>
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th scope="col"></th>
+ <th scope="col">{{ trans('general.name') }}</th>
+ <th scope="col">{{ trans('admin/hardware/form.tag') }}</th>
+ <th scope="col">{{ trans('admin/hardware/form.serial') }}</th>
+ </tr>
+ </thead>
+ <tbody>
+ @foreach ($items as $item)
+ <tr>
+ <td>
+ @if ($item->image_url ?? null)
+ <img src="{{ $item->image_url }}" style="max-height: {{ $snipeSettings->thumbnail_max_h }}px; width: auto;" alt="">
+ @endif
+ </td>
+ <td>
+ <a href="{{ route('hardware.show', $item->id) }}">
+ {{ $item->name }}
+ </a>
+ </td>
+ <td>{{ $item->asset_tag }}</td>
+ <td>{{ $item->serial }}</td>
+ </tr>
+ @endforeach
+ </tbody>
+ </table>
+ </div>
+ </div>
+
+ @if ($hideOnTargetSelected)
+ <script nonce="{{ csrf_token() }}">
+ (function () {
+ // Hide the removed-assets warning as soon as the user picks a
+ // checkout target — the checkout-target-panel Livewire component
+ // becomes the primary side-column content at that point and the
+ // stale warning would just eat vertical space. We piggyback on
+ // the same target selects the panel's bridge script watches so
+ // there's no coordination between the two.
+ var $warning = $('#removed-assets-warning');
+ if (!$warning.length) return;
+
+ var syncVisibility = function () {
+ var radioVal = $('input[name="checkout_to_type"]:checked').val() || 'user';
+ var selectSelectors = {
+ 'user': '#assigned_user_select',
+ 'asset': '#assigned_asset_select',
+ 'location': '#assigned_location_location_select',
+ };
+ var val = $(selectSelectors[radioVal]).val();
+ var hasTarget = val !== null && val !== undefined && val !== '';
+ $warning.toggle(!hasTarget);
+ };
+
+ $('#assigned_user_select, #assigned_asset_select, #assigned_location_location_select')
+ .on('change', syncVisibility);
+ $('input[name="checkout_to_type"]').on('change', syncVisibility);
+
+ // Run once on ready so a server-side pre-selected target
+ // (session-remembered after a validation redirect) hides the
+ // warning immediately instead of flashing it on the first paint.
+ syncVisibility();
+ })();
+ </script>
+ @endif
+@endif
diff --git a/resources/views/hardware/bulk-checkin.blade.php b/resources/views/hardware/bulk-checkin.blade.php
index 03c2ba7321..9346ef6a2a 100644
--- a/resources/views/hardware/bulk-checkin.blade.php
+++ b/resources/views/hardware/bulk-checkin.blade.php
@@ -15,9 +15,8 @@
}
</style>
-<div class="row">
- <!-- left column -->
- <div class="col-md-7">
+<x-container columns="2">
+ <x-page-column class="col-md-7">
<div class="box box-default">
<div class="box-header with-border">
<h2 class="box-title"> {{ trans('admin/hardware/form.tag') }} </h2>
@@ -26,26 +25,6 @@
<form class="form-horizontal" method="post" action="{{ route('hardware.bulkcheckin.store') }}" autocomplete="off">
{{ csrf_field() }}
- @if ($removed_assets->isNotEmpty())
- <div class="box box-solid box-warning">
- <div class="box-header with-border">
- <span class="box-title col-xs-12">Warning</span>
- </div>
- <div class="box-body">
- <p>{{ trans('general.unassigned_assets_removed') }}</p>
- <ul>
- @foreach($removed_assets as $removed_asset)
- <li>
- <a href="{{ route('hardware.show', $removed_asset->id) }}">
- {{ $removed_asset->present()->fullName }}
- </a>
- </li>
- @endforeach
- </ul>
- </div>
- </div>
- @endif
-
@include('partials.forms.edit.asset-select', [
'translated_name' => trans('general.assets'),
'fieldname' => 'selected_assets[]',
@@ -148,8 +127,15 @@
</div>
</form>
</div>
- </div> <!--/.col-md-7-->
-</div>
+ </x-page-column>
+
+ <x-page-column class="col-md-5">
+ <x-side-panel.removed-assets
+ :items="$removed_assets"
+ :message="trans('general.unassigned_assets_removed')"
+ />
+ </x-page-column>
+</x-container>
@stop
@section('moar_scripts')
diff --git a/resources/views/hardware/bulk-checkout.blade.php b/resources/views/hardware/bulk-checkout.blade.php
index d837ee4866..d7a7dedbdb 100644
--- a/resources/views/hardware/bulk-checkout.blade.php
+++ b/resources/views/hardware/bulk-checkout.blade.php
@@ -22,21 +22,6 @@
<x-box header="{{ trans('admin/hardware/form.tag') }}">
- @if ($removed_assets->isNotEmpty())
- <x-box box_style="solid box-warning" header="Warning">
- <p>{{ trans('general.assigned_assets_removed') }}</p>
- <ul>
- @foreach ($removed_assets as $removed_asset)
- <li>
- <a href="{{ route('hardware.show', $removed_asset->id) }}">
- {{ $removed_asset->present()->fullName }}
- </a>
- </li>
- @endforeach
- </ul>
- </x-box>
- @endif
-
@include ('partials.forms.edit.asset-select', [
'translated_name' => trans('general.assets'),
'fieldname' => 'selected_assets[]',
@@ -126,7 +111,14 @@
</x-page-column>
- <livewire:checkout-target-panel type="assets" />
+ <x-page-column class="col-md-5">
+ <x-side-panel.removed-assets
+ :items="$removed_assets"
+ :message="trans('general.assigned_assets_removed')"
+ :hideOnTargetSelected="true"
+ />
+ <livewire:checkout-target-panel type="assets" rootClass="col-md-12" />
+ </x-page-column>
</x-container>
@stop
diff --git a/resources/views/livewire/checkout-target-panel.blade.php b/resources/views/livewire/checkout-target-panel.blade.php
index f39c9aca8c..6bc49efda0 100644
--- a/resources/views/livewire/checkout-target-panel.blade.php
+++ b/resources/views/livewire/checkout-target-panel.blade.php
@@ -1,4 +1,4 @@
-<div class="col-md-5" @if ($targetId === null) style="display: none;" @endif>
+<div class="{{ $rootClass }}" @if ($targetId === null) style="display: none;" @endif>
<div class="box box-primary">
<div class="box-header with-border">
<h2 class="box-title">