refactor(livewire): organizar componentes y vistas por dominio en subnamespaces
- app/Livewire: 34 componentes agrupados en Issues/, Projects/, Phases/, Companies/, Users/, Admin/, Inspections/, Layers/, Media/, Common/ (Client/, Reports/, Forms/, Actions/ ya estaban). Namespaces actualizados. - resources/views/livewire: vistas sueltas movidas a subcarpetas espejo (companies/, users/, phases/, roles/, inspections/, media/, common/); render() actualizado. - Referencias actualizadas sin romper nada: rutas (FQN, nombres de ruta intactos), tags <livewire:...>/@livewire() a alias con punto, y use de los tests. - No tocado: Volt de Breeze (auth/profile/navigation), y el portal cliente (user-nav/client-projects) que ya tenía referencias inconsistentes. Verificado: 69 rutas OK, vistas compilan, suite 69 passing (solo 2 pre-existentes sqlite). autoload regenerado con --ignore-platform-reqs (PHP 8.2). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace App\Livewire\Phases;
|
||||
use Livewire\Component;
|
||||
use Livewire\Attributes\Layout;
|
||||
use App\Models\Project;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
#[Layout('layouts.app')]
|
||||
class PhaseGantt extends Component
|
||||
{
|
||||
public Project $project;
|
||||
public $ganttData = [];
|
||||
|
||||
public function mount(Project $project)
|
||||
{
|
||||
$user = Auth::user();
|
||||
if (!$user->can('manage all') && !$project->users()->where('user_id', $user->id)->exists()) {
|
||||
abort(403);
|
||||
}
|
||||
$this->project = $project;
|
||||
$this->loadGanttData();
|
||||
}
|
||||
|
||||
public function loadGanttData()
|
||||
{
|
||||
$phases = $this->project->phases()->with(['layers.features'])->orderBy('order')->get();
|
||||
$projectStart = $this->project->start_date ?? now()->startOfMonth();
|
||||
$projectEnd = $this->project->end_date_estimated ?? now()->addMonths(6);
|
||||
|
||||
$this->ganttData = $phases->map(function($phase) use ($projectStart, $projectEnd) {
|
||||
$planned_start = $phase->planned_start ?? $projectStart;
|
||||
$planned_end = $phase->planned_end ?? $projectEnd;
|
||||
$actual_start = $phase->actual_start;
|
||||
$actual_end = $phase->actual_end;
|
||||
|
||||
$totalDays = max(1, $projectStart->diffInDays($projectEnd));
|
||||
|
||||
$pStartOffset = max(0, $projectStart->diffInDays($planned_start));
|
||||
$pDuration = max(1, $planned_start->diffInDays($planned_end));
|
||||
$pStartPct = round(($pStartOffset / $totalDays) * 100, 2);
|
||||
$pWidthPct = round(($pDuration / $totalDays) * 100, 2);
|
||||
|
||||
$aStartPct = null; $aWidthPct = null;
|
||||
if ($actual_start) {
|
||||
$aStart = max(0, $projectStart->diffInDays($actual_start));
|
||||
$aEnd = $actual_end ?? now();
|
||||
$aDuration = max(1, $actual_start->diffInDays($aEnd));
|
||||
$aStartPct = round(($aStart / $totalDays) * 100, 2);
|
||||
$aWidthPct = round(($aDuration / $totalDays) * 100, 2);
|
||||
}
|
||||
|
||||
$isDelayed = $phase->planned_end && $phase->planned_end->isPast() && $phase->progress_percent < 100;
|
||||
|
||||
return [
|
||||
'id' => $phase->id,
|
||||
'name' => $phase->name,
|
||||
'color' => $phase->color ?? '#3b82f6',
|
||||
'progress' => $phase->progress_percent,
|
||||
'planned_start' => $planned_start->format('d/m/Y'),
|
||||
'planned_end' => $planned_end->format('d/m/Y'),
|
||||
'actual_start' => $actual_start?->format('d/m/Y'),
|
||||
'actual_end' => $actual_end?->format('d/m/Y'),
|
||||
'p_start_pct' => $pStartPct,
|
||||
'p_width_pct' => min($pWidthPct, 100 - $pStartPct),
|
||||
'a_start_pct' => $aStartPct,
|
||||
'a_width_pct' => $aWidthPct ? min($aWidthPct, 100 - $aStartPct) : null,
|
||||
'is_delayed' => $isDelayed,
|
||||
'features_count' => $phase->layers->sum(fn($l) => $l->features->count()),
|
||||
];
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
public function updatePhaseDates($phaseId, $plannedStart, $plannedEnd, $actualStart = null, $actualEnd = null)
|
||||
{
|
||||
$phase = $this->project->phases()->findOrFail($phaseId);
|
||||
$phase->update([
|
||||
'planned_start' => $plannedStart ?: null,
|
||||
'planned_end' => $plannedEnd ?: null,
|
||||
'actual_start' => $actualStart ?: null,
|
||||
'actual_end' => $actualEnd ?: null,
|
||||
]);
|
||||
$this->loadGanttData();
|
||||
$this->dispatch('notify', 'Fechas actualizadas');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.projects.phase-gantt', [
|
||||
'project' => $this->project,
|
||||
'phases' => $this->project->phases()->orderBy('order')->get(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user