chore: cleanup dead code + format with Pint
- 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)
This commit is contained in:
@@ -2,63 +2,86 @@
|
||||
|
||||
namespace App\Livewire\Projects;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Models\Project;
|
||||
use App\Models\Phase;
|
||||
use App\Models\Layer;
|
||||
use App\Models\Feature;
|
||||
use App\Models\Inspection;
|
||||
use App\Models\InspectionTemplate;
|
||||
use App\Models\Issue;
|
||||
use App\Models\Layer;
|
||||
use App\Models\Media;
|
||||
use App\Models\Phase;
|
||||
use App\Models\Project;
|
||||
use App\Notifications\InspectionCompletedNotification;
|
||||
use App\Notifications\InspectionDeletedNotification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
class ProjectMap extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public Project $project;
|
||||
|
||||
public $phases;
|
||||
|
||||
public $activeLayers = []; // Now stores Layer IDs (not Phase IDs)
|
||||
|
||||
public $showLayerModal = false;
|
||||
|
||||
// Editor properties
|
||||
public $selectedFeature = null;
|
||||
|
||||
public $selectedPhaseId = null;
|
||||
|
||||
public $editProgress = 0;
|
||||
|
||||
public $editComment = '';
|
||||
|
||||
public $editResponsible = '';
|
||||
|
||||
public $editPhotos = [];
|
||||
|
||||
public $formFullscreen = false;
|
||||
|
||||
// Tab management
|
||||
public $activeTab = 'edit';
|
||||
|
||||
public $allFeatures;
|
||||
|
||||
public $allInspections;
|
||||
|
||||
// Templates e inspecciones
|
||||
public $templates = [];
|
||||
|
||||
public $selectedTemplateId = null;
|
||||
|
||||
public $inspectionFormData = [];
|
||||
|
||||
public $inspectionHistory = [];
|
||||
|
||||
// Imágenes en mapa
|
||||
public $showFeatureImages = false;
|
||||
|
||||
public $featureImageMarkers = [];
|
||||
|
||||
// Filters
|
||||
public $filterStatus = '';
|
||||
|
||||
public $filterResponsible = '';
|
||||
|
||||
public $filterProgressMin = 0;
|
||||
|
||||
public $filterProgressMax = 100;
|
||||
|
||||
public $showFilters = false;
|
||||
|
||||
// Inspection workflow
|
||||
public $inspectionResult = '';
|
||||
|
||||
public $inspectionNotes = '';
|
||||
|
||||
public $inspectionPhotos = [];
|
||||
|
||||
// Issues
|
||||
@@ -69,10 +92,15 @@ class ProjectMap extends Component
|
||||
|
||||
// Inspection editor (para editar inspecciones existentes)
|
||||
public $editingInspection = null;
|
||||
|
||||
public $editInspectionFormData = [];
|
||||
|
||||
public $editInspectionResult = '';
|
||||
|
||||
public $editInspectionNotes = '';
|
||||
|
||||
public $editInspectionPhotos = [];
|
||||
|
||||
public $editInspectionPhotosToDelete = [];
|
||||
|
||||
public function mount(Project $project)
|
||||
@@ -81,20 +109,20 @@ class ProjectMap extends Component
|
||||
$this->authorizeProjectAccess();
|
||||
|
||||
$this->phases = $project->phases()->with([
|
||||
'layers' => fn($q) => $q->withCount('features'),
|
||||
'layers' => fn ($q) => $q->withCount('features'),
|
||||
'layers.features',
|
||||
'layers.features.images',
|
||||
])->get();
|
||||
|
||||
// Initialize activeLayers with ALL layer IDs (not phase IDs)
|
||||
$this->activeLayers = $this->phases
|
||||
->flatMap(fn($p) => $p->layers->pluck('id'))
|
||||
->map(fn($id) => (int) $id)
|
||||
->flatMap(fn ($p) => $p->layers->pluck('id'))
|
||||
->map(fn ($id) => (int) $id)
|
||||
->toArray();
|
||||
|
||||
$this->loadTemplates();
|
||||
|
||||
$this->allFeatures = Feature::whereHas('layer.phase', function($q) use ($project) {
|
||||
$this->allFeatures = Feature::whereHas('layer.phase', function ($q) use ($project) {
|
||||
$q->where('project_id', $project->id);
|
||||
})->with(['layer.phase', 'template'])->get();
|
||||
|
||||
@@ -111,8 +139,12 @@ class ProjectMap extends Component
|
||||
private function authorizeProjectAccess(): void
|
||||
{
|
||||
$user = Auth::user();
|
||||
if ($user->can('manage all')) return;
|
||||
if (!$this->project->users()->where('user_id', $user->id)->exists()) abort(403);
|
||||
if ($user->can('manage all')) {
|
||||
return;
|
||||
}
|
||||
if (! $this->project->users()->where('user_id', $user->id)->exists()) {
|
||||
abort(403);
|
||||
}
|
||||
}
|
||||
|
||||
public function loadTemplates()
|
||||
@@ -139,9 +171,11 @@ class ProjectMap extends Component
|
||||
public function togglePhase($phaseId)
|
||||
{
|
||||
$phase = $this->phases->find($phaseId);
|
||||
if (!$phase) return;
|
||||
$layerIds = $phase->layers->pluck('id')->map(fn($id) => (int) $id)->toArray();
|
||||
$allActive = !empty($layerIds) && collect($layerIds)->every(fn($id) => in_array($id, $this->activeLayers));
|
||||
if (! $phase) {
|
||||
return;
|
||||
}
|
||||
$layerIds = $phase->layers->pluck('id')->map(fn ($id) => (int) $id)->toArray();
|
||||
$allActive = ! empty($layerIds) && collect($layerIds)->every(fn ($id) => in_array($id, $this->activeLayers));
|
||||
if ($allActive) {
|
||||
$this->activeLayers = array_values(array_diff($this->activeLayers, $layerIds));
|
||||
} else {
|
||||
@@ -150,22 +184,51 @@ class ProjectMap extends Component
|
||||
$this->dispatch('layersUpdated', $this->activeLayers);
|
||||
}
|
||||
|
||||
public function openLayerModal() { $this->showLayerModal = true; }
|
||||
public function closeLayerModal() { $this->showLayerModal = false; }
|
||||
public function openLayerModal()
|
||||
{
|
||||
$this->showLayerModal = true;
|
||||
}
|
||||
|
||||
public function closeLayerModal()
|
||||
{
|
||||
$this->showLayerModal = false;
|
||||
}
|
||||
|
||||
// ─── Filters ────────────────────────────────────────────────────────────────
|
||||
|
||||
public function updatedFilterStatus() { $this->applyFilters(); }
|
||||
public function updatedFilterResponsible() { $this->applyFilters(); }
|
||||
public function updatedFilterProgressMin() { $this->applyFilters(); }
|
||||
public function updatedFilterProgressMax() { $this->applyFilters(); }
|
||||
public function updatedFilterStatus()
|
||||
{
|
||||
$this->applyFilters();
|
||||
}
|
||||
|
||||
public function updatedFilterResponsible()
|
||||
{
|
||||
$this->applyFilters();
|
||||
}
|
||||
|
||||
public function updatedFilterProgressMin()
|
||||
{
|
||||
$this->applyFilters();
|
||||
}
|
||||
|
||||
public function updatedFilterProgressMax()
|
||||
{
|
||||
$this->applyFilters();
|
||||
}
|
||||
|
||||
public function applyFilters()
|
||||
{
|
||||
$filtered = $this->allFeatures->filter(function($f) {
|
||||
if ($this->filterStatus && $f->status !== $this->filterStatus) return false;
|
||||
if ($this->filterResponsible && !str_contains(strtolower($f->responsible ?? ''), strtolower($this->filterResponsible))) return false;
|
||||
if ($f->progress < $this->filterProgressMin || $f->progress > $this->filterProgressMax) return false;
|
||||
$filtered = $this->allFeatures->filter(function ($f) {
|
||||
if ($this->filterStatus && $f->status !== $this->filterStatus) {
|
||||
return false;
|
||||
}
|
||||
if ($this->filterResponsible && ! str_contains(strtolower($f->responsible ?? ''), strtolower($this->filterResponsible))) {
|
||||
return false;
|
||||
}
|
||||
if ($f->progress < $this->filterProgressMin || $f->progress > $this->filterProgressMax) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
$this->dispatch('filtersChanged', $filtered->pluck('id')->values()->toArray());
|
||||
@@ -184,16 +247,24 @@ class ProjectMap extends Component
|
||||
|
||||
public function editFeatureStatus($status)
|
||||
{
|
||||
if (!$this->selectedFeature) return;
|
||||
if (! $this->selectedFeature) {
|
||||
return;
|
||||
}
|
||||
$feature = Feature::with('layer.phase')->findOrFail($this->selectedFeature->id);
|
||||
if ($feature->layer->phase->project_id !== $this->project->id) abort(403);
|
||||
if ($feature->layer->phase->project_id !== $this->project->id) {
|
||||
abort(403);
|
||||
}
|
||||
$feature->status = $status;
|
||||
if ($status === 'completed') $feature->progress = 100;
|
||||
if ($status === 'planned') $feature->progress = 0;
|
||||
if ($status === 'completed') {
|
||||
$feature->progress = 100;
|
||||
}
|
||||
if ($status === 'planned') {
|
||||
$feature->progress = 0;
|
||||
}
|
||||
$feature->save();
|
||||
$this->selectedFeature = $feature;
|
||||
$this->editProgress = $feature->progress;
|
||||
$this->allFeatures = $this->allFeatures->map(fn($f) => $f->id === $feature->id ? $feature : $f);
|
||||
$this->allFeatures = $this->allFeatures->map(fn ($f) => $f->id === $feature->id ? $feature : $f);
|
||||
$this->dispatch('featureStatusChanged', $feature->id, $feature->status, $feature->status_color);
|
||||
$this->dispatch('notify', 'Estado actualizado');
|
||||
}
|
||||
@@ -202,20 +273,23 @@ class ProjectMap extends Component
|
||||
{
|
||||
$feature = Feature::with('layer.phase')->findOrFail($featureId);
|
||||
$user = Auth::user();
|
||||
if (!$user->can('update progress')) {
|
||||
if (! $user->can('update progress')) {
|
||||
$this->dispatch('notify', 'Sin permisos');
|
||||
|
||||
return;
|
||||
}
|
||||
if ($feature->layer->phase->project_id !== $this->project->id) abort(403);
|
||||
if ($feature->layer->phase->project_id !== $this->project->id) {
|
||||
abort(403);
|
||||
}
|
||||
$feature->progress = min(100, max(0, $newProgress));
|
||||
$feature->save();
|
||||
$phase = $feature->layer->phase;
|
||||
$phase->progress_percent = $phase->features()->avg('progress') ?: 0;
|
||||
$phase->save();
|
||||
$phase->progressUpdates()->create([
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $user->id,
|
||||
'progress_percent' => $phase->progress_percent,
|
||||
'comment' => $comment,
|
||||
'comment' => $comment,
|
||||
]);
|
||||
$this->dispatch('progressUpdated', $featureId, $feature->progress);
|
||||
$this->dispatch('notify', 'Progreso actualizado');
|
||||
@@ -228,25 +302,33 @@ class ProjectMap extends Component
|
||||
#[On('map-select-feature')]
|
||||
public function selectFeature($featureId)
|
||||
{
|
||||
\Log::info('map-select-feature received', ['payload' => $featureId]);
|
||||
|
||||
\Log::info('[ProjectMap] map-select-feature received', ['payload' => $featureId, 'type' => gettype($featureId)]);
|
||||
|
||||
// Handle both formats: direct ID or { featureId: X }
|
||||
if (is_array($featureId) && isset($featureId['featureId'])) {
|
||||
$featureId = $featureId['featureId'];
|
||||
\Log::info('[ProjectMap] Extracted featureId from array', ['featureId' => $featureId]);
|
||||
}
|
||||
|
||||
|
||||
$this->selectedFeature = null;
|
||||
$feature = Feature::with(['template', 'layer.phase'])->find($featureId);
|
||||
if (!$feature) return;
|
||||
if ($feature->layer->phase->project_id !== $this->project->id) abort(403);
|
||||
if (! $feature) {
|
||||
\Log::warning('[ProjectMap] Feature not found', ['featureId' => $featureId]);
|
||||
|
||||
$this->selectedFeature = $feature;
|
||||
$this->selectedPhaseId = $feature->layer->phase_id;
|
||||
$this->editProgress = $feature->progress;
|
||||
$this->editResponsible = $feature->responsible ?? '';
|
||||
$this->editPhotos = $feature->properties['photos'] ?? [];
|
||||
return;
|
||||
}
|
||||
if ($feature->layer->phase->project_id !== $this->project->id) {
|
||||
\Log::warning('[ProjectMap] Feature not in project', ['featureId' => $featureId, 'projectId' => $this->project->id]);
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$this->selectedFeature = $feature;
|
||||
$this->selectedPhaseId = $feature->layer->phase_id;
|
||||
$this->editProgress = $feature->progress;
|
||||
$this->editResponsible = $feature->responsible ?? '';
|
||||
$this->editPhotos = $feature->properties['photos'] ?? [];
|
||||
$this->selectedTemplateId = $feature->template_id;
|
||||
$this->activeTab = 'edit';
|
||||
$this->activeTab = 'edit';
|
||||
|
||||
$this->loadInspectionHistory();
|
||||
$this->resetInspectionForm();
|
||||
@@ -256,8 +338,9 @@ class ProjectMap extends Component
|
||||
|
||||
public function loadInspectionHistory()
|
||||
{
|
||||
if (!$this->selectedFeature) {
|
||||
if (! $this->selectedFeature) {
|
||||
$this->inspectionHistory = [];
|
||||
|
||||
return;
|
||||
}
|
||||
$this->inspectionHistory = Inspection::where('feature_id', $this->selectedFeature->id)
|
||||
@@ -269,9 +352,9 @@ class ProjectMap extends Component
|
||||
public function resetInspectionForm()
|
||||
{
|
||||
$this->inspectionFormData = [];
|
||||
$this->inspectionResult = '';
|
||||
$this->inspectionNotes = '';
|
||||
$this->inspectionPhotos = [];
|
||||
$this->inspectionResult = '';
|
||||
$this->inspectionNotes = '';
|
||||
$this->inspectionPhotos = [];
|
||||
if ($this->selectedTemplateId) {
|
||||
$template = InspectionTemplate::find($this->selectedTemplateId);
|
||||
if ($template) {
|
||||
@@ -284,45 +367,50 @@ class ProjectMap extends Component
|
||||
|
||||
public function saveInspection()
|
||||
{
|
||||
if (!$this->selectedFeature || !$this->selectedTemplateId) {
|
||||
if (! $this->selectedFeature || ! $this->selectedTemplateId) {
|
||||
$this->dispatch('notify', 'Selecciona un elemento y un template.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Verificar permiso
|
||||
if (!auth()->user()->can('create inspections')) {
|
||||
if (! auth()->user()->can('create inspections')) {
|
||||
$this->dispatch('notify', 'Sin permisos para crear inspecciones.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$feature = Feature::with('layer.phase')->find($this->selectedFeature->id);
|
||||
if (!$feature || $feature->layer->phase->project_id !== $this->project->id) abort(403);
|
||||
if (! $feature || $feature->layer->phase->project_id !== $this->project->id) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$this->validate([
|
||||
'selectedTemplateId' => 'required|exists:inspection_templates,id',
|
||||
'inspectionPhotos.*' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:10240',
|
||||
'selectedTemplateId' => 'required|exists:inspection_templates,id',
|
||||
'inspectionPhotos.*' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:10240',
|
||||
]);
|
||||
|
||||
$template = InspectionTemplate::find($this->selectedTemplateId);
|
||||
foreach ($template->fields as $field) {
|
||||
if (($field['required'] ?? false) && empty($this->inspectionFormData[$field['name']])) {
|
||||
$this->dispatch('notify', "El campo {$field['label']} es obligatorio.");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$inspection = Inspection::create([
|
||||
'project_id' => $this->project->id,
|
||||
'layer_id' => $this->selectedFeature->layer_id,
|
||||
'feature_id' => $this->selectedFeature->id,
|
||||
'template_id' => $this->selectedTemplateId,
|
||||
'user_id' => auth()->id(),
|
||||
'project_id' => $this->project->id,
|
||||
'layer_id' => $this->selectedFeature->layer_id,
|
||||
'feature_id' => $this->selectedFeature->id,
|
||||
'template_id' => $this->selectedTemplateId,
|
||||
'user_id' => auth()->id(),
|
||||
'inspector_user_id' => auth()->id(),
|
||||
'status' => 'completed',
|
||||
'completed_at' => now(),
|
||||
'result' => $this->inspectionResult ?: null,
|
||||
'notes' => $this->inspectionNotes ?: null,
|
||||
'data' => $this->inspectionFormData,
|
||||
'status' => 'completed',
|
||||
'completed_at' => now(),
|
||||
'result' => $this->inspectionResult ?: null,
|
||||
'notes' => $this->inspectionNotes ?: null,
|
||||
'data' => $this->inspectionFormData,
|
||||
]);
|
||||
|
||||
// Fotos adjuntas a la inspección
|
||||
@@ -330,34 +418,34 @@ class ProjectMap extends Component
|
||||
$mime = $photo->getMimeType();
|
||||
$path = $photo->store("uploads/inspections/{$inspection->id}", 'public');
|
||||
$inspection->media()->create([
|
||||
'name' => $photo->getClientOriginalName(),
|
||||
'file_path' => $path,
|
||||
'file_type' => $mime,
|
||||
'name' => $photo->getClientOriginalName(),
|
||||
'file_path' => $path,
|
||||
'file_type' => $mime,
|
||||
'file_extension' => $photo->getClientOriginalExtension(),
|
||||
'file_size' => $photo->getSize(),
|
||||
'category' => str_starts_with($mime, 'image/') ? 'image' : 'document',
|
||||
'uploaded_by' => auth()->id(),
|
||||
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
||||
'file_size' => $photo->getSize(),
|
||||
'category' => str_starts_with($mime, 'image/') ? 'image' : 'document',
|
||||
'uploaded_by' => auth()->id(),
|
||||
'uuid' => (string) Str::uuid(),
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->inspectionResult === 'fail') {
|
||||
Issue::create([
|
||||
'project_id' => $this->project->id,
|
||||
'feature_id' => $this->selectedFeature->id,
|
||||
'project_id' => $this->project->id,
|
||||
'feature_id' => $this->selectedFeature->id,
|
||||
'inspection_id' => $inspection->id,
|
||||
'title' => 'Fallo en inspección: ' . ($template->name ?? 'Sin nombre'),
|
||||
'description' => $this->inspectionNotes,
|
||||
'priority' => 'high',
|
||||
'status' => 'open',
|
||||
'reported_by' => auth()->id(),
|
||||
'title' => 'Fallo en inspección: '.($template->name ?? 'Sin nombre'),
|
||||
'description' => $this->inspectionNotes,
|
||||
'priority' => 'high',
|
||||
'status' => 'open',
|
||||
'reported_by' => auth()->id(),
|
||||
]);
|
||||
$this->openIssuesCount = Issue::where('project_id', $this->project->id)
|
||||
->where('status', 'open')->count();
|
||||
$this->dispatch('notify', 'Inspección fallida — Issue creado automáticamente');
|
||||
} else {
|
||||
if (isset($this->inspectionFormData['progress'])) {
|
||||
$this->updateProgress($this->selectedFeature->id, (int)$this->inspectionFormData['progress'], 'Inspección registrada');
|
||||
$this->updateProgress($this->selectedFeature->id, (int) $this->inspectionFormData['progress'], 'Inspección registrada');
|
||||
}
|
||||
$this->dispatch('notify', 'Inspección guardada correctamente');
|
||||
}
|
||||
@@ -367,7 +455,7 @@ class ProjectMap extends Component
|
||||
->where('user_id', '!=', auth()->id())
|
||||
->get();
|
||||
foreach ($usersToNotify as $user) {
|
||||
$user->notify(new \App\Notifications\InspectionCompletedNotification($inspection));
|
||||
$user->notify(new InspectionCompletedNotification($inspection));
|
||||
}
|
||||
|
||||
// Reload global list
|
||||
@@ -382,14 +470,18 @@ class ProjectMap extends Component
|
||||
|
||||
public function assignTemplateToFeature($templateId)
|
||||
{
|
||||
if (!$this->selectedFeature) return;
|
||||
if (! $this->selectedFeature) {
|
||||
return;
|
||||
}
|
||||
$template = InspectionTemplate::where('id', $templateId)
|
||||
->where('project_id', $this->project->id)->first();
|
||||
if (!$template) abort(403);
|
||||
if (! $template) {
|
||||
abort(403);
|
||||
}
|
||||
$feature = Feature::findOrFail($this->selectedFeature->id);
|
||||
$feature->template_id = $templateId;
|
||||
$feature->save();
|
||||
$this->selectedFeature = $feature;
|
||||
$this->selectedFeature = $feature;
|
||||
$this->selectedTemplateId = $templateId;
|
||||
$this->resetInspectionForm();
|
||||
$this->dispatch('notify', 'Template asignado al elemento');
|
||||
@@ -397,10 +489,14 @@ class ProjectMap extends Component
|
||||
|
||||
public function saveFeatureProgress()
|
||||
{
|
||||
if (!$this->selectedFeature) return;
|
||||
if (! $this->selectedFeature) {
|
||||
return;
|
||||
}
|
||||
$feature = Feature::with('layer.phase')->findOrFail($this->selectedFeature->id);
|
||||
if ($feature->layer->phase->project_id !== $this->project->id) abort(403);
|
||||
$feature->progress = min(100, max(0, (int)$this->editProgress));
|
||||
if ($feature->layer->phase->project_id !== $this->project->id) {
|
||||
abort(403);
|
||||
}
|
||||
$feature->progress = min(100, max(0, (int) $this->editProgress));
|
||||
$feature->responsible = $this->editResponsible;
|
||||
$feature->save();
|
||||
$this->selectedFeature = $feature;
|
||||
@@ -424,21 +520,23 @@ class ProjectMap extends Component
|
||||
$ins = Inspection::where('project_id', $this->project->id)
|
||||
->with(['feature.layer.phase', 'template', 'user', 'media'])
|
||||
->find($id);
|
||||
if (!$ins) return;
|
||||
if (! $ins) {
|
||||
return;
|
||||
}
|
||||
$this->viewingInspection = [
|
||||
'id' => $ins->id,
|
||||
'feature_name' => $ins->feature?->name ?? '—',
|
||||
'layer_name' => $ins->feature?->layer?->name ?? '—',
|
||||
'phase_name' => $ins->feature?->layer?->phase?->name ?? '—',
|
||||
'id' => $ins->id,
|
||||
'feature_name' => $ins->feature?->name ?? '—',
|
||||
'layer_name' => $ins->feature?->layer?->name ?? '—',
|
||||
'phase_name' => $ins->feature?->layer?->phase?->name ?? '—',
|
||||
'template_name' => $ins->template?->name ?? '—',
|
||||
'user_name' => $ins->user?->name ?? '—',
|
||||
'date' => $ins->created_at->format('d/m/Y H:i'),
|
||||
'status' => $ins->status,
|
||||
'result' => $ins->result,
|
||||
'notes' => $ins->notes,
|
||||
'data' => $ins->data ?? [],
|
||||
'fields' => $ins->template?->fields ?? [],
|
||||
'photos' => $ins->media->map(fn ($m) => ['url' => $m->url, 'name' => $m->name, 'id' => $m->id])->values()->all(),
|
||||
'user_name' => $ins->user?->name ?? '—',
|
||||
'date' => $ins->created_at->format('d/m/Y H:i'),
|
||||
'status' => $ins->status,
|
||||
'result' => $ins->result,
|
||||
'notes' => $ins->notes,
|
||||
'data' => $ins->data ?? [],
|
||||
'fields' => $ins->template?->fields ?? [],
|
||||
'photos' => $ins->media->map(fn ($m) => ['url' => $m->url, 'name' => $m->name, 'id' => $m->id])->values()->all(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -455,7 +553,9 @@ class ProjectMap extends Component
|
||||
$ins = Inspection::where('project_id', $this->project->id)
|
||||
->with(['feature.layer.phase', 'template', 'user', 'media'])
|
||||
->find($id);
|
||||
if (!$ins) return;
|
||||
if (! $ins) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->editingInspection = $ins;
|
||||
$this->editInspectionFormData = $ins->data ?? [];
|
||||
@@ -480,11 +580,13 @@ class ProjectMap extends Component
|
||||
|
||||
public function deleteEditPhoto($mediaIndex)
|
||||
{
|
||||
if (!$this->editingInspection) return;
|
||||
if (! $this->editingInspection) {
|
||||
return;
|
||||
}
|
||||
$media = $this->editingInspection->media;
|
||||
if (isset($media[$mediaIndex])) {
|
||||
$m = $media[$mediaIndex];
|
||||
if (!in_array($m->id, $this->editInspectionPhotosToDelete)) {
|
||||
if (! in_array($m->id, $this->editInspectionPhotosToDelete)) {
|
||||
$this->editInspectionPhotosToDelete[] = $m->id;
|
||||
}
|
||||
}
|
||||
@@ -492,34 +594,40 @@ class ProjectMap extends Component
|
||||
|
||||
public function saveEditInspection()
|
||||
{
|
||||
if (!$this->editingInspection) return;
|
||||
|
||||
if (! $this->editingInspection) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Verificar permiso
|
||||
if (!auth()->user()->can('edit inspections')) {
|
||||
if (! auth()->user()->can('edit inspections')) {
|
||||
$this->dispatch('notify', 'Sin permisos para editar inspecciones.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->validate([
|
||||
'selectedTemplateId' => 'required|exists:inspection_templates,id',
|
||||
'editInspectionPhotos.*' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:10240',
|
||||
'selectedTemplateId' => 'required|exists:inspection_templates,id',
|
||||
'editInspectionPhotos.*' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:10240',
|
||||
'editInspectionPhotosToDelete' => 'array',
|
||||
'editInspectionPhotosToDelete.*' => 'exists:media,id',
|
||||
]);
|
||||
|
||||
$ins = $this->editingInspection;
|
||||
if ($ins->project_id !== $this->project->id) abort(403);
|
||||
if ($ins->project_id !== $this->project->id) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$template = InspectionTemplate::find($this->selectedTemplateId);
|
||||
foreach ($template->fields as $field) {
|
||||
if (($field['required'] ?? false) && empty($this->editInspectionFormData[$field['name']])) {
|
||||
$this->dispatch('notify', "El campo {$field['label']} es obligatorio.");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Eliminar fotos marcadas
|
||||
if (!empty($this->editInspectionPhotosToDelete)) {
|
||||
if (! empty($this->editInspectionPhotosToDelete)) {
|
||||
$mediaToDelete = Media::whereIn('id', $this->editInspectionPhotosToDelete)
|
||||
->where('mediable_type', Inspection::class)
|
||||
->where('mediable_id', $ins->id)
|
||||
@@ -532,9 +640,9 @@ class ProjectMap extends Component
|
||||
// Actualizar datos
|
||||
$ins->update([
|
||||
'template_id' => $this->selectedTemplateId,
|
||||
'result' => $this->editInspectionResult ?: null,
|
||||
'notes' => $this->editInspectionNotes ?: null,
|
||||
'data' => $this->editInspectionFormData,
|
||||
'result' => $this->editInspectionResult ?: null,
|
||||
'notes' => $this->editInspectionNotes ?: null,
|
||||
'data' => $this->editInspectionFormData,
|
||||
]);
|
||||
|
||||
// Añadir nuevas fotos
|
||||
@@ -542,14 +650,14 @@ class ProjectMap extends Component
|
||||
$mime = $photo->getMimeType();
|
||||
$path = $photo->store("uploads/inspections/{$ins->id}", 'public');
|
||||
$ins->media()->create([
|
||||
'name' => $photo->getClientOriginalName(),
|
||||
'file_path' => $path,
|
||||
'file_type' => $mime,
|
||||
'name' => $photo->getClientOriginalName(),
|
||||
'file_path' => $path,
|
||||
'file_type' => $mime,
|
||||
'file_extension' => $photo->getClientOriginalExtension(),
|
||||
'file_size' => $photo->getSize(),
|
||||
'category' => str_starts_with($mime, 'image/') ? 'image' : 'document',
|
||||
'uploaded_by' => auth()->id(),
|
||||
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
||||
'file_size' => $photo->getSize(),
|
||||
'category' => str_starts_with($mime, 'image/') ? 'image' : 'document',
|
||||
'uploaded_by' => auth()->id(),
|
||||
'uuid' => (string) Str::uuid(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -570,19 +678,21 @@ class ProjectMap extends Component
|
||||
public function deleteInspection($id)
|
||||
{
|
||||
\Log::info('deleteInspection: START', ['id' => $id]);
|
||||
|
||||
if (!auth()->user()->can('delete inspections')) {
|
||||
|
||||
if (! auth()->user()->can('delete inspections')) {
|
||||
$this->dispatch('notify', 'Sin permisos para eliminar inspecciones.');
|
||||
\Log::info('deleteInspection: permission denied');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$ins = Inspection::where('project_id', $this->project->id)
|
||||
->with(['feature', 'media'])
|
||||
->find($id);
|
||||
if (!$ins) {
|
||||
if (! $ins) {
|
||||
\Log::info('deleteInspection: inspection not found', ['id' => $id]);
|
||||
$this->dispatch('notify', 'Inspección no encontrada');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -612,7 +722,7 @@ class ProjectMap extends Component
|
||||
->where('user_id', '!=', auth()->id())
|
||||
->get();
|
||||
foreach ($usersToNotify as $user) {
|
||||
$user->notify(new \App\Notifications\InspectionDeletedNotification($ins));
|
||||
$user->notify(new InspectionDeletedNotification($ins));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,21 +730,25 @@ class ProjectMap extends Component
|
||||
|
||||
public function toggleFeatureImages()
|
||||
{
|
||||
$this->showFeatureImages = !$this->showFeatureImages;
|
||||
$this->showFeatureImages = ! $this->showFeatureImages;
|
||||
$this->loadFeatureImageMarkers();
|
||||
$this->dispatch('featureImagesToggled', $this->showFeatureImages, $this->featureImageMarkers);
|
||||
}
|
||||
|
||||
public function loadFeatureImageMarkers()
|
||||
{
|
||||
if (!$this->showFeatureImages) { $this->featureImageMarkers = []; return; }
|
||||
if (! $this->showFeatureImages) {
|
||||
$this->featureImageMarkers = [];
|
||||
|
||||
return;
|
||||
}
|
||||
$markers = [];
|
||||
foreach ($this->phases as $phase) {
|
||||
foreach ($phase->layers as $layer) {
|
||||
foreach ($layer->features as $feature) {
|
||||
$image = $feature->images->first();
|
||||
if ($image) {
|
||||
$geo = $feature->geometry;
|
||||
$geo = $feature->geometry;
|
||||
$coords = null;
|
||||
if ($geo && isset($geo['coordinates'])) {
|
||||
if ($geo['type'] === 'Point') {
|
||||
@@ -646,10 +760,10 @@ class ProjectMap extends Component
|
||||
if ($coords && $coords['lat'] && $coords['lng']) {
|
||||
$markers[] = [
|
||||
'feature_id' => $feature->id,
|
||||
'name' => $feature->name,
|
||||
'lat' => $coords['lat'],
|
||||
'lng' => $coords['lng'],
|
||||
'image_url' => $image->url,
|
||||
'name' => $feature->name,
|
||||
'lat' => $coords['lat'],
|
||||
'lng' => $coords['lng'],
|
||||
'image_url' => $image->url,
|
||||
'image_name' => $image->name,
|
||||
];
|
||||
}
|
||||
@@ -662,8 +776,10 @@ class ProjectMap extends Component
|
||||
|
||||
public function toggleFullscreen()
|
||||
{
|
||||
$this->formFullscreen = !$this->formFullscreen;
|
||||
if (!$this->formFullscreen) $this->dispatch('mapResize');
|
||||
$this->formFullscreen = ! $this->formFullscreen;
|
||||
if (! $this->formFullscreen) {
|
||||
$this->dispatch('mapResize');
|
||||
}
|
||||
}
|
||||
|
||||
public function setActiveTab($tab)
|
||||
@@ -675,7 +791,7 @@ class ProjectMap extends Component
|
||||
{
|
||||
return view('livewire.projects.project-map', [
|
||||
'project' => $this->project,
|
||||
'phases' => $this->phases,
|
||||
'phases' => $this->phases,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user