{{-- Users of Användare (#2957 slice 6b, card #3020). Included by user/index for user.index and admin.user.index. Expects: $data (collection of User; UserController@index scopes user.index to the company) and $normal_user (true on user.index). Toolbar: the same GET parameters as the old filter box (q, status, and qc on the admin list), sent to the route the page came from; status and qc sit in the "Filter" disclosure, open while one is in use. Rows, as before: user.index links to user.edit, and a main user gets "Ändra" plus "Ta bort användaren" (DELETE user.destroy after a native confirm dialog, disabled on the own row); admin.user.index adds the company column and links to admin.user.edit for admins, without delete. --}} @php $pageRows = \App\Support\TablePagination::rows($data); $normal_user = $normal_user === true; $authUser = Auth::user(); $canManage = $normal_user && $authUser->isMainUser(); $canAdminEdit = ! $normal_user && $authUser->isAdmin(); $action = $normal_user ? route('user.index') : route('admin.user.index'); $status = (string) request('status', ''); $filterOpen = $status !== '' || (! $normal_user && request()->filled('qc')); $filtered = $filterOpen || request()->filled('q'); $statusOptions = ['' => __('user.nh.statusAll'), '1' => __('user.formActive'), '0' => __('user.formInactive')]; if (! $normal_user) { $data->loadMissing('company'); } $mainUserId = $normal_user ? $authUser->company->main_user_id : null; $deletable = collect(); @endphp @if ($data->isEmpty()) {{ __('user.nh.emptyText') }} @if ($filtered) {{ __('user.nh.showAll') }} @elseif ($normal_user) {{ __('user.form.createUser') }} @endif @else @unless ($normal_user) @endunless @foreach ($pageRows as $user) @php $fullName = trim($user->first_name.' '.$user->last_name); $isMain = $normal_user ? $user->id == $mainUserId : ($user->company && $user->company->main_user_id == $user->id); $edit = $normal_user ? route('user.edit', $user->id) : route('admin.user.edit', $user->id); if ($canManage && $user->id != $authUser->id) { $deletable->push($user); } @endphp @unless ($normal_user) @endunless @endforeach
{{ __('userList.name') }} {{ __('userList.email') }} {{ __('userList.nh.role') }}{{ __('userList.companyname') }}{{ __('user.nh.columnActions') }}
{{ $fullName !== '' ? $fullName : $user->username }} @if ($fullName !== ''){{ $user->username }}@endif {{ $user->email }} @if ($isMain) {{ __('userList.mainText') }} @else {{ __('userList.nh.roleUser') }} @endif {{ $user->company?->name }} @if ($canManage || $canAdminEdit) {{ __('user.nh.edit') }} @if ($canManage) @if ($user->id != $authUser->id) {{ __('user.form.delete') }} @else {{ __('user.form.delete') }} @endif @endif @endif
{{ __('user.nh.count', ['count' => formatNumber($data->count())]) }} @foreach ($deletable as $user) @php($name = trim($user->first_name.' '.$user->last_name) ?: $user->username)

{{ __('user.nh.deleteTitle') }}

{{ __('user.nh.deleteText', ['name' => $name]) }}

@csrf @method('DELETE')
@endforeach
@endif