2026-05-07 23:31:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire;
|
|
|
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
use App\Models\Project;
|
|
|
|
|
use App\Models\Phase;
|
2026-06-17 10:36:44 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
2026-05-07 23:31:33 +02:00
|
|
|
|
|
|
|
|
class PhaseList extends Component
|
|
|
|
|
{
|
|
|
|
|
public Project $project;
|
|
|
|
|
public $phases;
|
|
|
|
|
|
|
|
|
|
public function mount(Project $project)
|
|
|
|
|
{
|
2026-06-17 10:36:44 +02:00
|
|
|
Gate::authorize('edit projects', $project);
|
2026-05-07 23:31:33 +02:00
|
|
|
$this->project = $project;
|
2026-06-17 10:36:44 +02:00
|
|
|
$this->phases = $project->phases;
|
2026-05-07 23:31:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addPhase()
|
|
|
|
|
{
|
2026-06-17 10:36:44 +02:00
|
|
|
Gate::authorize('edit projects', $this->project);
|
|
|
|
|
|
2026-05-07 23:31:33 +02:00
|
|
|
$this->project->phases()->create([
|
2026-06-17 10:36:44 +02:00
|
|
|
'name' => 'Nueva fase',
|
2026-05-07 23:31:33 +02:00
|
|
|
'order' => $this->phases->count() + 1,
|
2026-06-17 10:36:44 +02:00
|
|
|
'color' => '#' . substr(md5(random_int(0, PHP_INT_MAX)), 0, 6),
|
2026-05-07 23:31:33 +02:00
|
|
|
]);
|
|
|
|
|
$this->phases = $this->project->phases()->get();
|
|
|
|
|
session()->flash('message', 'Fase agregada');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deletePhase($phaseId)
|
|
|
|
|
{
|
2026-06-17 10:36:44 +02:00
|
|
|
Gate::authorize('edit projects', $this->project);
|
|
|
|
|
|
|
|
|
|
// Scope to this project to prevent IDOR deletion of another project's phase
|
|
|
|
|
Phase::where('id', $phaseId)
|
|
|
|
|
->where('project_id', $this->project->id)
|
|
|
|
|
->firstOrFail()
|
|
|
|
|
->delete();
|
|
|
|
|
|
2026-05-07 23:31:33 +02:00
|
|
|
$this->phases = $this->project->phases()->get();
|
2026-06-17 10:36:44 +02:00
|
|
|
session()->flash('message', 'Fase eliminada');
|
2026-05-07 23:31:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
return view('livewire.phase-list');
|
|
|
|
|
}
|
2026-06-17 10:36:44 +02:00
|
|
|
}
|