Add phase selection to template manager and create new template button
This commit is contained in:
@@ -5,16 +5,19 @@ namespace App\Livewire;
|
|||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use App\Models\InspectionTemplate;
|
use App\Models\InspectionTemplate;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
|
use App\Models\Phase;
|
||||||
|
|
||||||
class TemplateManager extends Component
|
class TemplateManager extends Component
|
||||||
{
|
{
|
||||||
public $project;
|
public $project;
|
||||||
public $templates;
|
public $templates;
|
||||||
|
public $phases;
|
||||||
public $editingTemplate = null;
|
public $editingTemplate = null;
|
||||||
public $showForm = false; // Controla si mostrar el formulario
|
public $showForm = false; // Controla si mostrar el formulario
|
||||||
public $form = [
|
public $form = [
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'description' => '',
|
'description' => '',
|
||||||
|
'phase_id' => null,
|
||||||
'fields' => [],
|
'fields' => [],
|
||||||
];
|
];
|
||||||
public $fieldTypes = [
|
public $fieldTypes = [
|
||||||
@@ -31,9 +34,15 @@ class TemplateManager extends Component
|
|||||||
public function mount(Project $project)
|
public function mount(Project $project)
|
||||||
{
|
{
|
||||||
$this->project = $project;
|
$this->project = $project;
|
||||||
|
$this->loadPhases();
|
||||||
$this->loadTemplates();
|
$this->loadTemplates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loadPhases()
|
||||||
|
{
|
||||||
|
$this->phases = $this->project->phases()->orderBy('name')->get();
|
||||||
|
}
|
||||||
|
|
||||||
public function loadTemplates()
|
public function loadTemplates()
|
||||||
{
|
{
|
||||||
$this->templates = InspectionTemplate::where('project_id', $this->project->id)->get();
|
$this->templates = InspectionTemplate::where('project_id', $this->project->id)->get();
|
||||||
@@ -49,7 +58,7 @@ class TemplateManager extends Component
|
|||||||
public function editTemplate($id)
|
public function editTemplate($id)
|
||||||
{
|
{
|
||||||
$template = InspectionTemplate::find($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->editingTemplate = $id;
|
||||||
$this->showForm = true;
|
$this->showForm = true;
|
||||||
}
|
}
|
||||||
@@ -65,6 +74,7 @@ class TemplateManager extends Component
|
|||||||
$this->form = [
|
$this->form = [
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'description' => '',
|
'description' => '',
|
||||||
|
'phase_id' => null,
|
||||||
'fields' => [],
|
'fields' => [],
|
||||||
];
|
];
|
||||||
$this->editingTemplate = null;
|
$this->editingTemplate = null;
|
||||||
@@ -94,6 +104,7 @@ class TemplateManager extends Component
|
|||||||
{
|
{
|
||||||
$this->validate([
|
$this->validate([
|
||||||
'form.name' => 'required|string|max:255',
|
'form.name' => 'required|string|max:255',
|
||||||
|
'form.phase_id' => 'nullable|exists:phases,id',
|
||||||
'form.fields' => 'array',
|
'form.fields' => 'array',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -106,6 +117,7 @@ class TemplateManager extends Component
|
|||||||
'name' => $this->form['name'],
|
'name' => $this->form['name'],
|
||||||
'description' => $this->form['description'],
|
'description' => $this->form['description'],
|
||||||
'project_id' => $this->project->id,
|
'project_id' => $this->project->id,
|
||||||
|
'phase_id' => $this->form['phase_id'],
|
||||||
'fields' => $this->form['fields'],
|
'fields' => $this->form['fields'],
|
||||||
]);
|
]);
|
||||||
session()->flash('message', 'Template creado');
|
session()->flash('message', 'Template creado');
|
||||||
|
|||||||
@@ -34,6 +34,23 @@
|
|||||||
<textarea wire:model="form.description" class="textarea textarea-bordered w-full" rows="2"></textarea>
|
<textarea wire:model="form.description" class="textarea textarea-bordered w-full" rows="2"></textarea>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
{{-- Fase asociada (opcional) --}}
|
||||||
|
<tr>
|
||||||
|
<td class="w-1/4 py-3 pr-4 align-top">
|
||||||
|
{{__('Fase asociada (opcional)')}}
|
||||||
|
</td>
|
||||||
|
<td class="py-3">
|
||||||
|
<select wire:model="form.phase_id" class="select select-bordered w-full">
|
||||||
|
<option value="">Ninguna (global para el proyecto)</option>
|
||||||
|
@foreach($phases as $phase)
|
||||||
|
<option value="{{ $phase->id }}" {{ old('form.phase_id') == $phase->id ? 'selected' : '' }}>
|
||||||
|
{{ $phase->name }}
|
||||||
|
</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@@ -107,6 +124,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Nombre</th>
|
<th>Nombre</th>
|
||||||
<th>Descripción</th>
|
<th>Descripción</th>
|
||||||
|
<th>Fase</th>
|
||||||
<th>Campos</th>
|
<th>Campos</th>
|
||||||
<th>Acciones</th>
|
<th>Acciones</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -116,6 +134,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{ $template->name }}</td>
|
<td>{{ $template->name }}</td>
|
||||||
<td>{{ $template->description ?? '-' }}</td>
|
<td>{{ $template->description ?? '-' }}</td>
|
||||||
|
<td>{{ $template->phase ? $template->phase->name : 'Global' }}</td>
|
||||||
<td>{{ count($template->fields) }}</td>
|
<td>{{ count($template->fields) }}</td>
|
||||||
<td>
|
<td>
|
||||||
<button wire:click="editTemplate({{ $template->id }})" class="btn btn-xs btn-warning">
|
<button wire:click="editTemplate({{ $template->id }})" class="btn btn-xs btn-warning">
|
||||||
@@ -126,7 +145,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
@empty
|
@empty
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4" class="text-center">No hay templates creados. Presiona "Nuevo template" para comenzar.</td>
|
<td colspan="5" class="text-center">No hay templates creados. Presiona "Nuevo template" para comenzar.</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforelse
|
@endforelse
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user