Add phase selection to template manager and create new template button

This commit is contained in:
2026-05-11 15:28:16 +02:00
parent 43e8a70f9c
commit 436e3ba5cf
2 changed files with 33 additions and 2 deletions
+13 -1
View File
@@ -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');