feat(issues): incidencias enriquecidas (tareas/comentarios/fotos/verificación) + tabla Rappasoft + logo
Web: - IssueTask + IssueComment (modelos, migraciones, soft-deletes, campos de sync). Issue gana tasks()/comments() y accessor de % de avance derivado de tareas. - IssueDetail (página): checklist con asignado/fecha límite/progreso, hilo de comentarios con foto por comentario, galería de fotos de la incidencia y flujo de verificación open→in_review→resolved/closed (+reabrir) con notas. - Creación/edición en páginas propias (IssueForm), sin modal; al guardar redirige al detalle. Rutas projects.issues.create/edit/show. - Listado con tabla Rappasoft (IssueTable): filtros por estado/prioridad, búsqueda, barra de progreso y acciones por fila gateadas por permisos; IssueManager queda como contenedor (cabecera + stats) que embebe la tabla. - Seguridad: pertenencia al proyecto + permisos por acción (view/create/edit/delete issues, upload/delete media) en todos los componentes. API móvil (offline): - /sync: issue_task.create/update y issue_comment.create (idempotente, LWW). - /media: parent_entity issue_task / issue_comment. - bundle + tombstones incluyen issue_tasks / issue_comments. - openapi.yaml + MOBILE_SYNC_PROTOCOL.md actualizados. Tests: MobileApiTest 23 passing (+5); IssuesTablePageTest (3) smoke de la tabla. Branding: logo RTE International — MAI Group (public/images/logo-rte.png) en login y navegación; application-logo pasa de SVG por defecto a <img>. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Issue;
|
||||
use App\Models\IssueComment;
|
||||
use App\Models\IssueTask;
|
||||
use App\Models\Project;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
#[Layout('layouts.app')]
|
||||
class IssueDetail extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public Project $project;
|
||||
public Issue $issue;
|
||||
|
||||
// New task form
|
||||
public string $newTaskTitle = '';
|
||||
public $newTaskAssignee = '';
|
||||
public $newTaskDue = '';
|
||||
|
||||
// New comment form
|
||||
public string $newComment = '';
|
||||
public $commentPhoto = null; // single optional photo on a comment
|
||||
|
||||
// Issue-level photos
|
||||
public $issuePhotos = []; // multiple
|
||||
|
||||
// Verification / resolution
|
||||
public string $resolutionNotes = '';
|
||||
|
||||
public $projectUsers = [];
|
||||
|
||||
public function mount(Project $project, Issue $issue)
|
||||
{
|
||||
abort_unless($issue->project_id === $project->id, 404);
|
||||
$this->project = $project;
|
||||
$this->issue = $issue;
|
||||
abort_unless($this->canAccessProject() && Auth::user()->can('view issues'), 403);
|
||||
|
||||
$this->resolutionNotes = $issue->resolution_notes ?? '';
|
||||
$this->projectUsers = $project->users()->orderBy('name')->get();
|
||||
$this->refreshIssue();
|
||||
}
|
||||
|
||||
private function canAccessProject(): bool
|
||||
{
|
||||
$user = Auth::user();
|
||||
return $user->can('manage all')
|
||||
|| $this->project->users()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
private function canEdit(): bool
|
||||
{
|
||||
return Auth::user()->can('edit issues');
|
||||
}
|
||||
|
||||
public function refreshIssue(): void
|
||||
{
|
||||
$this->issue->load([
|
||||
'reporter', 'assignee', 'feature',
|
||||
'tasks.assignee', 'tasks.completer',
|
||||
'comments.user', 'comments.media',
|
||||
'media.uploader',
|
||||
]);
|
||||
}
|
||||
|
||||
// ── Checklist ────────────────────────────────────────────────────────────────
|
||||
|
||||
public function addTask(): void
|
||||
{
|
||||
abort_unless($this->canEdit(), 403);
|
||||
$this->validate([
|
||||
'newTaskTitle' => 'required|string|max:255',
|
||||
'newTaskAssignee' => 'nullable|exists:users,id',
|
||||
'newTaskDue' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$this->issue->tasks()->create([
|
||||
'title' => $this->newTaskTitle,
|
||||
'assigned_to' => $this->newTaskAssignee ?: null,
|
||||
'due_date' => $this->newTaskDue ?: null,
|
||||
'order' => ((int) $this->issue->tasks()->max('order')) + 1,
|
||||
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
||||
]);
|
||||
|
||||
$this->reset(['newTaskTitle', 'newTaskAssignee', 'newTaskDue']);
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Tarea añadida');
|
||||
}
|
||||
|
||||
public function toggleTask($taskId): void
|
||||
{
|
||||
abort_unless($this->canEdit(), 403);
|
||||
$task = $this->issue->tasks()->findOrFail($taskId);
|
||||
$done = ! $task->is_done;
|
||||
$task->update([
|
||||
'is_done' => $done,
|
||||
'done_at' => $done ? now() : null,
|
||||
'done_by' => $done ? Auth::id() : null,
|
||||
]);
|
||||
$this->refreshIssue();
|
||||
}
|
||||
|
||||
public function deleteTask($taskId): void
|
||||
{
|
||||
abort_unless($this->canEdit(), 403);
|
||||
$this->issue->tasks()->findOrFail($taskId)->delete();
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Tarea eliminada');
|
||||
}
|
||||
|
||||
// ── Comments + photos ──────────────────────────────────────────────────────────
|
||||
|
||||
public function addComment(): void
|
||||
{
|
||||
// Anyone who can view the issue (and is a member) may comment / report progress.
|
||||
$this->validate([
|
||||
'newComment' => 'nullable|string|max:5000',
|
||||
'commentPhoto' => 'nullable|image|max:20480', // 20 MB
|
||||
]);
|
||||
|
||||
if (trim($this->newComment) === '' && ! $this->commentPhoto) {
|
||||
throw ValidationException::withMessages([
|
||||
'newComment' => 'Escribe un comentario o adjunta una foto.',
|
||||
]);
|
||||
}
|
||||
|
||||
$comment = $this->issue->comments()->create([
|
||||
'user_id' => Auth::id(),
|
||||
'body' => trim($this->newComment) ?: '(foto)',
|
||||
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
||||
]);
|
||||
|
||||
if ($this->commentPhoto) {
|
||||
abort_unless(Auth::user()->can('upload media'), 403);
|
||||
$this->storeUpload($this->commentPhoto, $comment, 'comment');
|
||||
}
|
||||
|
||||
$this->reset(['newComment', 'commentPhoto']);
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Comentario añadido');
|
||||
}
|
||||
|
||||
public function uploadIssuePhotos(): void
|
||||
{
|
||||
abort_unless(Auth::user()->can('upload media'), 403);
|
||||
$this->validate(['issuePhotos.*' => 'required|image|max:20480']);
|
||||
|
||||
foreach ($this->issuePhotos as $photo) {
|
||||
$this->storeUpload($photo, $this->issue, 'issue');
|
||||
}
|
||||
|
||||
$this->reset('issuePhotos');
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Fotos subidas');
|
||||
}
|
||||
|
||||
public function deleteMedia($mediaId): void
|
||||
{
|
||||
$media = \App\Models\Media::findOrFail($mediaId);
|
||||
$user = Auth::user();
|
||||
abort_unless($user->can('delete media') || $media->uploaded_by === $user->id, 403);
|
||||
$media->delete();
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Foto eliminada');
|
||||
}
|
||||
|
||||
/** Store an uploaded file on the public disk and attach it to a parent model. */
|
||||
private function storeUpload($file, $parent, string $entity): void
|
||||
{
|
||||
$mime = $file->getMimeType();
|
||||
$path = $file->store("uploads/issues/{$this->issue->id}/{$entity}", 'public');
|
||||
|
||||
$parent->media()->create([
|
||||
'name' => $file->getClientOriginalName(),
|
||||
'file_path' => $path,
|
||||
'file_type' => $mime,
|
||||
'file_extension' => $file->getClientOriginalExtension(),
|
||||
'file_size' => $file->getSize(),
|
||||
'category' => str_starts_with($mime, 'image/') ? 'image' : 'document',
|
||||
'uploaded_by' => Auth::id(),
|
||||
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
||||
]);
|
||||
}
|
||||
|
||||
// ── Status workflow (verification) ───────────────────────────────────────────────
|
||||
|
||||
public function sendToReview(): void
|
||||
{
|
||||
abort_unless($this->canEdit(), 403);
|
||||
$this->issue->update(['status' => 'in_review']);
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Incidencia enviada a revisión');
|
||||
}
|
||||
|
||||
public function verifyResolve(): void
|
||||
{
|
||||
abort_unless($this->canEdit(), 403);
|
||||
$this->issue->update([
|
||||
'status' => 'resolved',
|
||||
'resolved_at' => $this->issue->resolved_at ?? now(),
|
||||
'resolution_notes' => $this->resolutionNotes ?: null,
|
||||
]);
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Incidencia validada y resuelta');
|
||||
}
|
||||
|
||||
public function closeIssue(): void
|
||||
{
|
||||
abort_unless($this->canEdit(), 403);
|
||||
$this->issue->update([
|
||||
'status' => 'closed',
|
||||
'resolved_at' => $this->issue->resolved_at ?? now(),
|
||||
]);
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Incidencia cerrada');
|
||||
}
|
||||
|
||||
public function reopen(): void
|
||||
{
|
||||
abort_unless($this->canEdit(), 403);
|
||||
$this->issue->update(['status' => 'open', 'resolved_at' => null]);
|
||||
$this->refreshIssue();
|
||||
$this->dispatch('notify', 'Incidencia reabierta');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.issues.issue-detail', [
|
||||
'canEdit' => $this->canEdit(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user