diff --git a/app/Livewire/ProjectMap.php b/app/Livewire/ProjectMap.php index 4bc4481..d6363a1 100644 --- a/app/Livewire/ProjectMap.php +++ b/app/Livewire/ProjectMap.php @@ -37,7 +37,9 @@ class ProjectMap extends Component { $this->project = $project; // Cargar fases con sus capas y los features de esas capas (para mostrarlos en el mapa) - $this->phases = $project->phases()->with(['layers.features'])->get(); + $this->phases = $project->phases()->with(['layers' => function ($q) { + $q->withCount('features'); + }, 'layers.features'])->get(); // Por defecto mostrar todas las capas activas (todas las fases que tengan alguna capa con features) $this->activeLayers = $this->phases->pluck('id')->toArray(); $this->loadTemplates(); @@ -216,6 +218,34 @@ class ProjectMap extends Component $this->dispatch('notify', 'Template asignado al elemento'); } + /** + * Guardar progreso y responsable del feature seleccionado. + */ + public function saveFeatureProgress() + { + if (!$this->selectedFeature) return; + + $this->selectedFeature->progress = min(100, max(0, (int)$this->editProgress)); + $this->selectedFeature->responsible = $this->editResponsible; + $this->selectedFeature->save(); + + // Recalcular progreso de la fase + $phase = Phase::find($this->selectedFeature->layer->phase_id); + $phase->progress_percent = $phase->features()->avg('progress') ?: 0; + $phase->save(); + + $this->dispatch('progressUpdated', $phase->id, $phase->progress_percent); + $this->dispatch('notify', 'Progreso guardado'); + } + + /** + * Cuando cambia el template seleccionado, reiniciar el formulario. + */ + public function onTemplateChange() + { + $this->resetInspectionForm(); + } + public function toggleFullscreen() { $this->formFullscreen = !$this->formFullscreen; diff --git a/resources/views/livewire/projects/project-map.blade.php b/resources/views/livewire/projects/project-map.blade.php index e4fe63e..d4acfce 100644 --- a/resources/views/livewire/projects/project-map.blade.php +++ b/resources/views/livewire/projects/project-map.blade.php @@ -3,49 +3,62 @@
Configura las capas y elementos visibles del proyecto.
-Fase: {{ $selectedFeature->layer?->phase?->name ?? '—' }}
+Capa: {{ $selectedFeature->layer?->name ?? '—' }}
+👆
+Haz clic en un elemento del mapa para editarlo