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:
2026-06-18 12:51:41 +02:00
parent 3f240e5277
commit 8c774d075d
22 changed files with 818 additions and 15 deletions
@@ -0,0 +1,36 @@
<?php
namespace App\Console\Commands;
use App\Models\IssueTask;
use App\Notifications\IssueTaskOverdueNotification;
use Illuminate\Console\Command;
class NotifyOverdueIssueTasks extends Command
{
protected $signature = 'issues:notify-overdue';
protected $description = 'Notify assignees of issue tasks that are overdue (one notification per task)';
public function handle(): int
{
$tasks = IssueTask::overdue()
->whereNull('overdue_notified_at')
->whereNotNull('assigned_to')
->with(['assignee', 'issue'])
->get();
$sent = 0;
foreach ($tasks as $task) {
if ($task->assignee) {
$task->assignee->notify(new IssueTaskOverdueNotification($task));
$sent++;
}
$task->forceFill(['overdue_notified_at' => now()])->save();
}
$this->info("Tareas vencidas notificadas: {$sent}");
return self::SUCCESS;
}
}
+109
View File
@@ -0,0 +1,109 @@
<?php
namespace App\Livewire;
use App\Models\IssueChecklistTemplate;
use App\Models\Project;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Layout;
use Livewire\Component;
#[Layout('layouts.app')]
class IssueChecklistManager extends Component
{
public Project $project;
public $templates = [];
public bool $showForm = false;
public $editingId = null;
public string $name = '';
public array $items = [''];
public function mount(Project $project)
{
$this->project = $project;
abort_unless($this->canAccessProject() && Auth::user()->can('edit issues'), 403);
$this->loadTemplates();
}
private function canAccessProject(): bool
{
$user = Auth::user();
return $user->can('manage all')
|| $this->project->users()->where('user_id', $user->id)->exists();
}
public function loadTemplates(): void
{
$this->templates = IssueChecklistTemplate::where('project_id', $this->project->id)
->orderBy('name')->get();
}
public function newTemplate(): void
{
$this->reset(['editingId', 'name']);
$this->items = [''];
$this->resetErrorBag();
$this->showForm = true;
}
public function edit($id): void
{
$t = IssueChecklistTemplate::where('project_id', $this->project->id)->findOrFail($id);
$this->editingId = $t->id;
$this->name = $t->name;
$this->items = array_values($t->items ?: ['']) ?: [''];
$this->resetErrorBag();
$this->showForm = true;
}
public function addItemLine(): void
{
$this->items[] = '';
}
public function removeItemLine(int $i): void
{
unset($this->items[$i]);
$this->items = array_values($this->items);
if (empty($this->items)) {
$this->items = [''];
}
}
public function save(): void
{
$this->validate([
'name' => 'required|string|max:255',
'items' => 'required|array',
'items.*' => 'nullable|string|max:255',
]);
$items = array_values(array_filter(array_map('trim', $this->items), fn ($v) => $v !== ''));
if (empty($items)) {
$this->addError('items', 'Añade al menos una tarea.');
return;
}
IssueChecklistTemplate::updateOrCreate(
['id' => $this->editingId, 'project_id' => $this->project->id],
['name' => $this->name, 'items' => $items, 'project_id' => $this->project->id],
);
$this->showForm = false;
$this->loadTemplates();
$this->dispatch('notify', 'Plantilla guardada');
}
public function delete($id): void
{
IssueChecklistTemplate::where('project_id', $this->project->id)->findOrFail($id)->delete();
$this->loadTemplates();
$this->dispatch('notify', 'Plantilla eliminada');
}
public function render()
{
return view('livewire.issues.issue-checklist-manager');
}
}
+56 -1
View File
@@ -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');
}
+16
View File
@@ -4,6 +4,7 @@ namespace App\Livewire;
use App\Models\Issue;
use App\Models\Project;
use App\Notifications\IssueAssignedNotification;
use App\Notifications\IssueReportedNotification;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Layout;
@@ -28,6 +29,7 @@ class IssueForm extends Component
// Optional context (e.g. when reporting from a map feature)
public $featureId = null;
public $inspectionId = null;
public $featureName = null; // shown when the issue is pre-linked to a map element
public function mount(Project $project, ?Issue $issue = null)
{
@@ -50,6 +52,14 @@ class IssueForm extends Component
$this->resolutionNotes = $issue->resolution_notes ?? '';
$this->featureId = $issue->feature_id;
$this->inspectionId = $issue->inspection_id;
$this->featureName = $issue->feature?->name;
} elseif ($featureId = request()->integer('feature')) {
// Pre-link to a map element when reporting from the project map.
$feature = \App\Models\Feature::with('layer.phase')->find($featureId);
if ($feature && $feature->layer?->phase?->project_id === $project->id) {
$this->featureId = $feature->id;
$this->featureName = $feature->name;
}
}
}
@@ -92,12 +102,18 @@ class IssueForm extends Component
$payload['resolved_at'] = in_array($this->status, ['resolved', 'closed']) ? now() : null;
if ($this->issue) {
$previousAssignee = $this->issue->assigned_to;
// Don't overwrite an existing resolved date
if ($this->issue->resolved_at && in_array($this->status, ['resolved', 'closed'])) {
unset($payload['resolved_at']);
}
$this->issue->update($payload);
$issue = $this->issue;
// Notify a newly assigned user (when it changed and isn't the current actor).
if ($issue->assigned_to && $issue->assigned_to !== $previousAssignee && $issue->assigned_to !== Auth::id()) {
$issue->assignee?->notify(new IssueAssignedNotification($issue));
}
} else {
$issue = Issue::create(array_merge($payload, [
'project_id' => $this->project->id,
+6
View File
@@ -43,6 +43,9 @@ class IssueTable extends DataTableComponent
'media',
'tasks',
'tasks as tasks_done_count' => fn (Builder $q) => $q->where('is_done', true),
'tasks as overdue_tasks_count' => fn (Builder $q) => $q->where('is_done', false)
->whereNotNull('due_date')
->whereDate('due_date', '<', now()->toDateString()),
]);
}
@@ -81,6 +84,9 @@ class IssueTable extends DataTableComponent
<span class="text-xs text-base-content/50">'.$row->tasks_done_count.'/'.$row->tasks_count.' tareas</span>
</div>';
}
if ($row->overdue_tasks_count) {
$html .= '<div class="mt-1"><span class="badge badge-error badge-sm gap-1">⏰ '.$row->overdue_tasks_count.' vencida'.($row->overdue_tasks_count > 1 ? 's' : '').'</span></div>';
}
return $html;
})
->html(),
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class IssueChecklistTemplate extends Model
{
use SoftDeletes;
protected $fillable = ['project_id', 'name', 'items'];
protected $casts = ['items' => 'array'];
public function project()
{
return $this->belongsTo(Project::class);
}
}
+13 -4
View File
@@ -11,16 +11,25 @@ class IssueTask extends Model
protected $fillable = [
'issue_id', 'title', 'is_done', 'done_at', 'done_by',
'assigned_to', 'due_date', 'order',
'assigned_to', 'due_date', 'order', 'overdue_notified_at',
'uuid', 'client_updated_at',
];
protected $casts = [
'is_done' => 'boolean',
'done_at' => 'datetime',
'due_date' => 'date',
'is_done' => 'boolean',
'done_at' => 'datetime',
'due_date' => 'date',
'overdue_notified_at' => 'datetime',
];
/** Tasks that are past their due date and not yet completed. */
public function scopeOverdue($q)
{
return $q->where('is_done', false)
->whereNotNull('due_date')
->whereDate('due_date', '<', now()->toDateString());
}
public function issue() { return $this->belongsTo(Issue::class); }
public function assignee() { return $this->belongsTo(User::class, 'assigned_to'); }
public function completer() { return $this->belongsTo(User::class, 'done_by'); }
@@ -0,0 +1,30 @@
<?php
namespace App\Notifications;
use App\Models\Issue;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class IssueAssignedNotification extends Notification
{
use Queueable;
public function __construct(public Issue $issue) {}
public function via($notifiable): array
{
return ['database'];
}
public function toArray($notifiable): array
{
return [
'type' => 'issue_assigned',
'issue_id' => $this->issue->id,
'project_id' => $this->issue->project_id,
'priority' => $this->issue->priority,
'message' => "Se te ha asignado la incidencia '{$this->issue->title}'",
];
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Notifications;
use App\Models\IssueComment;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;
class IssueCommentedNotification extends Notification
{
use Queueable;
public function __construct(public IssueComment $comment) {}
public function via($notifiable): array
{
return ['database'];
}
public function toArray($notifiable): array
{
$issue = $this->comment->issue;
return [
'type' => 'issue_commented',
'issue_id' => $this->comment->issue_id,
'project_id' => $issue?->project_id,
'author' => $this->comment->user?->name,
'message' => "{$this->comment->user?->name} comentó en '{$issue?->title}': " . Str::limit($this->comment->body, 60),
];
}
}
@@ -0,0 +1,37 @@
<?php
namespace App\Notifications;
use App\Models\Issue;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class IssueStatusChangedNotification extends Notification
{
use Queueable;
public function __construct(public Issue $issue, public string $status) {}
public function via($notifiable): array
{
return ['database'];
}
public function toArray($notifiable): array
{
$label = [
'open' => 'reabierta',
'in_review' => 'enviada a revisión',
'resolved' => 'resuelta',
'closed' => 'cerrada',
][$this->status] ?? $this->status;
return [
'type' => 'issue_status_changed',
'issue_id' => $this->issue->id,
'project_id' => $this->issue->project_id,
'status' => $this->status,
'message' => "La incidencia '{$this->issue->title}' ha sido {$label}",
];
}
}
@@ -0,0 +1,31 @@
<?php
namespace App\Notifications;
use App\Models\IssueTask;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class IssueTaskAssignedNotification extends Notification
{
use Queueable;
public function __construct(public IssueTask $task) {}
public function via($notifiable): array
{
return ['database'];
}
public function toArray($notifiable): array
{
return [
'type' => 'issue_task_assigned',
'issue_id' => $this->task->issue_id,
'task_id' => $this->task->id,
'project_id' => $this->task->issue?->project_id,
'due_date' => $this->task->due_date?->toDateString(),
'message' => "Se te ha asignado la tarea '{$this->task->title}'",
];
}
}
@@ -0,0 +1,31 @@
<?php
namespace App\Notifications;
use App\Models\IssueTask;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class IssueTaskOverdueNotification extends Notification
{
use Queueable;
public function __construct(public IssueTask $task) {}
public function via($notifiable): array
{
return ['database'];
}
public function toArray($notifiable): array
{
return [
'type' => 'issue_task_overdue',
'issue_id' => $this->task->issue_id,
'task_id' => $this->task->id,
'project_id' => $this->task->issue?->project_id,
'due_date' => $this->task->due_date?->toDateString(),
'message' => "Tarea vencida: '{$this->task->title}' (venció el {$this->task->due_date?->format('d/m/Y')})",
];
}
}
@@ -0,0 +1,25 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('issue_checklist_templates', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained('projects')->cascadeOnDelete();
$table->string('name');
$table->json('items')->nullable(); // array of task titles
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('issue_checklist_templates');
}
};
@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('issue_tasks', function (Blueprint $table) {
$table->timestamp('overdue_notified_at')->nullable()->after('due_date');
});
}
public function down(): void
{
Schema::table('issue_tasks', function (Blueprint $table) {
$table->dropColumn('overdue_notified_at');
});
}
};
@@ -0,0 +1,98 @@
<div class="max-w-3xl mx-auto">
<a href="{{ route('projects.issues', $project) }}" wire:navigate
class="btn btn-ghost btn-sm gap-1 mb-3">
<x-heroicon-o-arrow-left class="w-4 h-4" /> Volver a incidencias
</a>
<div class="flex flex-wrap items-center justify-between gap-3 mb-5">
<div>
<h1 class="text-xl font-bold">Plantillas de checklist</h1>
<p class="text-sm text-base-content/60">Listas de tareas reutilizables para incidencias recurrentes · {{ $project->name }}</p>
</div>
<button wire:click="newTemplate" class="btn btn-primary btn-sm gap-2">
<x-heroicon-o-plus class="w-4 h-4" /> Nueva plantilla
</button>
</div>
{{-- List --}}
@if($templates->isEmpty())
<div class="flex flex-col items-center justify-center py-12 text-base-content/40">
<x-heroicon-o-clipboard-document-check class="w-14 h-14 mb-3" />
<p class="font-semibold">Sin plantillas</p>
<p class="text-sm">Crea una lista de tareas reutilizable para aplicarla a tus incidencias.</p>
</div>
@else
<div class="space-y-2">
@foreach($templates as $t)
<div wire:key="tpl-{{ $t->id }}" class="card bg-base-100 border border-base-300">
<div class="card-body p-4 flex-row items-center justify-between gap-3">
<div class="min-w-0">
<div class="font-semibold">{{ $t->name }}</div>
<div class="text-xs text-base-content/50">{{ count($t->items ?: []) }} tareas: {{ Str::limit(implode(' · ', $t->items ?: []), 90) }}</div>
</div>
<div class="flex items-center gap-1 shrink-0">
<button wire:click="edit({{ $t->id }})" class="btn btn-xs btn-ghost" title="Editar">
<x-heroicon-o-pencil class="w-3.5 h-3.5" />
</button>
<button wire:click="delete({{ $t->id }})" wire:confirm="¿Eliminar la plantilla '{{ $t->name }}'?"
class="btn btn-xs btn-error btn-outline" title="Eliminar">
<x-heroicon-o-trash class="w-3.5 h-3.5" />
</button>
</div>
</div>
</div>
@endforeach
</div>
@endif
{{-- Form modal --}}
@if($showForm)
<div class="fixed inset-0 z-40 bg-black/50" wire:click="$set('showForm', false)"></div>
<div class="fixed inset-0 z-50 flex items-center justify-center p-4">
<div class="bg-base-100 rounded-box shadow-2xl w-full max-w-lg max-h-[90vh] overflow-y-auto">
<div class="flex items-center justify-between p-4 border-b border-base-300">
<h3 class="font-bold">{{ $editingId ? 'Editar plantilla' : 'Nueva plantilla' }}</h3>
<button wire:click="$set('showForm', false)" class="btn btn-sm btn-ghost btn-circle">
<x-heroicon-o-x-mark class="w-4 h-4" />
</button>
</div>
<form wire:submit.prevent="save" class="p-4 space-y-3">
<div class="form-control">
<label class="label"><span class="label-text font-medium">Nombre <span class="text-error">*</span></span></label>
<input type="text" wire:model="name"
class="input input-bordered w-full @error('name') input-error @enderror"
placeholder="Ej.: Reparación de grieta" />
@error('name')<span class="text-xs text-error">{{ $message }}</span>@enderror
</div>
<div class="form-control">
<label class="label"><span class="label-text font-medium">Tareas</span></label>
<div class="space-y-2">
@foreach($items as $i => $item)
<div wire:key="item-{{ $i }}" class="flex items-center gap-2">
<input type="text" wire:model="items.{{ $i }}"
class="input input-bordered input-sm w-full"
placeholder="Descripción de la tarea..." />
<button type="button" wire:click="removeItemLine({{ $i }})"
class="btn btn-sm btn-ghost text-error">
<x-heroicon-o-x-mark class="w-4 h-4" />
</button>
</div>
@endforeach
</div>
@error('items')<span class="text-xs text-error">{{ $message }}</span>@enderror
<button type="button" wire:click="addItemLine" class="btn btn-xs btn-ghost gap-1 mt-2 w-fit">
<x-heroicon-o-plus class="w-3.5 h-3.5" /> Añadir tarea
</button>
</div>
<div class="flex justify-end gap-2 pt-2 border-t border-base-300">
<button type="button" wire:click="$set('showForm', false)" class="btn btn-ghost btn-sm">Cancelar</button>
<button type="submit" class="btn btn-primary btn-sm">Guardar</button>
</div>
</form>
</div>
</div>
@endif
</div>
@@ -161,6 +161,20 @@
<x-heroicon-o-plus class="w-4 h-4" />
</button>
</form>
@if(count($checklistTemplates))
<div class="flex items-center gap-2 mt-2 pt-2 border-t border-base-200">
<span class="text-xs text-base-content/50">Aplicar plantilla:</span>
<select wire:model="applyTemplateId" class="select select-bordered select-xs">
<option value="">Elegir...</option>
@foreach($checklistTemplates as $tpl)
<option value="{{ $tpl->id }}">{{ $tpl->name }} ({{ count($tpl->items ?: []) }})</option>
@endforeach
</select>
<button wire:click="applyTemplate" class="btn btn-xs btn-outline" @disabled(!$applyTemplateId)>Aplicar</button>
</div>
@error('applyTemplateId')<span class="text-xs text-error">{{ $message }}</span>@enderror
@endif
@endif
</div>
</div>
@@ -12,6 +12,13 @@
</h1>
<p class="text-sm text-base-content/60 mb-4">{{ $project->name }}</p>
@if($featureName)
<div class="alert alert-info py-2 mb-4 text-sm">
<x-heroicon-o-map-pin class="w-4 h-4" />
<span>Vinculada al elemento del mapa: <strong>{{ $featureName }}</strong></span>
</div>
@endif
<form wire:submit.prevent="save" class="space-y-4">
{{-- Título --}}
@@ -7,16 +7,28 @@
<h2 class="text-xl font-bold">Incidencias del proyecto</h2>
<p class="text-sm text-base-content/60">Gestión de incidencias y problemas</p>
</div>
@can('create issues')
<a
href="{{ route('projects.issues.create', $project) }}"
wire:navigate
class="btn btn-primary btn-sm gap-2"
>
<x-heroicon-o-plus class="w-4 h-4" />
Nueva incidencia
</a>
@endcan
<div class="flex items-center gap-2">
@can('edit issues')
<a
href="{{ route('projects.issues.checklists', $project) }}"
wire:navigate
class="btn btn-ghost btn-sm gap-2"
>
<x-heroicon-o-clipboard-document-check class="w-4 h-4" />
Plantillas
</a>
@endcan
@can('create issues')
<a
href="{{ route('projects.issues.create', $project) }}"
wire:navigate
class="btn btn-primary btn-sm gap-2"
>
<x-heroicon-o-plus class="w-4 h-4" />
Nueva incidencia
</a>
@endcan
</div>
</div>
{{-- ================================================================
@@ -156,6 +156,14 @@
<h3 class="font-bold text-base truncate">{{ $selectedFeature->name ?? __('Feature') }}</h3>
<p class="text-xs text-gray-500 truncate">{{ __('Phase') }}: {{ $selectedFeature->layer?->phase?->name ?? '—' }} · {{ __('Layer') }}: {{ $selectedFeature->layer?->name ?? '—' }}</p>
</div>
@can('create issues')
<a href="{{ route('projects.issues.create', ['project' => $project, 'feature' => $selectedFeature->id]) }}"
wire:navigate
class="btn btn-xs btn-error btn-outline gap-1 shrink-0" title="{{ __('Reportar incidencia') }}">
<x-heroicon-o-exclamation-triangle class="w-3.5 h-3.5" />
{{ __('Incidencia') }}
</a>
@endcan
</div>
{{-- En pantalla completa el contenido se reparte en columnas --}}
+4
View File
@@ -2,7 +2,11 @@
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schedule;
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
// Avisar a los asignados de tareas de incidencia vencidas (una vez por tarea).
Schedule::command('issues:notify-overdue')->dailyAt('07:00');
+1
View File
@@ -120,6 +120,7 @@ Route::get('/reports/dashboard', ReportsDashboard::class)->name('reports.dashboa
// Issues del proyecto
Route::get('/projects/{project}/issues', \App\Livewire\IssueManager::class)->name('projects.issues');
Route::get('/projects/{project}/issues/create', \App\Livewire\IssueForm::class)->name('projects.issues.create');
Route::get('/projects/{project}/issues/checklists', \App\Livewire\IssueChecklistManager::class)->name('projects.issues.checklists');
Route::get('/projects/{project}/issues/{issue}', \App\Livewire\IssueDetail::class)->name('projects.issues.show');
Route::get('/projects/{project}/issues/{issue}/edit', \App\Livewire\IssueForm::class)->name('projects.issues.edit');
+199
View File
@@ -0,0 +1,199 @@
<?php
namespace Tests\Feature;
use App\Livewire\IssueChecklistManager;
use App\Livewire\IssueDetail;
use App\Livewire\IssueForm;
use App\Models\Feature;
use App\Models\Issue;
use App\Models\IssueChecklistTemplate;
use App\Models\IssueTask;
use App\Models\Layer;
use App\Models\Phase;
use App\Models\Project;
use App\Models\User;
use App\Notifications\IssueCommentedNotification;
use App\Notifications\IssueStatusChangedNotification;
use App\Notifications\IssueTaskAssignedNotification;
use App\Notifications\IssueTaskOverdueNotification;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
use Spatie\Permission\Models\Permission;
use Tests\TestCase;
class IssuesEnhancementsTest extends TestCase
{
use RefreshDatabase;
private User $user;
private User $assignee;
private Project $project;
protected function setUp(): void
{
parent::setUp();
foreach (['view issues', 'create issues', 'edit issues', 'delete issues', 'upload media'] as $p) {
Permission::findOrCreate($p);
}
$this->user = User::factory()->create();
$this->user->givePermissionTo(['view issues', 'create issues', 'edit issues', 'delete issues', 'upload media']);
$this->assignee = User::factory()->create();
$this->project = Project::create([
'reference' => 'ENH-1',
'name' => 'Proyecto Enh',
'address' => 'Calle 1',
'lat' => 40.0,
'lng' => -3.0,
'start_date' => now()->toDateString(),
'end_date_estimated' => now()->addMonths(3)->toDateString(),
'status' => 'in_progress',
'created_by' => $this->user->id,
]);
$this->project->users()->attach($this->user->id, ['role_in_project' => 'supervisor']);
$this->project->users()->attach($this->assignee->id, ['role_in_project' => 'worker']);
}
private function makeIssue(array $attrs = []): Issue
{
return Issue::create(array_merge([
'project_id' => $this->project->id,
'title' => 'Incidencia enh',
'status' => 'open',
'priority' => 'medium',
'reported_by' => $this->user->id,
], $attrs));
}
private function makeFeature(): Feature
{
$phase = Phase::create([
'project_id' => $this->project->id, 'name' => 'F', 'order' => 1,
'color' => '#000', 'progress_percent' => 0,
]);
$layer = Layer::create([
'project_id' => $this->project->id, 'phase_id' => $phase->id,
'name' => 'L', 'color' => '#111', 'uploaded_by' => $this->user->id,
]);
return Feature::create([
'layer_id' => $layer->id, 'name' => 'Muro norte',
'geometry' => ['type' => 'Point', 'coordinates' => [-3.0, 40.0]],
'progress' => 0, 'status' => 'planned',
]);
}
// ── Notifications ────────────────────────────────────────────────────────────
public function test_assigning_a_task_notifies_the_assignee(): void
{
Notification::fake();
$issue = $this->makeIssue();
Livewire::actingAs($this->user)
->test(IssueDetail::class, ['project' => $this->project, 'issue' => $issue])
->set('newTaskTitle', 'Sanear zona')
->set('newTaskAssignee', $this->assignee->id)
->call('addTask');
Notification::assertSentTo($this->assignee, IssueTaskAssignedNotification::class);
}
public function test_commenting_notifies_the_assignee(): void
{
Notification::fake();
$issue = $this->makeIssue(['assigned_to' => $this->assignee->id]);
Livewire::actingAs($this->user)
->test(IssueDetail::class, ['project' => $this->project, 'issue' => $issue])
->set('newComment', 'Revisado en obra')
->call('addComment');
Notification::assertSentTo($this->assignee, IssueCommentedNotification::class);
}
public function test_resolving_notifies_stakeholders(): void
{
Notification::fake();
$issue = $this->makeIssue(['assigned_to' => $this->assignee->id]);
Livewire::actingAs($this->user)
->test(IssueDetail::class, ['project' => $this->project, 'issue' => $issue])
->call('verifyResolve');
Notification::assertSentTo($this->assignee, IssueStatusChangedNotification::class);
$this->assertEquals('resolved', $issue->fresh()->status);
}
// ── Checklist templates ────────────────────────────────────────────────────────
public function test_checklist_manager_creates_a_template(): void
{
Livewire::actingAs($this->user)
->test(IssueChecklistManager::class, ['project' => $this->project])
->set('name', 'Reparación grieta')
->set('items', ['Picar', 'Sellar', 'Pintar'])
->call('save');
$this->assertDatabaseHas('issue_checklist_templates', [
'project_id' => $this->project->id, 'name' => 'Reparación grieta',
]);
}
public function test_applying_a_template_creates_the_tasks(): void
{
$issue = $this->makeIssue();
$template = IssueChecklistTemplate::create([
'project_id' => $this->project->id,
'name' => 'Plantilla',
'items' => ['Picar', 'Sellar', 'Pintar'],
]);
Livewire::actingAs($this->user)
->test(IssueDetail::class, ['project' => $this->project, 'issue' => $issue])
->set('applyTemplateId', $template->id)
->call('applyTemplate');
$this->assertEquals(3, $issue->tasks()->count());
$this->assertEqualsCanonicalizing(['Picar', 'Sellar', 'Pintar'], $issue->tasks()->pluck('title')->all());
}
// ── Overdue alerts ───────────────────────────────────────────────────────────
public function test_overdue_command_notifies_assignee_once(): void
{
Notification::fake();
$issue = $this->makeIssue();
$task = $issue->tasks()->create([
'title' => 'Tarea vencida',
'assigned_to' => $this->assignee->id,
'due_date' => now()->subDays(2)->toDateString(),
'is_done' => false,
'uuid' => (string) \Illuminate\Support\Str::uuid(),
]);
$this->artisan('issues:notify-overdue')->assertSuccessful();
$this->artisan('issues:notify-overdue')->assertSuccessful(); // idempotent
Notification::assertSentTo($this->assignee, IssueTaskOverdueNotification::class);
Notification::assertCount(1);
$this->assertNotNull($task->fresh()->overdue_notified_at);
}
// ── Report issue from a map feature ──────────────────────────────────────────
public function test_issue_form_prelinks_feature_from_query(): void
{
$feature = $this->makeFeature();
// The create form mounts during the GET request, where it reads ?feature=.
$this->actingAs($this->user)
->get(route('projects.issues.create', ['project' => $this->project, 'feature' => $feature->id]))
->assertOk()
->assertSee('Muro norte')
->assertSee('Vinculada al elemento del mapa');
}
}