From 44f125293be8a070f1a9458040f26fd998b16c1b Mon Sep 17 00:00:00 2001 From: javier Date: Thu, 25 Jun 2026 16:45:21 +0200 Subject: [PATCH] feat(templates): grupos de campos, pregunta/comentarios por campo y plantillas globales MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builder de plantillas (parte 1 del bloque): - Cada campo admite "Grupo / sección" (título), "Pregunta / revisar" (texto corto, tras la etiqueta) y "Comentarios / ayuda" (texto largo, al final). - Plantillas híbridas: toggle "Global" → project_id null; el listado de un proyecto muestra sus plantillas + las globales (badge "Global"). Tests: TemplateCreationTest (grupo/pregunta/ayuda persisten; global sin proyecto y visible en otros proyectos). Suite 90 passing. Pendiente (parte 2): adaptar el formulario de inspección (grupos, comentarios, fotos) y el visor de inspección. Co-Authored-By: Claude Opus 4.8 (1M context) --- app/Livewire/Inspections/TemplateManager.php | 16 ++++-- .../inspections/template-manager.blade.php | 36 ++++++++++++- tests/Feature/TemplateCreationTest.php | 51 +++++++++++++++++++ 3 files changed, 98 insertions(+), 5 deletions(-) diff --git a/app/Livewire/Inspections/TemplateManager.php b/app/Livewire/Inspections/TemplateManager.php index 4975159..ffa256b 100644 --- a/app/Livewire/Inspections/TemplateManager.php +++ b/app/Livewire/Inspections/TemplateManager.php @@ -25,6 +25,7 @@ class TemplateManager extends Component 'name' => '', 'description' => '', 'phase_id' => null, + 'is_global' => false, 'fields' => [], ]; @@ -67,8 +68,12 @@ class TemplateManager extends Component public function loadTemplates() { - $this->templates = InspectionTemplate::where('project_id', $this->project->id) + // Plantillas del proyecto + globales (project_id null) + $this->templates = InspectionTemplate::where(function ($q) { + $q->where('project_id', $this->project->id)->orWhereNull('project_id'); + }) ->with('phase') + ->orderBy('name') ->get(); } @@ -87,6 +92,7 @@ class TemplateManager extends Component 'name' => $template->name, 'description' => $template->description ?? '', 'phase_id' => $template->phase_id, + 'is_global' => is_null($template->project_id), 'fields' => $template->fields ?? [], ]; $this->editingTemplate = $id; @@ -105,6 +111,7 @@ class TemplateManager extends Component 'name' => '', 'description' => '', 'phase_id' => null, + 'is_global' => false, 'fields' => [], ]; $this->editingTemplate = null; @@ -113,14 +120,17 @@ class TemplateManager extends Component public function addField() { $this->form['fields'][] = [ + 'group' => '', 'name' => '', 'label' => '', + 'question' => '', 'type' => 'text', 'options' => '', 'required' => false, 'min' => null, 'max' => null, 'step' => null, + 'help' => '', ]; } @@ -141,8 +151,8 @@ class TemplateManager extends Component $data = [ 'name' => $this->form['name'], 'description' => $this->form['description'], - 'project_id' => $this->project->id, - 'phase_id' => $this->form['phase_id'] ?: null, + 'project_id' => ($this->form['is_global'] ?? false) ? null : $this->project->id, + 'phase_id' => ($this->form['is_global'] ?? false) ? null : ($this->form['phase_id'] ?: null), 'fields' => array_values($this->form['fields']), ]; diff --git a/resources/views/livewire/inspections/template-manager.blade.php b/resources/views/livewire/inspections/template-manager.blade.php index b0905cd..73a5b3c 100644 --- a/resources/views/livewire/inspections/template-manager.blade.php +++ b/resources/views/livewire/inspections/template-manager.blade.php @@ -54,7 +54,7 @@ {{ __('Associated phase (optional)') }} - @foreach($phases as $phase)