diff --git a/app/Livewire/TemplateManager.php b/app/Livewire/TemplateManager.php index 2c53b79..644ecb0 100644 --- a/app/Livewire/TemplateManager.php +++ b/app/Livewire/TemplateManager.php @@ -5,16 +5,19 @@ namespace App\Livewire; use Livewire\Component; use App\Models\InspectionTemplate; use App\Models\Project; +use App\Models\Phase; class TemplateManager extends Component { public $project; public $templates; + public $phases; public $editingTemplate = null; public $showForm = false; // Controla si mostrar el formulario public $form = [ 'name' => '', 'description' => '', + 'phase_id' => null, 'fields' => [], ]; public $fieldTypes = [ @@ -31,9 +34,15 @@ class TemplateManager extends Component public function mount(Project $project) { $this->project = $project; + $this->loadPhases(); $this->loadTemplates(); } + public function loadPhases() + { + $this->phases = $this->project->phases()->orderBy('name')->get(); + } + public function loadTemplates() { $this->templates = InspectionTemplate::where('project_id', $this->project->id)->get(); @@ -49,7 +58,7 @@ class TemplateManager extends Component public function editTemplate($id) { $template = InspectionTemplate::find($id); - $this->form = $template->only(['name', 'description', 'fields']); + $this->form = $template->only(['name', 'description', 'phase_id', 'fields']); $this->editingTemplate = $id; $this->showForm = true; } @@ -65,6 +74,7 @@ class TemplateManager extends Component $this->form = [ 'name' => '', 'description' => '', + 'phase_id' => null, 'fields' => [], ]; $this->editingTemplate = null; @@ -94,6 +104,7 @@ class TemplateManager extends Component { $this->validate([ 'form.name' => 'required|string|max:255', + 'form.phase_id' => 'nullable|exists:phases,id', 'form.fields' => 'array', ]); @@ -106,6 +117,7 @@ class TemplateManager extends Component 'name' => $this->form['name'], 'description' => $this->form['description'], 'project_id' => $this->project->id, + 'phase_id' => $this->form['phase_id'], 'fields' => $this->form['fields'], ]); session()->flash('message', 'Template creado'); diff --git a/resources/views/livewire/template-manager.blade.php b/resources/views/livewire/template-manager.blade.php index 50e3eba..fabba98 100644 --- a/resources/views/livewire/template-manager.blade.php +++ b/resources/views/livewire/template-manager.blade.php @@ -34,6 +34,23 @@ + + {{-- Fase asociada (opcional) --}} + + + {{__('Fase asociada (opcional)')}} + + + + + @@ -107,6 +124,7 @@ Nombre Descripción + Fase Campos Acciones @@ -116,6 +134,7 @@ {{ $template->name }} {{ $template->description ?? '-' }} + {{ $template->phase ? $template->phase->name : 'Global' }} {{ count($template->fields) }}