- Remove unused FeaturesController (empty stubs, no routes) - Remove ConvertSpatialFile CLI command (unused; service used in LayerManager) - Remove MigrateGeojsonToFeatures CLI command (one-shot migration, not referenced) - Remove .claude/worktrees/ (11 old agent worktrees from June) - Apply Laravel Pint formatting across 219 files (style only, no functional changes) Tests: 101 passing (319 assertions) API routes: unchanged (8 routes intact)
54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Projects;
|
|
|
|
use App\Models\InspectionTemplate;
|
|
use App\Models\Project;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.app')]
|
|
class ProjectTemplatesPicker extends Component
|
|
{
|
|
public Project $project;
|
|
|
|
public array $assignedIds = [];
|
|
|
|
public string $search = '';
|
|
|
|
public function mount(Project $project)
|
|
{
|
|
$this->project = $project;
|
|
abort_unless(Auth::user()->can('edit projects'), 403);
|
|
$this->assignedIds = $project->inspectionTemplates()->pluck('inspection_templates.id')->map(fn ($v) => (int) $v)->all();
|
|
}
|
|
|
|
public function toggle(int $templateId): void
|
|
{
|
|
abort_unless(Auth::user()->can('edit projects'), 403);
|
|
InspectionTemplate::findOrFail($templateId); // valida
|
|
|
|
if (in_array($templateId, $this->assignedIds, true)) {
|
|
$this->project->inspectionTemplates()->detach($templateId);
|
|
$this->assignedIds = array_values(array_diff($this->assignedIds, [$templateId]));
|
|
$this->dispatch('notify', 'Plantilla desasignada del proyecto');
|
|
} else {
|
|
$this->project->inspectionTemplates()->syncWithoutDetaching([$templateId]);
|
|
$this->assignedIds[] = $templateId;
|
|
$this->dispatch('notify', 'Plantilla asignada al proyecto');
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$templates = InspectionTemplate::query()
|
|
->when($this->search !== '', fn ($q) => $q->where('name', 'like', '%'.$this->search.'%'))
|
|
->orderBy('name')->get();
|
|
|
|
return view('livewire.projects.project-templates-picker', [
|
|
'templates' => $templates,
|
|
]);
|
|
}
|
|
}
|