Files
construprogress/resources/views/livewire/role-manager.blade.php
T
javier 5092896a1e refactor(roles): role create/edit as a full page instead of a modal
Per feedback, 'New role' (and Edit) now open a dedicated page instead of a
modal:
- New RoleForm full-page component + view at /admin/roles/create and
  /admin/roles/{role}/edit (name, description, permission checkboxes; saves
  and redirects back to the list).
- RoleManager trimmed: the create/edit modal and its logic removed; 'New role'
  and the per-row/view-modal Edit are now links to the new pages.
- Kept the read-only View modal, single + bulk delete, and protections.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 17:05:01 +02:00

127 lines
6.7 KiB
PHP

<div class="py-8 max-w-6xl mx-auto sm:px-6 lg:px-8">
{{-- Cabecera --}}
<div class="flex items-center justify-between mb-6">
<div>
<h2 class="text-2xl font-bold text-gray-800">{{ __('Roles & permissions') }}</h2>
<p class="text-sm text-gray-500 mt-1">{{ __('Manage role groups and the permissions assigned to each.') }}</p>
</div>
<div class="flex items-center gap-2">
<a href="{{ route('admin.permissions') }}" class="btn btn-outline btn-sm gap-1" wire:navigate>
<x-heroicon-o-table-cells class="w-4 h-4" /> {{ __('Matrix view') }}
</a>
<a href="{{ route('admin.roles.create') }}" class="btn btn-primary btn-sm gap-1" wire:navigate>
<x-heroicon-o-plus class="w-4 h-4" /> {{ __('New role') }}
</a>
</div>
</div>
{{-- Barra de acciones en grupo --}}
@if(count($selected) > 0)
<div class="flex items-center justify-between bg-base-200 rounded-lg px-4 py-2 mb-3">
<span class="text-sm">{{ count($selected) }} {{ __('selected') }}</span>
<button wire:click="bulkDelete"
wire:confirm="{{ __('Delete the selected roles? Protected roles will be skipped.') }}"
class="btn btn-error btn-sm gap-1">
<x-heroicon-o-trash class="w-4 h-4" /> {{ __('Delete selected') }}
</button>
</div>
@endif
{{-- Tabla de roles --}}
<div class="overflow-x-auto border border-base-300 rounded-lg bg-white">
<table class="table table-zebra">
<thead>
<tr>
<th class="w-10">
<input type="checkbox" class="checkbox checkbox-sm" wire:model.live="selectAll" />
</th>
<th>{{ __('Name') }}</th>
<th>{{ __('Description') }}</th>
<th class="text-center">{{ __('Permissions') }}</th>
<th class="text-center">{{ __('Users') }}</th>
<th class="w-32 text-right">{{ __('Actions') }}</th>
</tr>
</thead>
<tbody>
@forelse($roles as $role)
<tr wire:key="role-{{ $role->id }}" class="hover">
<td>
<input type="checkbox" class="checkbox checkbox-sm"
value="{{ $role->id }}" wire:model.live="selected" />
</td>
<td class="font-semibold">
{{ $role->name }}
@if(in_array($role->name, ['Admin'], true))
<span class="badge badge-ghost badge-xs ml-1">{{ __('protected') }}</span>
@endif
</td>
<td class="text-sm text-gray-500 max-w-xs truncate">{{ $role->description ?: '—' }}</td>
<td class="text-center">
<span class="badge badge-outline badge-sm">{{ $role->permissions->count() }}</span>
</td>
<td class="text-center">
<span class="badge badge-ghost badge-sm">{{ $role->users_count }}</span>
</td>
<td class="text-right">
<div class="flex items-center justify-end gap-1">
<button wire:click="openView({{ $role->id }})" class="btn btn-ghost btn-xs" title="{{ __('View') }}">
<x-heroicon-o-eye class="w-4 h-4" />
</button>
<a href="{{ route('admin.roles.edit', $role->id) }}" class="btn btn-ghost btn-xs text-info" title="{{ __('Edit') }}" wire:navigate>
<x-heroicon-o-pencil class="w-4 h-4" />
</a>
@unless(in_array($role->name, ['Admin'], true))
<button wire:click="delete({{ $role->id }})"
wire:confirm="{{ __('Delete role') }} '{{ $role->name }}'?"
class="btn btn-ghost btn-xs text-error" title="{{ __('Delete') }}">
<x-heroicon-o-trash class="w-4 h-4" />
</button>
@endunless
</div>
</td>
</tr>
@empty
<tr><td colspan="6" class="text-center text-gray-400 py-8">{{ __('No roles') }}</td></tr>
@endforelse
</tbody>
</table>
</div>
{{-- ════════════════ MODAL VER ════════════════ --}}
@if($viewing)
<div class="modal modal-open z-[1500]">
<div class="modal-box max-w-lg">
<div class="flex items-center justify-between mb-3">
<h3 class="font-bold text-lg flex items-center gap-2">
<x-heroicon-o-shield-check class="w-5 h-5 text-primary" /> {{ $viewing->name }}
</h3>
<button wire:click="closeView" class="btn btn-sm btn-circle btn-ghost"><x-heroicon-o-x-mark class="w-5 h-5" /></button>
</div>
<p class="text-sm text-gray-600 mb-1">{{ $viewing->description ?: __('No description') }}</p>
<p class="text-xs text-gray-400 mb-4">{{ $viewing->users_count }} {{ __('users') }} · {{ $viewing->permissions->count() }} {{ __('permissions') }}</p>
<div class="divider text-xs">{{ __('Permissions') }}</div>
@if($viewing->permissions->isEmpty())
<p class="text-sm text-gray-400">{{ __('No permissions') }}</p>
@else
<div class="flex flex-wrap gap-1">
@foreach($viewing->permissions as $perm)
<span class="badge badge-primary badge-sm">{{ $perm->name }}</span>
@endforeach
</div>
@endif
<div class="modal-action">
<a href="{{ route('admin.roles.edit', $viewing->id) }}" class="btn btn-sm btn-info gap-1" wire:navigate>
<x-heroicon-o-pencil class="w-4 h-4" /> {{ __('Edit') }}
</a>
<button wire:click="closeView" class="btn btn-sm">{{ __('Close') }}</button>
</div>
</div>
<div class="modal-backdrop bg-black/40" wire:click="closeView"></div>
</div>
@endif
</div>