2026-06-16 18:05:53 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire;
|
|
|
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
use Livewire\Attributes\Layout;
|
2026-06-18 12:12:39 +02:00
|
|
|
use Livewire\Attributes\On;
|
2026-06-16 18:05:53 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
use App\Models\Project;
|
|
|
|
|
use App\Models\Issue;
|
|
|
|
|
|
|
|
|
|
#[Layout('layouts.app')]
|
|
|
|
|
class IssueManager extends Component
|
|
|
|
|
{
|
|
|
|
|
public Project $project;
|
|
|
|
|
|
|
|
|
|
public function mount(Project $project)
|
|
|
|
|
{
|
|
|
|
|
$this->project = $project;
|
2026-06-18 12:12:39 +02:00
|
|
|
abort_unless($this->canAccessProject() && Auth::user()->can('view issues'), 403);
|
2026-06-16 18:05:53 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-18 12:12:39 +02:00
|
|
|
/** The current user must be a project member (or super-admin) to touch issues. */
|
|
|
|
|
private function canAccessProject(): bool
|
2026-06-16 18:05:53 +02:00
|
|
|
{
|
2026-06-18 12:12:39 +02:00
|
|
|
$user = Auth::user();
|
|
|
|
|
return $user->can('manage all')
|
|
|
|
|
|| $this->project->users()->where('user_id', $user->id)->exists();
|
2026-06-16 18:05:53 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-18 12:12:39 +02:00
|
|
|
/** Re-render the stats bar after the embedded table changes an issue. */
|
|
|
|
|
#[On('issuesChanged')]
|
|
|
|
|
public function refreshStats(): void
|
2026-06-17 14:16:14 +02:00
|
|
|
{
|
2026-06-18 12:12:39 +02:00
|
|
|
// No state to mutate — the listener simply triggers a re-render so the
|
|
|
|
|
// stat counters recompute from the database in render().
|
2026-06-16 18:05:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
2026-06-18 12:12:39 +02:00
|
|
|
$counts = Issue::where('project_id', $this->project->id)
|
|
|
|
|
->selectRaw('status, count(*) as c')
|
|
|
|
|
->groupBy('status')
|
|
|
|
|
->pluck('c', 'status');
|
|
|
|
|
|
|
|
|
|
return view('livewire.issues.issue-manager', [
|
|
|
|
|
'countOpen' => (int) ($counts['open'] ?? 0),
|
|
|
|
|
'countInReview' => (int) ($counts['in_review'] ?? 0),
|
|
|
|
|
'countResolved' => (int) ($counts['resolved'] ?? 0),
|
|
|
|
|
'countClosed' => (int) ($counts['closed'] ?? 0),
|
|
|
|
|
'countTotal' => (int) $counts->sum(),
|
|
|
|
|
]);
|
2026-06-16 18:05:53 +02:00
|
|
|
}
|
|
|
|
|
}
|