feat(templates): tabla Rappasoft con filtros para el catálogo global

- Nueva InspectionTemplatesTable (DataTableComponent): columnas Plantilla,
  Descripción, Campos, Proyectos (uso) y Acciones; filtros en cabecera por nombre,
  descripción y uso (en uso / sin uso). Gateada por manage templates.
- GlobalTemplateManager: el listado HTML se sustituye por la tabla embebida.
  Acciones Editar/Borrar viajan por eventos (template-edit/template-delete);
  el manager emite templates-changed al guardar/borrar/importar para que la tabla
  se refresque (#[On('templates-changed')]).

Tests: GlobalTemplatesTest amplía con tabla (render + permiso, evento edit). Suite 91 passing.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-25 18:24:59 +02:00
co-authored by Claude Opus 4.7
parent f8a68312a3
commit 51c07ede38
5 changed files with 297 additions and 164 deletions
@@ -5,6 +5,7 @@ namespace App\Livewire\Inspections;
use App\Models\InspectionTemplate;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Layout;
use Livewire\Attributes\On;
use Livewire\Component;
use Livewire\WithFileUploads;
use PhpOffice\PhpSpreadsheet\IOFactory;
@@ -60,6 +61,7 @@ class GlobalTemplateManager extends Component
$this->showForm = true;
}
#[On('template-edit')]
public function editTemplate($id)
{
$template = InspectionTemplate::findOrFail($id);
@@ -135,12 +137,15 @@ class GlobalTemplateManager extends Component
$this->cancelForm();
$this->loadTemplates();
$this->dispatch('templates-changed');
}
#[On('template-delete')]
public function deleteTemplate($id)
{
InspectionTemplate::findOrFail($id)->delete();
$this->loadTemplates();
$this->dispatch('templates-changed');
$this->dispatch('notify', 'Plantilla eliminada');
}
@@ -203,6 +208,7 @@ class GlobalTemplateManager extends Component
$this->importTemplateName = '';
$this->importFile = null;
$this->loadTemplates();
$this->dispatch('templates-changed');
$this->dispatch('notify', 'Plantilla importada');
}
@@ -0,0 +1,112 @@
<?php
namespace App\Livewire\Inspections;
use App\Models\InspectionTemplate;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\On;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter;
class InspectionTemplatesTable extends DataTableComponent
{
protected $model = InspectionTemplate::class;
public function configure(): void
{
$this->setPrimaryKey('id')
->setDefaultSort('inspection_templates.name', 'asc')
->setSortingPillsEnabled(false)
->setSecondaryHeaderEnabled()
->setAdditionalSelects([
'inspection_templates.id as id',
'inspection_templates.fields as fields',
]);
}
/** Refrescar cuando el manager crea/edita/borra. */
#[On('templates-changed')]
public function refreshRows(): void
{
//
}
public function builder(): Builder
{
abort_unless(Auth::user()->can('manage templates'), 403);
return InspectionTemplate::query()
->withCount('projects');
}
public function columns(): array
{
return [
Column::make('Plantilla', 'name')
->sortable()->searchable()
->secondaryHeaderFilter('name')
->format(fn ($value) => '<span class="font-medium">' . e($value) . '</span>')
->html(),
Column::make('Descripción', 'description')
->searchable()
->secondaryHeaderFilter('description')
->format(fn ($value) => $value
? '<span class="text-sm text-base-content/70">' . e($value) . '</span>'
: '<span class="text-base-content/30 text-xs">—</span>')
->html(),
Column::make('Campos')
->label(fn ($row) =>
'<span class="badge badge-ghost badge-sm">' . count($row->fields ?? []) . '</span>')
->html(),
Column::make('Proyectos')
->secondaryHeaderFilter('usage')
->label(function ($row) {
$n = (int) ($row->projects_count ?? 0);
$cls = $n > 0 ? 'badge-info' : 'badge-ghost';
return '<span class="badge ' . $cls . ' badge-sm">' . $n . '</span>';
})
->html(),
Column::make('Acciones')
->label(fn ($row) =>
'<div class="flex justify-end gap-1">
<button wire:click="$dispatch(\'template-edit\', { id: ' . $row->id . ' })"
class="btn btn-xs btn-ghost" title="Editar">
<svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/></svg>
</button>
<button wire:click="$dispatch(\'template-delete\', { id: ' . $row->id . ' })"
wire:confirm="¿Eliminar la plantilla \'' . e($row->name) . '\'? Esta acción no se puede deshacer."
class="btn btn-xs btn-error btn-outline" title="Eliminar">
<svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
</button>
</div>')
->html(),
];
}
public function filters(): array
{
return [
TextFilter::make('Plantilla', 'name')
->config(['placeholder' => 'Buscar nombre…'])
->filter(fn (Builder $q, string $v) => $q->where('inspection_templates.name', 'like', '%' . $v . '%')),
TextFilter::make('Descripción', 'description')
->config(['placeholder' => 'Buscar descripción…'])
->filter(fn (Builder $q, string $v) => $q->where('inspection_templates.description', 'like', '%' . $v . '%')),
SelectFilter::make('Uso', 'usage')
->options(['' => 'Todos', 'used' => 'En uso (≥1 proyecto)', 'unused' => 'Sin uso'])
->filter(function (Builder $q, string $v) {
if ($v === 'used') $q->has('projects');
if ($v === 'unused') $q->doesntHave('projects');
}),
];
}
}
@@ -1,11 +1,12 @@
<div class="max-w-5xl mx-auto">
<div class="bg-base-100 p-4 rounded shadow">
<div>
<x-slot name="header">
{{-- ── Cabecera ─────────────────────────────────────────────────────────── --}}
<div class="flex justify-between items-center mb-4">
<div>
<h1 class="text-xl font-bold">📋 {{ __('Inspection templates') }}</h1>
<p class="text-sm text-base-content/60">{{ __('Global catalogue, reusable across all projects.') }}</p>
</div>
<div class="flex items-center gap-2">
<div class="flex items-center gap-4">
<button wire:click="openImportFileModal" class="btn btn-outline btn-sm gap-1" title="{{ __('Import from CSV/Excel') }}">
<x-heroicon-o-document-arrow-up class="w-4 h-4" />
{{ __('Import CSV/Excel') }}
@@ -15,174 +16,150 @@
</button>
</div>
</div>
</x-slot>
@if($showForm)
<form wire:submit.prevent="saveTemplate" class="border p-4 rounded mb-6 bg-base-200">
<table class="w-full mb-8">
<tbody>
<tr>
<td class="w-1/4 py-3 pr-4 align-top">{{ __('Template name') }}</td>
<td class="py-3"><input type="text" wire:model="form.name" class="input w-full" required></td>
</tr>
<tr>
<td class="w-1/4 py-3 pr-4 align-top">{{ __('Description') }}</td>
<td class="py-3"><textarea wire:model="form.description" class="textarea textarea-bordered w-full" rows="2"></textarea></td>
</tr>
</tbody>
</table>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white rounded-lg shadow p-6">
@if($showForm)
<form wire:submit.prevent="saveTemplate" class="border p-4 rounded mb-6 bg-base-200">
<table class="w-full mb-8">
<tbody>
<tr>
<td class="w-1/4 py-3 pr-4 align-top">{{ __('Template name') }}</td>
<td class="py-3"><input type="text" wire:model="form.name" class="input w-full" required></td>
</tr>
<tr>
<td class="w-1/4 py-3 pr-4 align-top">{{ __('Description') }}</td>
<td class="py-3"><textarea wire:model="form.description" class="textarea textarea-bordered w-full" rows="2"></textarea></td>
</tr>
</tbody>
</table>
<div class="border-t pt-4 mt-2">
<h3 class="font-bold mb-3">{{ __('Form fields') }}</h3>
@foreach($form['fields'] as $index => $field)
<div class="border p-3 rounded mb-3 bg-base-100">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Group / section') }}</div>
<div><input type="text" wire:model="form.fields.{{ $index }}.group" placeholder="ej: Geometría" class="input input-sm w-full"></div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Internal name') }}</div>
<div><input type="text" wire:model="form.fields.{{ $index }}.name" placeholder="ej: altura_medida" class="input input-sm w-full"></div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Visible label') }}</div>
<div><input type="text" wire:model="form.fields.{{ $index }}.label" placeholder="ej: Altura medida (m)" class="input input-sm w-full"></div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Question / check') }}</div>
<div><input type="text" wire:model="form.fields.{{ $index }}.question" placeholder="ej: ¿Cumple la cota?" class="input input-sm w-full"></div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Field type') }}</div>
<div>
<select wire:model="form.fields.{{ $index }}.type" class="select select-sm w-full">
@foreach($fieldTypes as $typeValue => $typeLabel)
<option value="{{ $typeValue }}">{{ $typeLabel }}</option>
@endforeach
</select>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Required') }}</div>
<div class="flex justify-between items-center">
<input type="checkbox" wire:model="form.fields.{{ $index }}.required" class="checkbox checkbox-sm">
<button type="button" wire:click="removeField({{ $index }})" class="btn btn-xs btn-error">{{ __('Remove field') }}</button>
</div>
</div>
@if(in_array($field['type'], ['integer', 'decimal', 'percentage']))
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Min') }} / {{ __('Max') }} / {{ __('Step') }}</div>
<div class="flex gap-2">
<input type="number" wire:model="form.fields.{{ $index }}.min" placeholder="{{ __('Min') }}" class="input input-xs w-20">
<input type="number" wire:model="form.fields.{{ $index }}.max" placeholder="{{ __('Max') }}" class="input input-xs w-20">
<input type="number" step="any" wire:model="form.fields.{{ $index }}.step" placeholder="{{ __('Step') }}" class="input input-xs w-20">
<div class="border-t pt-4 mt-2">
<h3 class="font-bold mb-3">{{ __('Form fields') }}</h3>
@foreach($form['fields'] as $index => $field)
<div class="border p-3 rounded mb-3 bg-base-100">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Group / section') }}</div>
<div><input type="text" wire:model="form.fields.{{ $index }}.group" placeholder="ej: Geometría" class="input input-sm w-full"></div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Internal name') }}</div>
<div><input type="text" wire:model="form.fields.{{ $index }}.name" placeholder="ej: altura_medida" class="input input-sm w-full"></div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Visible label') }}</div>
<div><input type="text" wire:model="form.fields.{{ $index }}.label" placeholder="ej: Altura medida (m)" class="input input-sm w-full"></div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Question / check') }}</div>
<div><input type="text" wire:model="form.fields.{{ $index }}.question" placeholder="ej: ¿Cumple la cota?" class="input input-sm w-full"></div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Field type') }}</div>
<div>
<select wire:model="form.fields.{{ $index }}.type" class="select select-sm w-full">
@foreach($fieldTypes as $typeValue => $typeLabel)
<option value="{{ $typeValue }}">{{ $typeLabel }}</option>
@endforeach
</select>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Required') }}</div>
<div class="flex justify-between items-center">
<input type="checkbox" wire:model="form.fields.{{ $index }}.required" class="checkbox checkbox-sm">
<button type="button" wire:click="removeField({{ $index }})" class="btn btn-xs btn-error">{{ __('Remove field') }}</button>
</div>
</div>
@if(in_array($field['type'], ['integer', 'decimal', 'percentage']))
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Min') }} / {{ __('Max') }} / {{ __('Step') }}</div>
<div class="flex gap-2">
<input type="number" wire:model="form.fields.{{ $index }}.min" placeholder="{{ __('Min') }}" class="input input-xs w-20">
<input type="number" wire:model="form.fields.{{ $index }}.max" placeholder="{{ __('Max') }}" class="input input-xs w-20">
<input type="number" step="any" wire:model="form.fields.{{ $index }}.step" placeholder="{{ __('Step') }}" class="input input-xs w-20">
</div>
</div>
@elseif($field['type'] === 'select')
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Options (comma separated)') }}</div>
<div><input type="text" wire:model="form.fields.{{ $index }}.options" placeholder="ej: Bueno,Regular,Malo" class="input input-sm w-full"></div>
</div>
@endif
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Comments / help') }}</div>
<div><textarea wire:model="form.fields.{{ $index }}.help" rows="2" placeholder="{{ __('Notes or instructions for this field') }}" class="textarea textarea-bordered textarea-sm w-full"></textarea></div>
</div>
</div>
@elseif($field['type'] === 'select')
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Options (comma separated)') }}</div>
<div><input type="text" wire:model="form.fields.{{ $index }}.options" placeholder="ej: Bueno,Regular,Malo" class="input input-sm w-full"></div>
@endforeach
<button type="button" wire:click="addField" class="btn btn-sm btn-secondary mt-2">+ {{ __('Add field') }}</button>
</div>
<div class="flex gap-2 mt-4">
<button type="submit" class="btn btn-primary">{{ $editingTemplate ? __('Update') : __('Save template') }}</button>
<button type="button" wire:click="cancelForm" class="btn">{{ __('Cancel') }}</button>
</div>
</form>
@endif
{{-- Tabla Rappasoft (filtros en cabecera: nombre, descripción, uso) --}}
<livewire:inspections.inspection-templates-table :key="'tpl-table'" />
</div>
{{-- MODAL: Importar desde CSV/Excel --}}
@if($showImportFileModal)
<div class="fixed inset-0 z-40 bg-black/50" wire:click="$set('showImportFileModal', false)"></div>
<div class="fixed inset-0 z-50 flex items-center justify-center p-4">
<div class="bg-base-100 rounded-box shadow-2xl w-full max-w-2xl max-h-[90vh] overflow-y-auto">
<div class="flex items-center justify-between p-4 border-b border-base-300">
<h3 class="font-bold">{{ __('Import from CSV/Excel') }}</h3>
<button wire:click="$set('showImportFileModal', false)" class="btn btn-sm btn-ghost btn-circle"><x-heroicon-o-x-mark class="w-4 h-4" /></button>
</div>
<div class="p-4 space-y-3">
<p class="text-xs text-base-content/60">
{{ __('Columns: name, label, type, required, options, min, max, step') }}.
<button type="button" wire:click="downloadExampleCsv" class="link link-primary">{{ __('Download example CSV') }}</button>
</p>
<div class="form-control">
<label class="label"><span class="label-text font-medium">{{ __('Template name') }} <span class="text-error">*</span></span></label>
<input type="text" wire:model="importTemplateName" class="input input-bordered w-full" />
@error('importTemplateName')<span class="text-xs text-error">{{ $message }}</span>@enderror
</div>
<div class="form-control">
<label class="label"><span class="label-text font-medium">{{ __('File (CSV / Excel)') }} <span class="text-error">*</span></span></label>
<input type="file" wire:model="importFile" accept=".csv,.txt,.xlsx,.xls" class="file-input file-input-bordered w-full" />
@error('importFile')<span class="text-xs text-error">{{ $message }}</span>@enderror
</div>
@if($importError)<div class="alert alert-error text-sm py-2">{{ $importError }}</div>@endif
<div class="flex justify-end">
<button wire:click="parseImportFile" class="btn btn-sm btn-secondary gap-1"><x-heroicon-o-eye class="w-4 h-4" /> {{ __('Preview') }}</button>
</div>
@if(!empty($importPreviewFields))
<div class="border border-base-300 rounded-box p-2">
<p class="text-sm font-medium mb-2">{{ count($importPreviewFields) }} {{ __('fields detected') }}:</p>
<div class="overflow-x-auto">
<table class="table table-xs">
<thead><tr><th>{{ __('Label') }}</th><th>{{ __('Name') }}</th><th>{{ __('Type') }}</th><th>{{ __('Required') }}</th></tr></thead>
<tbody>
@foreach($importPreviewFields as $f)
<tr><td>{{ $f['label'] }}</td><td class="font-mono text-xs">{{ $f['name'] }}</td><td><span class="badge badge-ghost badge-sm">{{ $f['type'] }}</span></td><td>{{ !empty($f['required']) ? '✓' : '' }}</td></tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endif
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-2">
<div class="font-medium">{{ __('Comments / help') }}</div>
<div><textarea wire:model="form.fields.{{ $index }}.help" rows="2" placeholder="{{ __('Notes or instructions for this field') }}" class="textarea textarea-bordered textarea-sm w-full"></textarea></div>
</div>
</div>
@endforeach
<button type="button" wire:click="addField" class="btn btn-sm btn-secondary mt-2">+ {{ __('Add field') }}</button>
<div class="flex justify-end gap-2 p-4 border-t border-base-300">
<button wire:click="$set('showImportFileModal', false)" class="btn btn-ghost btn-sm">{{ __('Cancel') }}</button>
<button wire:click="confirmImportFile" class="btn btn-primary btn-sm" @disabled(empty($importPreviewFields))>{{ __('Create template') }}</button>
</div>
</div>
</div>
<div class="flex gap-2 mt-4">
<button type="submit" class="btn btn-primary">{{ $editingTemplate ? __('Update') : __('Save template') }}</button>
<button type="button" wire:click="cancelForm" class="btn">{{ __('Cancel') }}</button>
</div>
</form>
@endif
{{-- Tabla --}}
<div class="overflow-x-auto">
<table class="table table-zebra">
<thead>
<tr>
<th>{{ __('Name') }}</th>
<th>{{ __('Description') }}</th>
<th>{{ __('Fields') }}</th>
<th>{{ __('Used in projects') }}</th>
<th>{{ __('Actions') }}</th>
</tr>
</thead>
<tbody>
@forelse($templates as $template)
<tr>
<td class="font-medium">{{ $template->name }}</td>
<td>{{ $template->description ?? '-' }}</td>
<td>{{ count($template->fields ?? []) }}</td>
<td><span class="badge badge-ghost badge-sm">{{ $template->projects()->count() }}</span></td>
<td>
<button wire:click="editTemplate({{ $template->id }})" class="btn btn-xs btn-warning">{{ __('Edit') }}</button>
<button wire:click="deleteTemplate({{ $template->id }})"
wire:confirm="{{ __('Delete template confirmation') }}"
class="btn btn-xs btn-error">{{ __('Delete') }}</button>
</td>
</tr>
@empty
<tr><td colspan="5" class="text-center text-base-content/40 py-6">{{ __('No templates yet (table)') }}</td></tr>
@endforelse
</tbody>
</table>
@endif
</div>
</div>
{{-- MODAL: Importar desde CSV/Excel --}}
@if($showImportFileModal)
<div class="fixed inset-0 z-40 bg-black/50" wire:click="$set('showImportFileModal', false)"></div>
<div class="fixed inset-0 z-50 flex items-center justify-center p-4">
<div class="bg-base-100 rounded-box shadow-2xl w-full max-w-2xl max-h-[90vh] overflow-y-auto">
<div class="flex items-center justify-between p-4 border-b border-base-300">
<h3 class="font-bold">{{ __('Import from CSV/Excel') }}</h3>
<button wire:click="$set('showImportFileModal', false)" class="btn btn-sm btn-ghost btn-circle"><x-heroicon-o-x-mark class="w-4 h-4" /></button>
</div>
<div class="p-4 space-y-3">
<p class="text-xs text-base-content/60">
{{ __('Columns: name, label, type, required, options, min, max, step') }}.
<button type="button" wire:click="downloadExampleCsv" class="link link-primary">{{ __('Download example CSV') }}</button>
</p>
<div class="form-control">
<label class="label"><span class="label-text font-medium">{{ __('Template name') }} <span class="text-error">*</span></span></label>
<input type="text" wire:model="importTemplateName" class="input input-bordered w-full" />
@error('importTemplateName')<span class="text-xs text-error">{{ $message }}</span>@enderror
</div>
<div class="form-control">
<label class="label"><span class="label-text font-medium">{{ __('File (CSV / Excel)') }} <span class="text-error">*</span></span></label>
<input type="file" wire:model="importFile" accept=".csv,.txt,.xlsx,.xls" class="file-input file-input-bordered w-full" />
@error('importFile')<span class="text-xs text-error">{{ $message }}</span>@enderror
</div>
@if($importError)<div class="alert alert-error text-sm py-2">{{ $importError }}</div>@endif
<div class="flex justify-end">
<button wire:click="parseImportFile" class="btn btn-sm btn-secondary gap-1"><x-heroicon-o-eye class="w-4 h-4" /> {{ __('Preview') }}</button>
</div>
@if(!empty($importPreviewFields))
<div class="border border-base-300 rounded-box p-2">
<p class="text-sm font-medium mb-2">{{ count($importPreviewFields) }} {{ __('fields detected') }}:</p>
<div class="overflow-x-auto">
<table class="table table-xs">
<thead><tr><th>{{ __('Label') }}</th><th>{{ __('Name') }}</th><th>{{ __('Type') }}</th><th>{{ __('Required') }}</th></tr></thead>
<tbody>
@foreach($importPreviewFields as $f)
<tr><td>{{ $f['label'] }}</td><td class="font-mono text-xs">{{ $f['name'] }}</td><td><span class="badge badge-ghost badge-sm">{{ $f['type'] }}</span></td><td>{{ !empty($f['required']) ? '✓' : '' }}</td></tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endif
</div>
<div class="flex justify-end gap-2 p-4 border-t border-base-300">
<button wire:click="$set('showImportFileModal', false)" class="btn btn-ghost btn-sm">{{ __('Cancel') }}</button>
<button wire:click="confirmImportFile" class="btn btn-primary btn-sm" @disabled(empty($importPreviewFields))>{{ __('Create template') }}</button>
</div>
</div>
</div>
@endif
</div>
</div>
+1
View File
@@ -75,6 +75,7 @@ Route::get('/reports/dashboard', ReportsDashboard::class)->name('reports.dashboa
// Ruta para que el componente Livewire muestre/gestione el progreso de una fase
Route::get('/phases/{phase}/progress', PhaseProgress::class)->name('phases.progress');
Route::get('/projects-list', ProjectList::class)->name('projects.list');
// Ruta para templates
// Plantillas globales (catálogo único)
Route::get('/inspection-templates', \App\Livewire\Inspections\GlobalTemplateManager::class)
+37
View File
@@ -3,6 +3,7 @@
namespace Tests\Feature;
use App\Livewire\Inspections\GlobalTemplateManager;
use App\Livewire\Inspections\InspectionTemplatesTable;
use App\Livewire\Projects\ProjectMap;
use App\Livewire\Projects\ProjectTemplatesPicker;
use App\Models\InspectionTemplate;
@@ -79,6 +80,42 @@ class GlobalTemplatesTest extends TestCase
$this->assertFalse($project->fresh()->inspectionTemplates()->where('inspection_templates.id', $tpl->id)->exists());
}
public function test_templates_table_lists_and_requires_permission(): void
{
Permission::findOrCreate('manage templates');
InspectionTemplate::create(['name' => 'Recepción acero', 'fields' => []]);
// Sin permiso → 403
$weak = User::factory()->create();
Livewire::actingAs($weak)
->test(InspectionTemplatesTable::class)
->assertForbidden();
// Con permiso → lista
$admin = User::factory()->create();
$admin->givePermissionTo('manage templates');
Livewire::actingAs($admin)
->test(InspectionTemplatesTable::class)
->assertOk()
->assertSee('Recepción acero');
}
public function test_table_emits_edit_event_handled_by_manager(): void
{
Permission::findOrCreate('manage templates');
$admin = User::factory()->create();
$admin->givePermissionTo('manage templates');
$tpl = InspectionTemplate::create(['name' => 'Editame', 'fields' => []]);
// El manager escucha #[On('template-edit')] y abre el form
Livewire::actingAs($admin)
->test(GlobalTemplateManager::class)
->assertSet('showForm', false)
->call('editTemplate', $tpl->id) // simula el dispatch
->assertSet('showForm', true)
->assertSet('editingTemplate', $tpl->id);
}
public function test_map_template_selector_only_shows_assigned_templates(): void
{
$user = User::factory()->create();