feat(issues): notificaciones, plantillas de checklist, alertas de vencimiento y reporte desde el mapa
- Notificaciones (DB): asignación de incidencia (IssueAssigned), asignación de tarea (IssueTaskAssigned), comentario (IssueCommented) y cambio de estado (IssueStatusChanged) a reporter+asignado excluyendo al actor. - Plantillas de checklist: tabla issue_checklist_templates + modelo, gestor CRUD (IssueChecklistManager, ruta projects.issues.checklists) y "Aplicar plantilla" en el detalle (alta masiva de tareas). - Alertas de vencimiento: columna overdue_notified_at + scope overdue, comando issues:notify-overdue (programado a diario) que avisa al asignado una sola vez; badge "vencidas" en la tabla y resaltado por tarea en el detalle. - Reporte desde el mapa: botón "Incidencia" en el panel del feature seleccionado → formulario con feature pre-vinculado (IssueForm lee ?feature=). Tests: IssuesEnhancementsTest (7). Suite 57 passing (solo 2 pre-existentes sqlite). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,9 +3,13 @@
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Issue;
|
||||
use App\Models\IssueChecklistTemplate;
|
||||
use App\Models\IssueComment;
|
||||
use App\Models\IssueTask;
|
||||
use App\Models\Project;
|
||||
use App\Notifications\IssueCommentedNotification;
|
||||
use App\Notifications\IssueStatusChangedNotification;
|
||||
use App\Notifications\IssueTaskAssignedNotification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Attributes\Layout;
|
||||
@@ -25,6 +29,10 @@ class IssueDetail extends Component
|
||||
public $newTaskAssignee = '';
|
||||
public $newTaskDue = '';
|
||||
|
||||
// Checklist templates
|
||||
public $checklistTemplates = [];
|
||||
public $applyTemplateId = '';
|
||||
|
||||
// New comment form
|
||||
public string $newComment = '';
|
||||
public $commentPhoto = null; // single optional photo on a comment
|
||||
@@ -46,6 +54,7 @@ class IssueDetail extends Component
|
||||
|
||||
$this->resolutionNotes = $issue->resolution_notes ?? '';
|
||||
$this->projectUsers = $project->users()->orderBy('name')->get();
|
||||
$this->checklistTemplates = IssueChecklistTemplate::where('project_id', $project->id)->orderBy('name')->get();
|
||||
$this->refreshIssue();
|
||||
}
|
||||
|
||||
@@ -61,6 +70,17 @@ class IssueDetail extends Component
|
||||
return Auth::user()->can('edit issues');
|
||||
}
|
||||
|
||||
/** Notify the issue's stakeholders (reporter + assignee), excluding the current actor. */
|
||||
private function notifyStakeholders($notification): void
|
||||
{
|
||||
$this->issue->loadMissing(['reporter', 'assignee']);
|
||||
collect([$this->issue->reporter, $this->issue->assignee])
|
||||
->filter()
|
||||
->unique('id')
|
||||
->reject(fn ($u) => $u->id === Auth::id())
|
||||
->each(fn ($u) => $u->notify($notification));
|
||||
}
|
||||
|
||||
public function refreshIssue(): void
|
||||
{
|
||||
$this->issue->load([
|
||||
@@ -82,7 +102,7 @@ class IssueDetail extends Component
|
||||
'newTaskDue' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$this->issue->tasks()->create([
|
||||
$task = $this->issue->tasks()->create([
|
||||
'title' => $this->newTaskTitle,
|
||||
'assigned_to' => $this->newTaskAssignee ?: null,
|
||||
'due_date' => $this->newTaskDue ?: null,
|
||||
@@ -90,11 +110,39 @@ class IssueDetail extends Component
|
||||
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
||||
]);
|
||||
|
||||
// Notify the assignee (unless they assigned it to themselves).
|
||||
if ($task->assigned_to && $task->assigned_to !== Auth::id()) {
|
||||
$task->loadMissing('issue');
|
||||
$task->assignee?->notify(new IssueTaskAssignedNotification($task));
|
||||
}
|
||||
|
||||
$this->reset(['newTaskTitle', 'newTaskAssignee', 'newTaskDue']);
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Tarea añadida');
|
||||
}
|
||||
|
||||
public function applyTemplate(): void
|
||||
{
|
||||
abort_unless($this->canEdit(), 403);
|
||||
$this->validate(['applyTemplateId' => 'required|exists:issue_checklist_templates,id']);
|
||||
|
||||
$template = IssueChecklistTemplate::where('project_id', $this->project->id)
|
||||
->findOrFail($this->applyTemplateId);
|
||||
|
||||
$order = (int) $this->issue->tasks()->max('order');
|
||||
foreach ($template->items ?: [] as $title) {
|
||||
$this->issue->tasks()->create([
|
||||
'title' => $title,
|
||||
'order' => ++$order,
|
||||
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->applyTemplateId = '';
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Plantilla aplicada');
|
||||
}
|
||||
|
||||
public function toggleTask($taskId): void
|
||||
{
|
||||
abort_unless($this->canEdit(), 403);
|
||||
@@ -143,6 +191,9 @@ class IssueDetail extends Component
|
||||
$this->storeUpload($this->commentPhoto, $comment, 'comment');
|
||||
}
|
||||
|
||||
$comment->setRelation('issue', $this->issue)->setRelation('user', Auth::user());
|
||||
$this->notifyStakeholders(new IssueCommentedNotification($comment));
|
||||
|
||||
$this->reset(['newComment', 'commentPhoto']);
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Comentario añadido');
|
||||
@@ -196,6 +247,7 @@ class IssueDetail extends Component
|
||||
{
|
||||
abort_unless($this->canEdit(), 403);
|
||||
$this->issue->update(['status' => 'in_review']);
|
||||
$this->notifyStakeholders(new IssueStatusChangedNotification($this->issue, 'in_review'));
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Incidencia enviada a revisión');
|
||||
}
|
||||
@@ -208,6 +260,7 @@ class IssueDetail extends Component
|
||||
'resolved_at' => $this->issue->resolved_at ?? now(),
|
||||
'resolution_notes' => $this->resolutionNotes ?: null,
|
||||
]);
|
||||
$this->notifyStakeholders(new IssueStatusChangedNotification($this->issue, 'resolved'));
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Incidencia validada y resuelta');
|
||||
}
|
||||
@@ -219,6 +272,7 @@ class IssueDetail extends Component
|
||||
'status' => 'closed',
|
||||
'resolved_at' => $this->issue->resolved_at ?? now(),
|
||||
]);
|
||||
$this->notifyStakeholders(new IssueStatusChangedNotification($this->issue, 'closed'));
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Incidencia cerrada');
|
||||
}
|
||||
@@ -227,6 +281,7 @@ class IssueDetail extends Component
|
||||
{
|
||||
abort_unless($this->canEdit(), 403);
|
||||
$this->issue->update(['status' => 'open', 'resolved_at' => null]);
|
||||
$this->notifyStakeholders(new IssueStatusChangedNotification($this->issue, 'open'));
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Incidencia reabierta');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user