2026-05-07 23:31:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire;
|
|
|
|
|
|
|
|
|
|
use Livewire\Component;
|
2026-06-17 09:32:07 +02:00
|
|
|
use Livewire\Attributes\Layout;
|
2026-05-07 23:31:33 +02:00
|
|
|
use App\Models\Phase;
|
2026-06-16 18:25:36 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2026-05-07 23:31:33 +02:00
|
|
|
|
2026-06-17 09:32:07 +02:00
|
|
|
#[Layout('layouts.app')]
|
2026-05-07 23:31:33 +02:00
|
|
|
class PhaseProgress extends Component
|
|
|
|
|
{
|
|
|
|
|
public Phase $phase;
|
|
|
|
|
public $progress;
|
|
|
|
|
public $comment = '';
|
|
|
|
|
|
|
|
|
|
public function mount(Phase $phase)
|
|
|
|
|
{
|
2026-06-16 18:25:36 +02:00
|
|
|
$user = Auth::user();
|
|
|
|
|
if (!$user->hasRole('Admin') && !$phase->project->users()->where('user_id', $user->id)->exists()) {
|
|
|
|
|
abort(403);
|
|
|
|
|
}
|
2026-05-09 21:17:36 +02:00
|
|
|
$this->phase = $phase->load('progressUpdates');
|
2026-05-07 23:31:33 +02:00
|
|
|
$this->progress = $phase->progress_percent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateProgressManual()
|
|
|
|
|
{
|
2026-06-16 18:25:36 +02:00
|
|
|
$user = Auth::user();
|
|
|
|
|
if (!$user->can('update progress') && !$user->hasRole('Admin')) {
|
|
|
|
|
session()->flash('error', 'Sin permisos para actualizar el progreso.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-05-07 23:31:33 +02:00
|
|
|
$this->validate(['progress' => 'required|integer|min:0|max:100']);
|
|
|
|
|
$this->phase->progress_percent = $this->progress;
|
|
|
|
|
$this->phase->save();
|
|
|
|
|
|
|
|
|
|
$this->phase->progressUpdates()->create([
|
|
|
|
|
'user_id' => auth()->id(),
|
|
|
|
|
'progress_percent' => $this->progress,
|
|
|
|
|
'comment' => $this->comment,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->dispatch('progressUpdated', $this->phase->id, $this->progress);
|
|
|
|
|
session()->flash('message', 'Progreso actualizado');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
return view('livewire.phase-progress');
|
|
|
|
|
}
|
|
|
|
|
}
|