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:
@@ -5,6 +5,8 @@ namespace App\Http\Controllers\Api\V1;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Feature;
|
||||
use App\Models\Issue;
|
||||
use App\Models\IssueComment;
|
||||
use App\Models\IssueTask;
|
||||
use App\Models\Layer;
|
||||
use App\Models\Media;
|
||||
use App\Models\Phase;
|
||||
@@ -17,11 +19,13 @@ use Illuminate\Support\Str;
|
||||
class MediaController extends Controller
|
||||
{
|
||||
private array $map = [
|
||||
'feature' => Feature::class,
|
||||
'issue' => Issue::class,
|
||||
'project' => Project::class,
|
||||
'phase' => Phase::class,
|
||||
'layer' => Layer::class,
|
||||
'feature' => Feature::class,
|
||||
'issue' => Issue::class,
|
||||
'issue_task' => IssueTask::class,
|
||||
'issue_comment' => IssueComment::class,
|
||||
'project' => Project::class,
|
||||
'phase' => Phase::class,
|
||||
'layer' => Layer::class,
|
||||
];
|
||||
|
||||
/** Upload a file (multipart) and attach it to a parent record. Idempotent by uuid. */
|
||||
@@ -73,12 +77,14 @@ class MediaController extends Controller
|
||||
private function projectOf(string $entity, $parent): ?Project
|
||||
{
|
||||
return match ($entity) {
|
||||
'project' => $parent,
|
||||
'phase' => $parent->project,
|
||||
'layer' => $parent->phase?->project,
|
||||
'feature' => $parent->layer?->phase?->project,
|
||||
'issue' => $parent->project,
|
||||
default => null,
|
||||
'project' => $parent,
|
||||
'phase' => $parent->project,
|
||||
'layer' => $parent->phase?->project,
|
||||
'feature' => $parent->layer?->phase?->project,
|
||||
'issue' => $parent->project,
|
||||
'issue_task' => $parent->issue?->project,
|
||||
'issue_comment' => $parent->issue?->project,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ use App\Models\Feature;
|
||||
use App\Models\Inspection;
|
||||
use App\Models\InspectionTemplate;
|
||||
use App\Models\Issue;
|
||||
use App\Models\IssueComment;
|
||||
use App\Models\IssueTask;
|
||||
use App\Models\Layer;
|
||||
use App\Models\Media;
|
||||
use App\Models\Phase;
|
||||
@@ -49,25 +51,35 @@ class ProjectApiController extends Controller
|
||||
$issues = $changed(Issue::where('project_id', $project->id))->get();
|
||||
$templates = $changed(InspectionTemplate::where('project_id', $project->id))->get();
|
||||
|
||||
$allIssueIds = Issue::withTrashed()->where('project_id', $project->id)->pluck('id');
|
||||
$issueTasks = $changed(IssueTask::whereIn('issue_id', $allIssueIds))->get();
|
||||
$issueComments = $changed(IssueComment::whereIn('issue_id', $allIssueIds))->get();
|
||||
|
||||
$featureIds = Feature::whereIn('layer_id', $allLayerIds)->pluck('id');
|
||||
$issueIds = Issue::where('project_id', $project->id)->pluck('id');
|
||||
$media = $changed(Media::where(function ($q) use ($project, $featureIds, $issueIds) {
|
||||
$taskIds = IssueTask::whereIn('issue_id', $allIssueIds)->pluck('id');
|
||||
$commentIds = IssueComment::whereIn('issue_id', $allIssueIds)->pluck('id');
|
||||
$media = $changed(Media::where(function ($q) use ($project, $featureIds, $issueIds, $taskIds, $commentIds) {
|
||||
$q->where(fn ($w) => $w->where('mediable_type', Project::class)->where('mediable_id', $project->id))
|
||||
->orWhere(fn ($w) => $w->where('mediable_type', Feature::class)->whereIn('mediable_id', $featureIds))
|
||||
->orWhere(fn ($w) => $w->where('mediable_type', Issue::class)->whereIn('mediable_id', $issueIds));
|
||||
->orWhere(fn ($w) => $w->where('mediable_type', Issue::class)->whereIn('mediable_id', $issueIds))
|
||||
->orWhere(fn ($w) => $w->where('mediable_type', IssueTask::class)->whereIn('mediable_id', $taskIds))
|
||||
->orWhere(fn ($w) => $w->where('mediable_type', IssueComment::class)->whereIn('mediable_id', $commentIds));
|
||||
}))->get();
|
||||
|
||||
return response()->json([
|
||||
'server_time' => now()->toIso8601String(),
|
||||
'project' => $this->mapProject($project),
|
||||
'phases' => $phases->map(fn ($p) => $this->mapPhase($p))->values(),
|
||||
'layers' => $layers->map(fn ($l) => $this->mapLayer($l))->values(),
|
||||
'features' => $features->map(fn ($f) => $this->mapFeature($f))->values(),
|
||||
'inspections' => $inspections->map(fn ($i) => $this->mapInspection($i))->values(),
|
||||
'issues' => $issues->map(fn ($i) => $this->mapIssue($i))->values(),
|
||||
'templates' => $templates->map(fn ($t) => $this->mapTemplate($t))->values(),
|
||||
'media' => $media->map(fn ($m) => $this->mapMedia($m))->values(),
|
||||
'deleted' => $since ? $this->tombstones($since, $project, $allPhaseIds, $allLayerIds) : (object) [],
|
||||
'server_time' => now()->toIso8601String(),
|
||||
'project' => $this->mapProject($project),
|
||||
'phases' => $phases->map(fn ($p) => $this->mapPhase($p))->values(),
|
||||
'layers' => $layers->map(fn ($l) => $this->mapLayer($l))->values(),
|
||||
'features' => $features->map(fn ($f) => $this->mapFeature($f))->values(),
|
||||
'inspections' => $inspections->map(fn ($i) => $this->mapInspection($i))->values(),
|
||||
'issues' => $issues->map(fn ($i) => $this->mapIssue($i))->values(),
|
||||
'issue_tasks' => $issueTasks->map(fn ($t) => $this->mapIssueTask($t))->values(),
|
||||
'issue_comments' => $issueComments->map(fn ($c) => $this->mapIssueComment($c))->values(),
|
||||
'templates' => $templates->map(fn ($t) => $this->mapTemplate($t))->values(),
|
||||
'media' => $media->map(fn ($m) => $this->mapMedia($m))->values(),
|
||||
'deleted' => $since ? $this->tombstones($since, $project, $allPhaseIds, $allLayerIds, $allIssueIds) : (object) [],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -100,14 +112,16 @@ class ProjectApiController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
private function tombstones(Carbon $since, Project $project, $allPhaseIds, $allLayerIds): array
|
||||
private function tombstones(Carbon $since, Project $project, $allPhaseIds, $allLayerIds, $allIssueIds): array
|
||||
{
|
||||
return [
|
||||
'phases' => Phase::onlyTrashed()->where('project_id', $project->id)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
'layers' => Layer::onlyTrashed()->whereIn('phase_id', $allPhaseIds)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
'features' => Feature::onlyTrashed()->whereIn('layer_id', $allLayerIds)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
'inspections' => Inspection::onlyTrashed()->where('project_id', $project->id)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
'issues' => Issue::onlyTrashed()->where('project_id', $project->id)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
'phases' => Phase::onlyTrashed()->where('project_id', $project->id)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
'layers' => Layer::onlyTrashed()->whereIn('phase_id', $allPhaseIds)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
'features' => Feature::onlyTrashed()->whereIn('layer_id', $allLayerIds)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
'inspections' => Inspection::onlyTrashed()->where('project_id', $project->id)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
'issues' => Issue::onlyTrashed()->where('project_id', $project->id)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
'issue_tasks' => IssueTask::onlyTrashed()->whereIn('issue_id', $allIssueIds)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
'issue_comments' => IssueComment::onlyTrashed()->whereIn('issue_id', $allIssueIds)->where('deleted_at', '>', $since)->pluck('id')->values(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -166,6 +180,24 @@ class ProjectApiController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
private function mapIssueTask(IssueTask $t): array
|
||||
{
|
||||
return [
|
||||
'id' => $t->id, 'issue_id' => $t->issue_id, 'title' => $t->title,
|
||||
'is_done' => $t->is_done, 'done_at' => $t->done_at?->toIso8601String(), 'done_by' => $t->done_by,
|
||||
'assigned_to' => $t->assigned_to, 'due_date' => $t->due_date?->toDateString(),
|
||||
'order' => $t->order, 'updated_at' => $t->updated_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
|
||||
private function mapIssueComment(IssueComment $c): array
|
||||
{
|
||||
return [
|
||||
'id' => $c->id, 'issue_id' => $c->issue_id, 'user_id' => $c->user_id, 'body' => $c->body,
|
||||
'created_at' => $c->created_at?->toIso8601String(), 'updated_at' => $c->updated_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
|
||||
private function mapTemplate(InspectionTemplate $t): array
|
||||
{
|
||||
return [
|
||||
@@ -180,9 +212,11 @@ class ProjectApiController extends Controller
|
||||
private function mapMedia(Media $m): array
|
||||
{
|
||||
$entity = [
|
||||
Project::class => 'project',
|
||||
Feature::class => 'feature',
|
||||
Issue::class => 'issue',
|
||||
Project::class => 'project',
|
||||
Feature::class => 'feature',
|
||||
Issue::class => 'issue',
|
||||
IssueTask::class => 'issue_task',
|
||||
IssueComment::class => 'issue_comment',
|
||||
][$m->mediable_type] ?? class_basename($m->mediable_type);
|
||||
|
||||
return [
|
||||
|
||||
@@ -6,6 +6,8 @@ use App\Http\Controllers\Controller;
|
||||
use App\Models\Feature;
|
||||
use App\Models\Inspection;
|
||||
use App\Models\Issue;
|
||||
use App\Models\IssueComment;
|
||||
use App\Models\IssueTask;
|
||||
use App\Models\Phase;
|
||||
use App\Models\ProgressUpdate;
|
||||
use App\Models\Project;
|
||||
@@ -63,6 +65,9 @@ class SyncController extends Controller
|
||||
'inspection.create' => $this->inspectionCreate($user, $uuid, $op),
|
||||
'issue.create' => $this->issueCreate($user, $uuid, $op),
|
||||
'issue.update' => $this->issueUpdate($user, $uuid, $op),
|
||||
'issue_task.create' => $this->issueTaskCreate($user, $uuid, $op),
|
||||
'issue_task.update' => $this->issueTaskUpdate($user, $uuid, $op),
|
||||
'issue_comment.create' => $this->issueCommentCreate($user, $uuid, $op),
|
||||
'feature.update' => $this->featureUpdate($user, $uuid, $op),
|
||||
default => $this->error($uuid, 'unsupported entity/op: ' . $op['entity'] . '.' . $op['op']),
|
||||
};
|
||||
@@ -245,6 +250,116 @@ class SyncController extends Controller
|
||||
return $this->applied($uuid, $issue->id);
|
||||
}
|
||||
|
||||
// ── issue_task.create / issue_task.update ──────────────────────────────────────
|
||||
|
||||
private function issueTaskCreate(User $user, string $uuid, array $op): array
|
||||
{
|
||||
if ($existing = IssueTask::where('uuid', $uuid)->first()) {
|
||||
return $this->duplicate($uuid, $existing->id);
|
||||
}
|
||||
|
||||
$v = Validator::make($op['data'], [
|
||||
'issue_id' => ['required', 'integer', 'exists:issues,id'],
|
||||
'title' => ['required', 'string', 'max:255'],
|
||||
'assigned_to' => ['nullable', 'integer', 'exists:users,id'],
|
||||
'due_date' => ['nullable', 'date'],
|
||||
'is_done' => ['nullable', 'boolean'],
|
||||
]);
|
||||
if ($v->fails()) {
|
||||
return $this->error($uuid, 'validation: ' . $v->errors()->first());
|
||||
}
|
||||
$d = $v->validated();
|
||||
|
||||
$issue = Issue::with('project')->findOrFail($d['issue_id']);
|
||||
if (! $this->canAccess($user, $issue->project) || ! $user->can('edit issues')) {
|
||||
return $this->error($uuid, 'forbidden');
|
||||
}
|
||||
|
||||
$done = $d['is_done'] ?? false;
|
||||
$task = IssueTask::create([
|
||||
'uuid' => $uuid,
|
||||
'issue_id' => $issue->id,
|
||||
'title' => $d['title'],
|
||||
'assigned_to' => $d['assigned_to'] ?? null,
|
||||
'due_date' => $d['due_date'] ?? null,
|
||||
'is_done' => $done,
|
||||
'done_at' => $done ? now() : null,
|
||||
'done_by' => $done ? $user->id : null,
|
||||
'order' => ((int) $issue->tasks()->max('order')) + 1,
|
||||
'client_updated_at' => $op['client_updated_at'] ?? null,
|
||||
]);
|
||||
|
||||
return $this->applied($uuid, $task->id);
|
||||
}
|
||||
|
||||
private function issueTaskUpdate(User $user, string $uuid, array $op): array
|
||||
{
|
||||
$v = Validator::make($op['data'], [
|
||||
'id' => ['required', 'integer', 'exists:issue_tasks,id'],
|
||||
'title' => ['nullable', 'string', 'max:255'],
|
||||
'assigned_to' => ['nullable', 'integer', 'exists:users,id'],
|
||||
'due_date' => ['nullable', 'date'],
|
||||
'is_done' => ['nullable', 'boolean'],
|
||||
]);
|
||||
if ($v->fails()) {
|
||||
return $this->error($uuid, 'validation: ' . $v->errors()->first());
|
||||
}
|
||||
$d = $v->validated();
|
||||
|
||||
$task = IssueTask::with('issue.project')->findOrFail($d['id']);
|
||||
if (! $this->canAccess($user, $task->issue?->project) || ! $user->can('edit issues')) {
|
||||
return $this->error($uuid, 'forbidden');
|
||||
}
|
||||
|
||||
if ($conflict = $this->conflict($uuid, $task, $op)) {
|
||||
return $conflict;
|
||||
}
|
||||
|
||||
if (array_key_exists('is_done', $d)) {
|
||||
$task->is_done = (bool) $d['is_done'];
|
||||
$task->done_at = $d['is_done'] ? ($task->done_at ?? now()) : null;
|
||||
$task->done_by = $d['is_done'] ? ($task->done_by ?? $user->id) : null;
|
||||
}
|
||||
$task->fill(collect($d)->only('title', 'assigned_to', 'due_date')->toArray());
|
||||
$task->client_updated_at = $op['client_updated_at'] ?? null;
|
||||
$task->save();
|
||||
|
||||
return $this->applied($uuid, $task->id);
|
||||
}
|
||||
|
||||
// ── issue_comment.create ────────────────────────────────────────────────────────
|
||||
|
||||
private function issueCommentCreate(User $user, string $uuid, array $op): array
|
||||
{
|
||||
if ($existing = IssueComment::where('uuid', $uuid)->first()) {
|
||||
return $this->duplicate($uuid, $existing->id);
|
||||
}
|
||||
|
||||
$v = Validator::make($op['data'], [
|
||||
'issue_id' => ['required', 'integer', 'exists:issues,id'],
|
||||
'body' => ['required', 'string', 'max:5000'],
|
||||
]);
|
||||
if ($v->fails()) {
|
||||
return $this->error($uuid, 'validation: ' . $v->errors()->first());
|
||||
}
|
||||
$d = $v->validated();
|
||||
|
||||
$issue = Issue::with('project')->findOrFail($d['issue_id']);
|
||||
if (! $this->canAccess($user, $issue->project) || ! $user->can('view issues')) {
|
||||
return $this->error($uuid, 'forbidden');
|
||||
}
|
||||
|
||||
$comment = IssueComment::create([
|
||||
'uuid' => $uuid,
|
||||
'issue_id' => $issue->id,
|
||||
'user_id' => $user->id,
|
||||
'body' => $d['body'],
|
||||
'client_updated_at' => $op['client_updated_at'] ?? null,
|
||||
]);
|
||||
|
||||
return $this->applied($uuid, $comment->id);
|
||||
}
|
||||
|
||||
// ── feature.update ────────────────────────────────────────────────────────────
|
||||
|
||||
private function featureUpdate(User $user, string $uuid, array $op): array
|
||||
|
||||
@@ -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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Issue;
|
||||
use App\Models\Project;
|
||||
use App\Notifications\IssueReportedNotification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Component;
|
||||
|
||||
#[Layout('layouts.app')]
|
||||
class IssueForm extends Component
|
||||
{
|
||||
public Project $project;
|
||||
public ?Issue $issue = null; // null = create, set = edit
|
||||
|
||||
public $projectUsers = [];
|
||||
|
||||
// Form fields
|
||||
public $title = '';
|
||||
public $description = '';
|
||||
public $status = 'open';
|
||||
public $priority = 'medium';
|
||||
public $assignedTo = '';
|
||||
public $resolutionNotes = '';
|
||||
|
||||
// Optional context (e.g. when reporting from a map feature)
|
||||
public $featureId = null;
|
||||
public $inspectionId = null;
|
||||
|
||||
public function mount(Project $project, ?Issue $issue = null)
|
||||
{
|
||||
$this->project = $project;
|
||||
|
||||
if ($issue) {
|
||||
abort_unless($issue->project_id === $project->id, 404);
|
||||
}
|
||||
abort_unless($this->canAccessProject() && Auth::user()->can($issue ? 'edit issues' : 'create issues'), 403);
|
||||
|
||||
$this->projectUsers = $project->users()->orderBy('name')->get();
|
||||
|
||||
if ($issue) {
|
||||
$this->issue = $issue;
|
||||
$this->title = $issue->title;
|
||||
$this->description = $issue->description ?? '';
|
||||
$this->status = $issue->status;
|
||||
$this->priority = $issue->priority;
|
||||
$this->assignedTo = $issue->assigned_to ?? '';
|
||||
$this->resolutionNotes = $issue->resolution_notes ?? '';
|
||||
$this->featureId = $issue->feature_id;
|
||||
$this->inspectionId = $issue->inspection_id;
|
||||
}
|
||||
}
|
||||
|
||||
private function canAccessProject(): bool
|
||||
{
|
||||
$user = Auth::user();
|
||||
return $user->can('manage all')
|
||||
|| $this->project->users()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'status' => 'required|in:' . implode(',', Issue::STATUSES),
|
||||
'priority' => 'required|in:' . implode(',', Issue::PRIORITIES),
|
||||
'assignedTo' => 'nullable|exists:users,id',
|
||||
'resolutionNotes' => 'nullable|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
abort_unless(Auth::user()->can($this->issue ? 'edit issues' : 'create issues'), 403);
|
||||
$this->validate();
|
||||
|
||||
$payload = [
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'status' => $this->status,
|
||||
'priority' => $this->priority,
|
||||
'feature_id' => $this->featureId,
|
||||
'inspection_id' => $this->inspectionId,
|
||||
'assigned_to' => $this->assignedTo ?: null,
|
||||
'resolution_notes' => $this->resolutionNotes ?: null,
|
||||
];
|
||||
|
||||
// Keep resolved_at in sync with the status
|
||||
$payload['resolved_at'] = in_array($this->status, ['resolved', 'closed']) ? now() : null;
|
||||
|
||||
if ($this->issue) {
|
||||
// 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;
|
||||
} else {
|
||||
$issue = Issue::create(array_merge($payload, [
|
||||
'project_id' => $this->project->id,
|
||||
'reported_by' => Auth::id(),
|
||||
]));
|
||||
|
||||
$issue->load(['feature', 'assignee']);
|
||||
$creator = $this->project->creator;
|
||||
if ($creator && $creator->id !== Auth::id()) {
|
||||
$creator->notify(new IssueReportedNotification($issue));
|
||||
}
|
||||
if ($issue->assignee && $issue->assignee->id !== Auth::id()) {
|
||||
$issue->assignee->notify(new IssueReportedNotification($issue));
|
||||
}
|
||||
}
|
||||
|
||||
session()->flash('message', $this->issue ? 'Incidencia actualizada' : 'Incidencia creada');
|
||||
|
||||
return $this->redirectRoute('projects.issues.show', ['project' => $this->project, 'issue' => $issue], navigate: true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.issues.issue-form');
|
||||
}
|
||||
}
|
||||
+24
-161
@@ -4,188 +4,51 @@ namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\On;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\Project;
|
||||
use App\Models\Issue;
|
||||
use App\Notifications\IssueReportedNotification;
|
||||
|
||||
#[Layout('layouts.app')]
|
||||
class IssueManager extends Component
|
||||
{
|
||||
public Project $project;
|
||||
|
||||
public $issues = [];
|
||||
public $projectUsers = [];
|
||||
|
||||
// Form / modal state
|
||||
public $showForm = false;
|
||||
public $editingIssue = null; // issue id when editing, null when creating
|
||||
|
||||
// Form fields
|
||||
public $title = '';
|
||||
public $description = '';
|
||||
public $status = 'open';
|
||||
public $priority = 'medium';
|
||||
public $assignedTo = '';
|
||||
public $resolutionNotes = '';
|
||||
|
||||
// Optional context (e.g. when reporting from a map feature)
|
||||
public $featureId = null;
|
||||
public $inspectionId = null;
|
||||
|
||||
public function mount(Project $project)
|
||||
{
|
||||
$this->project = $project;
|
||||
$this->loadProjectUsers();
|
||||
$this->loadIssues();
|
||||
abort_unless($this->canAccessProject() && Auth::user()->can('view issues'), 403);
|
||||
}
|
||||
|
||||
public function loadIssues()
|
||||
/** The current user must be a project member (or super-admin) to touch issues. */
|
||||
private function canAccessProject(): bool
|
||||
{
|
||||
$this->issues = Issue::where('project_id', $this->project->id)
|
||||
->with(['feature', 'reporter', 'assignee'])
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
$user = Auth::user();
|
||||
return $user->can('manage all')
|
||||
|| $this->project->users()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
public function loadProjectUsers()
|
||||
/** Re-render the stats bar after the embedded table changes an issue. */
|
||||
#[On('issuesChanged')]
|
||||
public function refreshStats(): void
|
||||
{
|
||||
$this->projectUsers = $this->project->users()->orderBy('name')->get();
|
||||
}
|
||||
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'status' => 'required|in:' . implode(',', Issue::STATUSES),
|
||||
'priority' => 'required|in:' . implode(',', Issue::PRIORITIES),
|
||||
'assignedTo' => 'nullable|exists:users,id',
|
||||
'resolutionNotes' => 'nullable|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function openForm($issueId = null)
|
||||
{
|
||||
$this->resetForm();
|
||||
|
||||
if ($issueId) {
|
||||
$issue = Issue::where('project_id', $this->project->id)->findOrFail($issueId);
|
||||
$this->editingIssue = $issue->id;
|
||||
$this->title = $issue->title;
|
||||
$this->description = $issue->description ?? '';
|
||||
$this->status = $issue->status;
|
||||
$this->priority = $issue->priority;
|
||||
$this->assignedTo = $issue->assigned_to ?? '';
|
||||
$this->resolutionNotes = $issue->resolution_notes ?? '';
|
||||
$this->featureId = $issue->feature_id;
|
||||
$this->inspectionId = $issue->inspection_id;
|
||||
}
|
||||
|
||||
$this->showForm = true;
|
||||
}
|
||||
|
||||
public function closeForm()
|
||||
{
|
||||
$this->showForm = false;
|
||||
$this->resetForm();
|
||||
}
|
||||
|
||||
private function resetForm(): void
|
||||
{
|
||||
$this->reset([
|
||||
'title', 'description', 'assignedTo', 'resolutionNotes',
|
||||
'featureId', 'inspectionId', 'editingIssue',
|
||||
]);
|
||||
$this->status = 'open';
|
||||
$this->priority = 'medium';
|
||||
$this->resetErrorBag();
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$payload = [
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'status' => $this->status,
|
||||
'priority' => $this->priority,
|
||||
'feature_id' => $this->featureId,
|
||||
'inspection_id' => $this->inspectionId,
|
||||
'assigned_to' => $this->assignedTo ?: null,
|
||||
'resolution_notes' => $this->resolutionNotes ?: null,
|
||||
];
|
||||
|
||||
// Keep resolved_at in sync with the status
|
||||
if (in_array($this->status, ['resolved', 'closed'])) {
|
||||
$payload['resolved_at'] = now();
|
||||
} else {
|
||||
$payload['resolved_at'] = null;
|
||||
}
|
||||
|
||||
if ($this->editingIssue) {
|
||||
$issue = Issue::where('project_id', $this->project->id)->findOrFail($this->editingIssue);
|
||||
// Don't overwrite an existing resolved date if it was already resolved
|
||||
if ($issue->resolved_at && in_array($this->status, ['resolved', 'closed'])) {
|
||||
unset($payload['resolved_at']);
|
||||
}
|
||||
$issue->update($payload);
|
||||
} else {
|
||||
$issue = Issue::create(array_merge($payload, [
|
||||
'project_id' => $this->project->id,
|
||||
'reported_by' => Auth::id(),
|
||||
]));
|
||||
|
||||
if ($issue->wasRecentlyCreated) {
|
||||
$issue->load(['feature', 'assignee']);
|
||||
$creator = $this->project->creator;
|
||||
if ($creator && $creator->id !== Auth::id()) {
|
||||
$creator->notify(new IssueReportedNotification($issue));
|
||||
}
|
||||
if ($issue->assignee && $issue->assignee->id !== Auth::id()) {
|
||||
$issue->assignee->notify(new IssueReportedNotification($issue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->closeForm();
|
||||
$this->loadIssues();
|
||||
$this->dispatch('notify', 'Issue guardado correctamente');
|
||||
}
|
||||
|
||||
public function resolve($issueId)
|
||||
{
|
||||
$issue = Issue::where('project_id', $this->project->id)->findOrFail($issueId);
|
||||
$issue->update([
|
||||
'status' => 'resolved',
|
||||
'resolved_at' => $issue->resolved_at ?? now(),
|
||||
]);
|
||||
$this->loadIssues();
|
||||
$this->dispatch('notify', 'Issue marcado como resuelto');
|
||||
}
|
||||
|
||||
public function close($issueId)
|
||||
{
|
||||
$issue = Issue::where('project_id', $this->project->id)->findOrFail($issueId);
|
||||
$issue->update([
|
||||
'status' => 'closed',
|
||||
'resolved_at' => $issue->resolved_at ?? now(),
|
||||
]);
|
||||
$this->loadIssues();
|
||||
$this->dispatch('notify', 'Issue cerrado');
|
||||
}
|
||||
|
||||
public function delete($issueId)
|
||||
{
|
||||
$issue = Issue::where('project_id', $this->project->id)->findOrFail($issueId);
|
||||
$issue->delete();
|
||||
$this->loadIssues();
|
||||
$this->dispatch('notify', 'Issue eliminado');
|
||||
// No state to mutate — the listener simply triggers a re-render so the
|
||||
// stat counters recompute from the database in render().
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.issues.issue-manager');
|
||||
$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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Issue;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
use Rappasoft\LaravelLivewireTables\DataTableComponent;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Column;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
|
||||
|
||||
class IssueTable extends DataTableComponent
|
||||
{
|
||||
protected $model = Issue::class;
|
||||
|
||||
public int $projectId;
|
||||
|
||||
public function configure(): void
|
||||
{
|
||||
$this->setPrimaryKey('id')
|
||||
->setDefaultSort('created_at', 'desc')
|
||||
->setSortingPillsEnabled(false)
|
||||
->setAdditionalSelects(['issues.id as id', 'issues.created_at as created_at']);
|
||||
}
|
||||
|
||||
public function builder(): Builder
|
||||
{
|
||||
// Defence in depth: only members (or super-admin) may list a project's issues.
|
||||
$user = Auth::user();
|
||||
abort_unless(
|
||||
$user->can('view issues') && (
|
||||
$user->can('manage all')
|
||||
|| \App\Models\Project::whereKey($this->projectId)->whereHas('users', fn ($q) => $q->where('user_id', $user->id))->exists()
|
||||
),
|
||||
403
|
||||
);
|
||||
|
||||
return Issue::where('issues.project_id', $this->projectId)
|
||||
->with(['feature', 'reporter', 'assignee'])
|
||||
->withCount([
|
||||
'comments',
|
||||
'media',
|
||||
'tasks',
|
||||
'tasks as tasks_done_count' => fn (Builder $q) => $q->where('is_done', true),
|
||||
]);
|
||||
}
|
||||
|
||||
public function columns(): array
|
||||
{
|
||||
return [
|
||||
Column::make('Prioridad', 'priority')
|
||||
->sortable()
|
||||
->format(function ($value, $row) {
|
||||
$label = ['low' => 'Bajo', 'medium' => 'Medio', 'high' => 'Alto', 'critical' => 'Crítico'][$value] ?? ucfirst($value);
|
||||
$textColor = in_array($value, ['critical', 'high']) ? '#fff' : '#1f2937';
|
||||
return '<span class="badge badge-sm font-semibold" style="background-color:'.$row->priority_color.';color:'.$textColor.';border-color:transparent;">'.$label.'</span>';
|
||||
})
|
||||
->html(),
|
||||
|
||||
Column::make('Título', 'title')
|
||||
->sortable()
|
||||
->searchable()
|
||||
->format(function ($value, $row) {
|
||||
$url = route('projects.issues.show', [$this->projectId, $row->id]);
|
||||
$html = '<a href="'.$url.'" wire:navigate class="font-medium text-sm link link-hover">'.e($value).'</a>';
|
||||
if ($row->description) {
|
||||
$html .= '<div class="text-xs text-base-content/50 truncate max-w-xs">'.e(Str::limit($row->description, 60)).'</div>';
|
||||
}
|
||||
$meta = [];
|
||||
if ($row->reporter) $meta[] = 'Reportado por '.e($row->reporter->name);
|
||||
if ($row->comments_count) $meta[] = '💬 '.$row->comments_count;
|
||||
if ($row->media_count) $meta[] = '📷 '.$row->media_count;
|
||||
if ($meta) {
|
||||
$html .= '<div class="text-xs text-base-content/40 mt-0.5">'.implode(' · ', $meta).'</div>';
|
||||
}
|
||||
if ($row->tasks_count) {
|
||||
$pct = (int) round($row->tasks_done_count / $row->tasks_count * 100);
|
||||
$html .= '<div class="flex items-center gap-2 mt-1 max-w-xs">
|
||||
<progress class="progress progress-success w-24 h-1.5" value="'.$pct.'" max="100"></progress>
|
||||
<span class="text-xs text-base-content/50">'.$row->tasks_done_count.'/'.$row->tasks_count.' tareas</span>
|
||||
</div>';
|
||||
}
|
||||
return $html;
|
||||
})
|
||||
->html(),
|
||||
|
||||
Column::make('Feature')
|
||||
->label(fn ($row) => $row->feature
|
||||
? '<span class="badge badge-outline badge-sm">'.e($row->feature->name).'</span>'
|
||||
: '<span class="text-base-content/30 text-xs">—</span>')
|
||||
->html(),
|
||||
|
||||
Column::make('Estado', 'status')
|
||||
->sortable()
|
||||
->format(function ($value, $row) {
|
||||
$label = ['open' => 'Abierto', 'in_review' => 'En revisión', 'resolved' => 'Resuelto', 'closed' => 'Cerrado'][$value] ?? ucfirst($value);
|
||||
return '<span class="badge badge-sm" style="background-color:'.$row->status_color.';color:#fff;border-color:transparent;">'.$label.'</span>';
|
||||
})
|
||||
->html(),
|
||||
|
||||
Column::make('Asignado a')
|
||||
->label(fn ($row) => $row->assignee
|
||||
? '<span class="text-sm">'.e($row->assignee->name).'</span>'
|
||||
: '<span class="text-base-content/30 text-xs">Sin asignar</span>')
|
||||
->html(),
|
||||
|
||||
Column::make('Fecha', 'created_at')
|
||||
->sortable()
|
||||
->format(function ($value, $row) {
|
||||
$html = $row->created_at->format('d/m/Y');
|
||||
if ($row->resolved_at) {
|
||||
$html .= '<div class="text-success text-xs">Res. '.$row->resolved_at->format('d/m/Y').'</div>';
|
||||
}
|
||||
return $html;
|
||||
})
|
||||
->html(),
|
||||
|
||||
Column::make('Acciones')
|
||||
->label(function ($row) {
|
||||
$user = Auth::user();
|
||||
$detail = route('projects.issues.show', [$this->projectId, $row->id]);
|
||||
$edit = route('projects.issues.edit', [$this->projectId, $row->id]);
|
||||
|
||||
$html = '<div class="flex items-center justify-end gap-1 flex-wrap">';
|
||||
$html .= '<a href="'.$detail.'" wire:navigate class="btn btn-xs btn-ghost" title="Abrir detalle">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"/></svg>
|
||||
</a>';
|
||||
|
||||
if ($user->can('edit issues')) {
|
||||
$html .= '<a href="'.$edit.'" wire:navigate class="btn btn-xs btn-ghost" title="Editar">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/></svg>
|
||||
</a>';
|
||||
if (in_array($row->status, ['open', 'in_review'])) {
|
||||
$html .= '<button wire:click="resolve('.$row->id.')" class="btn btn-xs btn-success" title="Marcar como resuelto">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
|
||||
</button>';
|
||||
}
|
||||
if ($row->status !== 'closed') {
|
||||
$html .= '<button wire:click="close('.$row->id.')" class="btn btn-xs btn-neutral" title="Cerrar">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
|
||||
</button>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->can('delete issues')) {
|
||||
$html .= '<button wire:click="deleteIssue('.$row->id.')" wire:confirm="¿Eliminar esta incidencia? Esta acción no se puede deshacer."
|
||||
class="btn btn-xs btn-error btn-outline" title="Eliminar">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
|
||||
</button>';
|
||||
}
|
||||
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
})
|
||||
->html(),
|
||||
];
|
||||
}
|
||||
|
||||
public function filters(): array
|
||||
{
|
||||
return [
|
||||
SelectFilter::make('Estado', 'status')
|
||||
->options([
|
||||
'' => 'Estado: todos',
|
||||
'open' => 'Abierto',
|
||||
'in_review' => 'En revisión',
|
||||
'resolved' => 'Resuelto',
|
||||
'closed' => 'Cerrado',
|
||||
])
|
||||
->filter(fn (Builder $query, string $value) => $query->where('issues.status', $value)),
|
||||
|
||||
SelectFilter::make('Prioridad', 'priority')
|
||||
->options([
|
||||
'' => 'Prioridad: todas',
|
||||
'critical' => 'Crítica',
|
||||
'high' => 'Alta',
|
||||
'medium' => 'Media',
|
||||
'low' => 'Baja',
|
||||
])
|
||||
->filter(fn (Builder $query, string $value) => $query->where('issues.priority', $value)),
|
||||
];
|
||||
}
|
||||
|
||||
// ── Row actions ────────────────────────────────────────────────────────────────
|
||||
|
||||
private function findIssue(int $id): Issue
|
||||
{
|
||||
return Issue::where('project_id', $this->projectId)->findOrFail($id);
|
||||
}
|
||||
|
||||
public function resolve(int $id): void
|
||||
{
|
||||
abort_unless(Auth::user()->can('edit issues'), 403);
|
||||
$issue = $this->findIssue($id);
|
||||
$issue->update(['status' => 'resolved', 'resolved_at' => $issue->resolved_at ?? now()]);
|
||||
$this->dispatch('issuesChanged');
|
||||
$this->dispatch('notify', 'Incidencia marcada como resuelta');
|
||||
}
|
||||
|
||||
public function close(int $id): void
|
||||
{
|
||||
abort_unless(Auth::user()->can('edit issues'), 403);
|
||||
$issue = $this->findIssue($id);
|
||||
$issue->update(['status' => 'closed', 'resolved_at' => $issue->resolved_at ?? now()]);
|
||||
$this->dispatch('issuesChanged');
|
||||
$this->dispatch('notify', 'Incidencia cerrada');
|
||||
}
|
||||
|
||||
public function deleteIssue(int $id): void
|
||||
{
|
||||
abort_unless(Auth::user()->can('delete issues'), 403);
|
||||
$this->findIssue($id)->delete();
|
||||
$this->dispatch('issuesChanged');
|
||||
$this->dispatch('notify', 'Incidencia eliminada');
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,28 @@ class Issue extends Model
|
||||
public function reporter() { return $this->belongsTo(User::class, 'reported_by'); }
|
||||
public function assignee() { return $this->belongsTo(User::class, 'assigned_to'); }
|
||||
public function media() { return $this->morphMany(Media::class, 'mediable'); }
|
||||
public function tasks() { return $this->hasMany(IssueTask::class)->orderBy('order')->orderBy('id'); }
|
||||
public function comments() { return $this->hasMany(IssueComment::class)->orderBy('created_at'); }
|
||||
|
||||
public function scopeOpen($q) { return $q->where('status', 'open'); }
|
||||
public function scopeCritical($q) { return $q->where('priority', 'critical'); }
|
||||
|
||||
/** Resolution progress derived from the checklist: done tasks / total. */
|
||||
public function getProgressAttribute(): int
|
||||
{
|
||||
$total = $this->tasks->count();
|
||||
if ($total === 0) {
|
||||
return in_array($this->status, ['resolved', 'closed'], true) ? 100 : 0;
|
||||
}
|
||||
return (int) round($this->tasks->where('is_done', true)->count() / $total * 100);
|
||||
}
|
||||
|
||||
/** True when there is at least one task and all of them are done. */
|
||||
public function getTasksCompleteAttribute(): bool
|
||||
{
|
||||
return $this->tasks->count() > 0 && $this->tasks->every(fn ($t) => $t->is_done);
|
||||
}
|
||||
|
||||
public function getPriorityColorAttribute(): string
|
||||
{
|
||||
return match($this->priority) {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class IssueComment extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'issue_id', 'user_id', 'body',
|
||||
'uuid', 'client_updated_at',
|
||||
];
|
||||
|
||||
public function issue() { return $this->belongsTo(Issue::class); }
|
||||
public function user() { return $this->belongsTo(User::class); }
|
||||
public function media() { return $this->morphMany(Media::class, 'mediable'); }
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class IssueTask extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'issue_id', 'title', 'is_done', 'done_at', 'done_by',
|
||||
'assigned_to', 'due_date', 'order',
|
||||
'uuid', 'client_updated_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_done' => 'boolean',
|
||||
'done_at' => 'datetime',
|
||||
'due_date' => 'date',
|
||||
];
|
||||
|
||||
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'); }
|
||||
public function media() { return $this->morphMany(Media::class, 'mediable'); }
|
||||
|
||||
/** Overdue = has a due date in the past and not yet done. */
|
||||
public function getIsOverdueAttribute(): bool
|
||||
{
|
||||
return ! $this->is_done && $this->due_date && $this->due_date->isPast();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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_tasks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('issue_id')->constrained('issues')->cascadeOnDelete();
|
||||
$table->string('title');
|
||||
$table->boolean('is_done')->default(false);
|
||||
$table->timestamp('done_at')->nullable();
|
||||
$table->foreignId('done_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->foreignId('assigned_to')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->date('due_date')->nullable();
|
||||
$table->integer('order')->default(0);
|
||||
|
||||
// Offline sync
|
||||
$table->uuid('uuid')->nullable()->unique();
|
||||
$table->timestamp('client_updated_at')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('issue_tasks');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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_comments', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('issue_id')->constrained('issues')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained('users');
|
||||
$table->text('body');
|
||||
|
||||
// Offline sync
|
||||
$table->uuid('uuid')->nullable()->unique();
|
||||
$table->timestamp('client_updated_at')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('issue_comments');
|
||||
}
|
||||
};
|
||||
@@ -110,3 +110,17 @@ Respuesta por operación:
|
||||
- **Fase C — PUSH:** `/sync` idempotente con validación/autorización/conflictos (recoge y endurece la lógica actual).
|
||||
- **Fase D — Media:** subida multipart + descarga.
|
||||
- **Fase E — Endurecimiento + Docs:** rate-limit, `sync_logs`, OpenAPI/Swagger como contrato para el equipo móvil.
|
||||
|
||||
---
|
||||
|
||||
## Addendum (2026-06-18): Incidencias enriquecidas — tareas, comentarios y fotos
|
||||
|
||||
El detalle de una incidencia incluye ahora un **checklist de tareas** y un **hilo de comentarios**, ambos con fotos. Todo es sincronizable offline:
|
||||
|
||||
- **Nuevas entidades de PULL** en el `bundle` (y en `deleted`): `issue_tasks`, `issue_comments`.
|
||||
- **Nuevas operaciones de PUSH** en `/sync` (idempotentes por `uuid`):
|
||||
- `issue_task.create` — `data`: `issue_id`, `title`, `assigned_to?`, `due_date?`, `is_done?`. Requiere `edit issues`.
|
||||
- `issue_task.update` — `data`: `id`, y cualquiera de `title`/`assigned_to`/`due_date`/`is_done`. Last-write-wins por `client_updated_at`. Requiere `edit issues`.
|
||||
- `issue_comment.create` — `data`: `issue_id`, `body`. Requiere `view issues`.
|
||||
- **Fotos**: `POST /media` admite `parent_entity` = `issue_task` y `issue_comment` (además de `issue`). Requiere `upload media`.
|
||||
- El **% de avance** de la incidencia se deriva de las tareas completadas (no se almacena ni se sincroniza).
|
||||
|
||||
+6
-2
@@ -130,7 +130,7 @@ paths:
|
||||
required: [uuid, parent_entity, parent_id, file]
|
||||
properties:
|
||||
uuid: { type: string, format: uuid }
|
||||
parent_entity: { type: string, enum: [feature, issue, project, phase, layer] }
|
||||
parent_entity: { type: string, enum: [feature, issue, issue_task, issue_comment, project, phase, layer] }
|
||||
parent_id: { type: integer }
|
||||
file: { type: string, format: binary }
|
||||
category: { type: string, enum: [image, document, other] }
|
||||
@@ -156,7 +156,7 @@ components:
|
||||
type: object
|
||||
required: [entity, op, uuid, data]
|
||||
properties:
|
||||
entity: { type: string, enum: [progress_update, inspection, issue, feature] }
|
||||
entity: { type: string, enum: [progress_update, inspection, issue, issue_task, issue_comment, feature] }
|
||||
op: { type: string, enum: [create, update] }
|
||||
uuid: { type: string, format: uuid, description: client-generated idempotency key }
|
||||
client_updated_at: { type: string, format: date-time }
|
||||
@@ -185,6 +185,8 @@ components:
|
||||
features: { type: array, items: { type: object } }
|
||||
inspections: { type: array, items: { type: object } }
|
||||
issues: { type: array, items: { type: object } }
|
||||
issue_tasks: { type: array, items: { type: object } }
|
||||
issue_comments: { type: array, items: { type: object } }
|
||||
templates: { type: array, items: { type: object } }
|
||||
media: { type: array, items: { type: object } }
|
||||
deleted:
|
||||
@@ -196,3 +198,5 @@ components:
|
||||
features: { type: array, items: { type: integer } }
|
||||
inspections: { type: array, items: { type: integer } }
|
||||
issues: { type: array, items: { type: integer } }
|
||||
issue_tasks: { type: array, items: { type: integer } }
|
||||
issue_comments: { type: array, items: { type: integer } }
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
@@ -1,3 +1 @@
|
||||
<svg viewBox="0 0 316 316" xmlns="http://www.w3.org/2000/svg" {{ $attributes }}>
|
||||
<path d="M305.8 81.125C305.77 80.995 305.69 80.885 305.65 80.755C305.56 80.525 305.49 80.285 305.37 80.075C305.29 79.935 305.17 79.815 305.07 79.685C304.94 79.515 304.83 79.325 304.68 79.175C304.55 79.045 304.39 78.955 304.25 78.845C304.09 78.715 303.95 78.575 303.77 78.475L251.32 48.275C249.97 47.495 248.31 47.495 246.96 48.275L194.51 78.475C194.33 78.575 194.19 78.725 194.03 78.845C193.89 78.955 193.73 79.045 193.6 79.175C193.45 79.325 193.34 79.515 193.21 79.685C193.11 79.815 192.99 79.935 192.91 80.075C192.79 80.285 192.71 80.525 192.63 80.755C192.58 80.875 192.51 80.995 192.48 81.125C192.38 81.495 192.33 81.875 192.33 82.265V139.625L148.62 164.795V52.575C148.62 52.185 148.57 51.805 148.47 51.435C148.44 51.305 148.36 51.195 148.32 51.065C148.23 50.835 148.16 50.595 148.04 50.385C147.96 50.245 147.84 50.125 147.74 49.995C147.61 49.825 147.5 49.635 147.35 49.485C147.22 49.355 147.06 49.265 146.92 49.155C146.76 49.025 146.62 48.885 146.44 48.785L93.99 18.585C92.64 17.805 90.98 17.805 89.63 18.585L37.18 48.785C37 48.885 36.86 49.035 36.7 49.155C36.56 49.265 36.4 49.355 36.27 49.485C36.12 49.635 36.01 49.825 35.88 49.995C35.78 50.125 35.66 50.245 35.58 50.385C35.46 50.595 35.38 50.835 35.3 51.065C35.25 51.185 35.18 51.305 35.15 51.435C35.05 51.805 35 52.185 35 52.575V232.235C35 233.795 35.84 235.245 37.19 236.025L142.1 296.425C142.33 296.555 142.58 296.635 142.82 296.725C142.93 296.765 143.04 296.835 143.16 296.865C143.53 296.965 143.9 297.015 144.28 297.015C144.66 297.015 145.03 296.965 145.4 296.865C145.5 296.835 145.59 296.775 145.69 296.745C145.95 296.655 146.21 296.565 146.45 296.435L251.36 236.035C252.72 235.255 253.55 233.815 253.55 232.245V174.885L303.81 145.945C305.17 145.165 306 143.725 306 142.155V82.265C305.95 81.875 305.89 81.495 305.8 81.125ZM144.2 227.205L100.57 202.515L146.39 176.135L196.66 147.195L240.33 172.335L208.29 190.625L144.2 227.205ZM244.75 114.995V164.795L226.39 154.225L201.03 139.625V89.825L219.39 100.395L244.75 114.995ZM249.12 57.105L292.81 82.265L249.12 107.425L205.43 82.265L249.12 57.105ZM114.49 184.425L96.13 194.995V85.305L121.49 70.705L139.85 60.135V169.815L114.49 184.425ZM91.76 27.425L135.45 52.585L91.76 77.745L48.07 52.585L91.76 27.425ZM43.67 60.135L62.03 70.705L87.39 85.305V202.545V202.555V202.565C87.39 202.735 87.44 202.895 87.46 203.055C87.49 203.265 87.49 203.485 87.55 203.695V203.705C87.6 203.875 87.69 204.035 87.76 204.195C87.84 204.375 87.89 204.575 87.99 204.745C87.99 204.745 87.99 204.755 88 204.755C88.09 204.905 88.22 205.035 88.33 205.175C88.45 205.335 88.55 205.495 88.69 205.635L88.7 205.645C88.82 205.765 88.98 205.855 89.12 205.965C89.28 206.085 89.42 206.225 89.59 206.325C89.6 206.325 89.6 206.325 89.61 206.335C89.62 206.335 89.62 206.345 89.63 206.345L139.87 234.775V285.065L43.67 229.705V60.135ZM244.75 229.705L148.58 285.075V234.775L219.8 194.115L244.75 179.875V229.705ZM297.2 139.625L253.49 164.795V114.995L278.85 100.395L297.21 89.825V139.625H297.2Z"/>
|
||||
</svg>
|
||||
<img src="{{ asset('images/logo-rte.png') }}" alt="RTE International — MAI Group" {{ $attributes }}>
|
||||
|
||||
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 103 B |
@@ -21,7 +21,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<a href="/" wire:navigate>
|
||||
<x-application-logo class="w-20 h-20 fill-current text-gray-500" />
|
||||
<x-application-logo class="w-28 h-28 object-contain" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
<div class="max-w-5xl mx-auto">
|
||||
|
||||
{{-- ================================================================
|
||||
BACK + HEADER
|
||||
================================================================ --}}
|
||||
@php
|
||||
$statusLabel = [
|
||||
'open' => 'Abierto', 'in_review' => 'En revisión',
|
||||
'resolved' => 'Resuelto', 'closed' => 'Cerrado',
|
||||
][$issue->status] ?? $issue->status;
|
||||
$priorityLabel = [
|
||||
'low' => 'Baja', 'medium' => 'Media', 'high' => 'Alta', 'critical' => 'Crítica',
|
||||
][$issue->priority] ?? $issue->priority;
|
||||
$doneCount = $issue->tasks->where('is_done', true)->count();
|
||||
$totalCount = $issue->tasks->count();
|
||||
@endphp
|
||||
|
||||
<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-start justify-between gap-3 mb-4">
|
||||
<div class="min-w-0">
|
||||
<h1 class="text-2xl font-bold leading-tight">{{ $issue->title }}</h1>
|
||||
<div class="flex flex-wrap items-center gap-2 mt-2">
|
||||
<span class="badge badge-sm" style="background-color: {{ $issue->status_color }}; color:#fff; border:0;">{{ $statusLabel }}</span>
|
||||
<span class="badge badge-sm" style="background-color: {{ $issue->priority_color }}; color:#fff; border:0;">Prioridad: {{ $priorityLabel }}</span>
|
||||
@if($issue->feature)
|
||||
<span class="badge badge-outline badge-sm">{{ $issue->feature->name }}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="text-xs text-base-content/50 mt-2">
|
||||
Reportado por <strong>{{ $issue->reporter?->name ?? '—' }}</strong>
|
||||
el {{ $issue->created_at->format('d/m/Y H:i') }}
|
||||
@if($issue->assignee) · Asignado a <strong>{{ $issue->assignee->name }}</strong> @endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Resolution progress --}}
|
||||
@if($totalCount > 0)
|
||||
<div class="text-right">
|
||||
<div class="radial-progress text-success" style="--value:{{ $issue->progress }}; --size:4rem;" role="progressbar">
|
||||
{{ $issue->progress }}%
|
||||
</div>
|
||||
<div class="text-xs text-base-content/50 mt-1">{{ $doneCount }}/{{ $totalCount }} tareas</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@if($issue->description)
|
||||
<div class="bg-base-200 rounded-box p-4 mb-4 text-sm whitespace-pre-line">{{ $issue->description }}</div>
|
||||
@endif
|
||||
|
||||
{{-- ================================================================
|
||||
STATUS WORKFLOW BAR
|
||||
================================================================ --}}
|
||||
@if($canEdit)
|
||||
<div class="flex flex-wrap items-center gap-2 mb-6 p-3 bg-base-100 border border-base-300 rounded-box">
|
||||
<span class="text-sm font-medium text-base-content/70 mr-1">Acciones:</span>
|
||||
|
||||
@if(in_array($issue->status, ['open']))
|
||||
<button wire:click="sendToReview" class="btn btn-sm btn-warning gap-1"
|
||||
@if($totalCount > 0 && $doneCount < $totalCount) disabled @endif>
|
||||
<x-heroicon-o-eye class="w-4 h-4" /> Enviar a revisión
|
||||
</button>
|
||||
@if($totalCount > 0 && $doneCount < $totalCount)
|
||||
<span class="text-xs text-base-content/50">Completa todas las tareas para enviar a revisión</span>
|
||||
@endif
|
||||
@endif
|
||||
|
||||
@if(in_array($issue->status, ['open', 'in_review']))
|
||||
<button wire:click="verifyResolve" class="btn btn-sm btn-success gap-1">
|
||||
<x-heroicon-o-check-badge class="w-4 h-4" /> Validar y resolver
|
||||
</button>
|
||||
@endif
|
||||
|
||||
@if($issue->status !== 'closed')
|
||||
<button wire:click="closeIssue" class="btn btn-sm btn-neutral gap-1">
|
||||
<x-heroicon-o-x-mark class="w-4 h-4" /> Cerrar
|
||||
</button>
|
||||
@endif
|
||||
|
||||
@if(in_array($issue->status, ['resolved', 'closed']))
|
||||
<button wire:click="reopen" class="btn btn-sm btn-outline gap-1">
|
||||
<x-heroicon-o-arrow-path class="w-4 h-4" /> Reabrir
|
||||
</button>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||
|
||||
{{-- ================================================================
|
||||
LEFT: CHECKLIST + COMMENTS
|
||||
================================================================ --}}
|
||||
<div class="lg:col-span-2 space-y-6">
|
||||
|
||||
{{-- CHECKLIST --}}
|
||||
<div class="card bg-base-100 border border-base-300">
|
||||
<div class="card-body p-4">
|
||||
<h2 class="font-bold flex items-center gap-2">
|
||||
<x-heroicon-o-clipboard-document-check class="w-5 h-5" />
|
||||
Tareas para resolver
|
||||
<span class="badge badge-sm">{{ $doneCount }}/{{ $totalCount }}</span>
|
||||
</h2>
|
||||
|
||||
@if($totalCount > 0)
|
||||
<progress class="progress progress-success w-full h-2 my-1" value="{{ $issue->progress }}" max="100"></progress>
|
||||
@endif
|
||||
|
||||
<ul class="divide-y divide-base-200">
|
||||
@forelse($issue->tasks as $task)
|
||||
<li wire:key="task-{{ $task->id }}" class="flex items-center gap-3 py-2">
|
||||
<input type="checkbox"
|
||||
class="checkbox checkbox-sm checkbox-success"
|
||||
@checked($task->is_done)
|
||||
@disabled(! $canEdit)
|
||||
wire:click="toggleTask({{ $task->id }})" />
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="text-sm {{ $task->is_done ? 'line-through text-base-content/40' : '' }}">{{ $task->title }}</div>
|
||||
<div class="flex flex-wrap items-center gap-2 text-xs text-base-content/50">
|
||||
@if($task->assignee)<span>👤 {{ $task->assignee->name }}</span>@endif
|
||||
@if($task->due_date)
|
||||
<span class="{{ $task->is_overdue ? 'text-error font-semibold' : '' }}">📅 {{ $task->due_date->format('d/m/Y') }}</span>
|
||||
@endif
|
||||
@if($task->is_done && $task->completer)
|
||||
<span class="text-success">✓ {{ $task->completer->name }} · {{ $task->done_at?->format('d/m/Y') }}</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@if($canEdit)
|
||||
<button wire:click="deleteTask({{ $task->id }})"
|
||||
wire:confirm="¿Eliminar esta tarea?"
|
||||
class="btn btn-xs btn-ghost text-error">
|
||||
<x-heroicon-o-trash class="w-3.5 h-3.5" />
|
||||
</button>
|
||||
@endif
|
||||
</li>
|
||||
@empty
|
||||
<li class="py-3 text-sm text-base-content/40">Aún no hay tareas. Añade la primera abajo.</li>
|
||||
@endforelse
|
||||
</ul>
|
||||
|
||||
@if($canEdit)
|
||||
<form wire:submit.prevent="addTask" class="mt-3 grid grid-cols-1 sm:grid-cols-12 gap-2 items-start">
|
||||
<div class="sm:col-span-6">
|
||||
<input type="text" wire:model="newTaskTitle"
|
||||
class="input input-bordered input-sm w-full @error('newTaskTitle') input-error @enderror"
|
||||
placeholder="Nueva tarea..." />
|
||||
@error('newTaskTitle')<span class="text-xs text-error">{{ $message }}</span>@enderror
|
||||
</div>
|
||||
<select wire:model="newTaskAssignee" class="select select-bordered select-sm sm:col-span-3">
|
||||
<option value="">Sin asignar</option>
|
||||
@foreach($projectUsers as $u)
|
||||
<option value="{{ $u->id }}">{{ $u->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<input type="date" wire:model="newTaskDue" class="input input-bordered input-sm sm:col-span-2" />
|
||||
<button type="submit" class="btn btn-sm btn-primary sm:col-span-1">
|
||||
<x-heroicon-o-plus class="w-4 h-4" />
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- COMMENTS / SEGUIMIENTO --}}
|
||||
<div class="card bg-base-100 border border-base-300">
|
||||
<div class="card-body p-4">
|
||||
<h2 class="font-bold flex items-center gap-2">
|
||||
<x-heroicon-o-chat-bubble-left-right class="w-5 h-5" />
|
||||
Seguimiento y comentarios
|
||||
<span class="badge badge-sm">{{ $issue->comments->count() }}</span>
|
||||
</h2>
|
||||
|
||||
<div class="space-y-4 mt-2">
|
||||
@forelse($issue->comments as $comment)
|
||||
<div wire:key="comment-{{ $comment->id }}" class="flex gap-3">
|
||||
<span class="w-8 h-8 rounded-full bg-primary text-primary-content flex items-center justify-center text-xs font-bold flex-shrink-0">
|
||||
{{ strtoupper(substr($comment->user?->name ?? '?', 0, 1)) }}
|
||||
</span>
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="text-sm">
|
||||
<strong>{{ $comment->user?->name ?? 'Usuario' }}</strong>
|
||||
<span class="text-xs text-base-content/40">· {{ $comment->created_at->diffForHumans() }}</span>
|
||||
</div>
|
||||
<div class="text-sm whitespace-pre-line">{{ $comment->body }}</div>
|
||||
@if($comment->media->count())
|
||||
<div class="flex flex-wrap gap-2 mt-2">
|
||||
@foreach($comment->media as $m)
|
||||
<a href="{{ $m->url }}" target="_blank" wire:key="cmedia-{{ $m->id }}">
|
||||
<img src="{{ $m->url }}" class="w-20 h-20 object-cover rounded-box border border-base-300" />
|
||||
</a>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@empty
|
||||
<p class="text-sm text-base-content/40">Sin comentarios todavía.</p>
|
||||
@endforelse
|
||||
</div>
|
||||
|
||||
{{-- New comment --}}
|
||||
<form wire:submit.prevent="addComment" class="mt-4 border-t border-base-200 pt-3 space-y-2">
|
||||
<textarea wire:model="newComment"
|
||||
class="textarea textarea-bordered w-full h-20 @error('newComment') textarea-error @enderror"
|
||||
placeholder="Escribe un comentario o nota de seguimiento..."></textarea>
|
||||
@error('newComment')<span class="text-xs text-error">{{ $message }}</span>@enderror
|
||||
<div class="flex items-center justify-between gap-2 flex-wrap">
|
||||
<label class="flex items-center gap-2 text-sm cursor-pointer">
|
||||
<x-heroicon-o-paper-clip class="w-4 h-4" />
|
||||
<input type="file" wire:model="commentPhoto" accept="image/*"
|
||||
class="file-input file-input-bordered file-input-xs max-w-xs" />
|
||||
</label>
|
||||
<button type="submit" class="btn btn-sm btn-primary gap-1"
|
||||
wire:loading.attr="disabled" wire:target="addComment,commentPhoto">
|
||||
<span wire:loading.remove wire:target="commentPhoto"><x-heroicon-o-paper-airplane class="w-4 h-4" /></span>
|
||||
<span wire:loading wire:target="commentPhoto" class="loading loading-spinner loading-xs"></span>
|
||||
Comentar
|
||||
</button>
|
||||
</div>
|
||||
@error('commentPhoto')<span class="text-xs text-error">{{ $message }}</span>@enderror
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- ================================================================
|
||||
RIGHT: PHOTOS + RESOLUTION
|
||||
================================================================ --}}
|
||||
<div class="space-y-6">
|
||||
|
||||
{{-- ISSUE PHOTOS --}}
|
||||
<div class="card bg-base-100 border border-base-300">
|
||||
<div class="card-body p-4">
|
||||
<h2 class="font-bold flex items-center gap-2">
|
||||
<x-heroicon-o-photo class="w-5 h-5" /> Fotos de la incidencia
|
||||
</h2>
|
||||
|
||||
@if($issue->media->count())
|
||||
<div class="grid grid-cols-2 gap-2 mt-2">
|
||||
@foreach($issue->media as $m)
|
||||
<div wire:key="imedia-{{ $m->id }}" class="relative group">
|
||||
<a href="{{ $m->url }}" target="_blank">
|
||||
<img src="{{ $m->url }}" class="w-full h-24 object-cover rounded-box border border-base-300" />
|
||||
</a>
|
||||
@can('delete media')
|
||||
<button wire:click="deleteMedia({{ $m->id }})" wire:confirm="¿Eliminar foto?"
|
||||
class="btn btn-xs btn-error btn-circle absolute top-1 right-1 opacity-0 group-hover:opacity-100">
|
||||
<x-heroicon-o-x-mark class="w-3 h-3" />
|
||||
</button>
|
||||
@endcan
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@else
|
||||
<p class="text-sm text-base-content/40 mt-1">Sin fotos.</p>
|
||||
@endif
|
||||
|
||||
@can('upload media')
|
||||
<form wire:submit.prevent="uploadIssuePhotos" class="mt-3 space-y-2">
|
||||
<input type="file" wire:model="issuePhotos" multiple accept="image/*"
|
||||
class="file-input file-input-bordered file-input-sm w-full" />
|
||||
@error('issuePhotos.*')<span class="text-xs text-error">{{ $message }}</span>@enderror
|
||||
@if($issuePhotos)
|
||||
<button type="submit" class="btn btn-sm btn-primary w-full gap-1"
|
||||
wire:loading.attr="disabled" wire:target="uploadIssuePhotos,issuePhotos">
|
||||
<span wire:loading wire:target="issuePhotos" class="loading loading-spinner loading-xs"></span>
|
||||
Subir {{ count($issuePhotos) }} foto(s)
|
||||
</button>
|
||||
@endif
|
||||
</form>
|
||||
@endcan
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- RESOLUTION NOTES --}}
|
||||
@if($canEdit)
|
||||
<div class="card bg-base-100 border border-base-300">
|
||||
<div class="card-body p-4">
|
||||
<h2 class="font-bold flex items-center gap-2">
|
||||
<x-heroicon-o-clipboard-document-list class="w-5 h-5" /> Notas de resolución
|
||||
</h2>
|
||||
<textarea wire:model="resolutionNotes"
|
||||
class="textarea textarea-bordered w-full h-24"
|
||||
placeholder="Cómo se resolvió la incidencia..."></textarea>
|
||||
<button wire:click="verifyResolve" class="btn btn-sm btn-success gap-1 mt-1">
|
||||
<x-heroicon-o-check-badge class="w-4 h-4" /> Guardar y resolver
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@elseif($issue->resolution_notes)
|
||||
<div class="card bg-base-100 border border-base-300">
|
||||
<div class="card-body p-4">
|
||||
<h2 class="font-bold">Notas de resolución</h2>
|
||||
<p class="text-sm whitespace-pre-line">{{ $issue->resolution_notes }}</p>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,119 @@
|
||||
<div class="max-w-2xl 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="card bg-base-100 border border-base-300">
|
||||
<div class="card-body">
|
||||
<h1 class="text-xl font-bold mb-1">
|
||||
{{ $issue ? 'Editar incidencia' : 'Nueva incidencia' }}
|
||||
</h1>
|
||||
<p class="text-sm text-base-content/60 mb-4">{{ $project->name }}</p>
|
||||
|
||||
<form wire:submit.prevent="save" class="space-y-4">
|
||||
|
||||
{{-- Título --}}
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Título <span class="text-error">*</span></span>
|
||||
</label>
|
||||
<input type="text" wire:model="title" autofocus
|
||||
class="input input-bordered w-full @error('title') input-error @enderror"
|
||||
placeholder="Describe brevemente el problema..." />
|
||||
@error('title')
|
||||
<label class="label"><span class="label-text-alt text-error">{{ $message }}</span></label>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
{{-- Descripción --}}
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text font-medium">Descripción</span></label>
|
||||
<textarea wire:model="description"
|
||||
class="textarea textarea-bordered w-full h-28 resize-y @error('description') textarea-error @enderror"
|
||||
placeholder="Detalla el problema, contexto, pasos para reproducirlo..."></textarea>
|
||||
@error('description')
|
||||
<label class="label"><span class="label-text-alt text-error">{{ $message }}</span></label>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
{{-- Prioridad + Estado --}}
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Prioridad <span class="text-error">*</span></span>
|
||||
</label>
|
||||
<select wire:model="priority"
|
||||
class="select select-bordered w-full @error('priority') select-error @enderror">
|
||||
<option value="low">Baja</option>
|
||||
<option value="medium">Media</option>
|
||||
<option value="high">Alta</option>
|
||||
<option value="critical">Crítica</option>
|
||||
</select>
|
||||
@error('priority')
|
||||
<label class="label"><span class="label-text-alt text-error">{{ $message }}</span></label>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Estado <span class="text-error">*</span></span>
|
||||
</label>
|
||||
<select wire:model.live="status"
|
||||
class="select select-bordered w-full @error('status') select-error @enderror">
|
||||
<option value="open">Abierto</option>
|
||||
<option value="in_review">En revisión</option>
|
||||
<option value="resolved">Resuelto</option>
|
||||
<option value="closed">Cerrado</option>
|
||||
</select>
|
||||
@error('status')
|
||||
<label class="label"><span class="label-text-alt text-error">{{ $message }}</span></label>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Asignado a --}}
|
||||
<div class="form-control">
|
||||
<label class="label"><span class="label-text font-medium">Asignado a</span></label>
|
||||
<select wire:model="assignedTo"
|
||||
class="select select-bordered w-full @error('assignedTo') select-error @enderror">
|
||||
<option value="">Sin asignar</option>
|
||||
@foreach($projectUsers as $user)
|
||||
<option value="{{ $user->id }}">{{ $user->name }} – {{ $user->email }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('assignedTo')
|
||||
<label class="label"><span class="label-text-alt text-error">{{ $message }}</span></label>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
{{-- Notas de resolución (visible when status = resolved or closed) --}}
|
||||
@if(in_array($status, ['resolved', 'closed']))
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Notas de resolución</span>
|
||||
<span class="label-text-alt text-base-content/50">Opcional</span>
|
||||
</label>
|
||||
<textarea wire:model="resolutionNotes"
|
||||
class="textarea textarea-bordered w-full h-20 resize-y @error('resolutionNotes') textarea-error @enderror"
|
||||
placeholder="Describe cómo se resolvió el problema..."></textarea>
|
||||
@error('resolutionNotes')
|
||||
<label class="label"><span class="label-text-alt text-error">{{ $message }}</span></label>
|
||||
@enderror
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{-- Footer --}}
|
||||
<div class="flex items-center justify-end gap-3 pt-2 border-t border-base-300">
|
||||
<a href="{{ route('projects.issues', $project) }}" wire:navigate class="btn btn-ghost">Cancelar</a>
|
||||
<button type="submit" wire:loading.attr="disabled" wire:target="save" class="btn btn-primary gap-2">
|
||||
<span wire:loading.remove wire:target="save"><x-heroicon-o-check class="w-4 h-4" /></span>
|
||||
<span wire:loading wire:target="save" class="loading loading-spinner loading-sm"></span>
|
||||
{{ $issue ? 'Actualizar incidencia' : 'Crear incidencia' }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -4,28 +4,24 @@
|
||||
================================================================ --}}
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 mb-5">
|
||||
<div>
|
||||
<h2 class="text-xl font-bold">Issues del proyecto</h2>
|
||||
<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>
|
||||
<button
|
||||
wire:click="openForm()"
|
||||
class="btn btn-primary btn-sm gap-2"
|
||||
>
|
||||
<x-heroicon-o-plus class="w-4 h-4" />
|
||||
Nuevo Issue
|
||||
</button>
|
||||
@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>
|
||||
|
||||
{{-- ================================================================
|
||||
STATS BAR
|
||||
================================================================ --}}
|
||||
@php
|
||||
$countOpen = $issues->where('status', 'open')->count();
|
||||
$countInReview = $issues->where('status', 'in_review')->count();
|
||||
$countResolved = $issues->where('status', 'resolved')->count();
|
||||
$countClosed = $issues->where('status', 'closed')->count();
|
||||
@endphp
|
||||
|
||||
<div class="flex flex-wrap gap-2 mb-5">
|
||||
<div class="stat bg-base-200 rounded-box py-2 px-4 flex-1 min-w-[120px]">
|
||||
<div class="stat-title text-xs">Abiertos</div>
|
||||
@@ -45,359 +41,12 @@
|
||||
</div>
|
||||
<div class="stat bg-base-200 rounded-box py-2 px-4 flex-1 min-w-[120px]">
|
||||
<div class="stat-title text-xs">Total</div>
|
||||
<div class="stat-value text-2xl">{{ $issues->count() }}</div>
|
||||
<div class="stat-value text-2xl">{{ $countTotal }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- ================================================================
|
||||
ISSUES TABLE
|
||||
ISSUES TABLE (Rappasoft)
|
||||
================================================================ --}}
|
||||
@if($issues->isEmpty())
|
||||
<div class="flex flex-col items-center justify-center py-16 text-base-content/40">
|
||||
<x-heroicon-o-bug-ant class="w-16 h-16 mb-3" />
|
||||
<p class="text-lg font-semibold">Sin issues registrados</p>
|
||||
<p class="text-sm">Crea el primer issue con el botón "Nuevo Issue".</p>
|
||||
</div>
|
||||
@else
|
||||
<div class="overflow-x-auto rounded-box border border-base-300">
|
||||
<table class="table table-sm w-full">
|
||||
<thead class="bg-base-200">
|
||||
<tr>
|
||||
<th class="w-28">Prioridad</th>
|
||||
<th>Título</th>
|
||||
<th class="hidden md:table-cell">Feature</th>
|
||||
<th class="w-28">Estado</th>
|
||||
<th class="hidden lg:table-cell w-36">Asignado a</th>
|
||||
<th class="hidden lg:table-cell w-28">Fecha</th>
|
||||
<th class="w-36 text-right">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($issues as $issue)
|
||||
<tr wire:key="issue-{{ $issue->id }}" class="hover">
|
||||
{{-- Prioridad --}}
|
||||
<td>
|
||||
@php
|
||||
$pClass = match($issue->priority) {
|
||||
'critical' => 'badge-purple',
|
||||
'high' => 'badge-error',
|
||||
'medium' => 'badge-warning',
|
||||
'low' => 'badge-ghost',
|
||||
default => 'badge-ghost',
|
||||
};
|
||||
$pLabel = match($issue->priority) {
|
||||
'critical' => 'Crítico',
|
||||
'high' => 'Alto',
|
||||
'medium' => 'Medio',
|
||||
'low' => 'Bajo',
|
||||
default => ucfirst($issue->priority),
|
||||
};
|
||||
@endphp
|
||||
<span
|
||||
class="badge badge-sm font-semibold
|
||||
{{ $issue->priority === 'critical' ? 'text-white' : '' }}"
|
||||
style="background-color: {{ $issue->priority_color }}; color: {{ $issue->priority === 'critical' || $issue->priority === 'high' ? '#fff' : '#1f2937' }}; border-color: transparent;"
|
||||
>
|
||||
{{ $pLabel }}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{{-- Título + descripción breve --}}
|
||||
<td>
|
||||
<div class="font-medium text-sm leading-tight">{{ $issue->title }}</div>
|
||||
@if($issue->description)
|
||||
<div class="text-xs text-base-content/50 truncate max-w-xs">{{ Str::limit($issue->description, 60) }}</div>
|
||||
@endif
|
||||
@if($issue->reporter)
|
||||
<div class="text-xs text-base-content/40 mt-0.5">
|
||||
Reportado por {{ $issue->reporter->name }}
|
||||
</div>
|
||||
@endif
|
||||
</td>
|
||||
|
||||
{{-- Feature --}}
|
||||
<td class="hidden md:table-cell">
|
||||
@if($issue->feature)
|
||||
<span class="badge badge-outline badge-sm">{{ $issue->feature->name }}</span>
|
||||
@else
|
||||
<span class="text-base-content/30 text-xs">—</span>
|
||||
@endif
|
||||
</td>
|
||||
|
||||
{{-- Estado --}}
|
||||
<td>
|
||||
@php
|
||||
$sLabel = match($issue->status) {
|
||||
'open' => 'Abierto',
|
||||
'in_review' => 'En revisión',
|
||||
'resolved' => 'Resuelto',
|
||||
'closed' => 'Cerrado',
|
||||
default => ucfirst($issue->status),
|
||||
};
|
||||
@endphp
|
||||
<span
|
||||
class="badge badge-sm"
|
||||
style="background-color: {{ $issue->status_color }}; color: #fff; border-color: transparent;"
|
||||
>
|
||||
{{ $sLabel }}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{{-- Asignado a --}}
|
||||
<td class="hidden lg:table-cell">
|
||||
@if($issue->assignee)
|
||||
<div class="flex items-center gap-1.5">
|
||||
<span class="w-6 h-6 rounded-full bg-primary text-primary-content flex items-center justify-center text-xs font-bold flex-shrink-0">
|
||||
{{ strtoupper(substr($issue->assignee->name, 0, 1)) }}
|
||||
</span>
|
||||
<span class="text-sm truncate">{{ $issue->assignee->name }}</span>
|
||||
</div>
|
||||
@else
|
||||
<span class="text-base-content/30 text-xs">Sin asignar</span>
|
||||
@endif
|
||||
</td>
|
||||
|
||||
{{-- Fecha --}}
|
||||
<td class="hidden lg:table-cell text-xs text-base-content/50">
|
||||
{{ $issue->created_at->format('d/m/Y') }}
|
||||
@if($issue->resolved_at)
|
||||
<div class="text-success">Res. {{ $issue->resolved_at->format('d/m/Y') }}</div>
|
||||
@endif
|
||||
</td>
|
||||
|
||||
{{-- Acciones --}}
|
||||
<td class="text-right">
|
||||
<div class="flex items-center justify-end gap-1 flex-wrap">
|
||||
{{-- Editar --}}
|
||||
<button
|
||||
wire:click="openForm({{ $issue->id }})"
|
||||
class="btn btn-xs btn-ghost tooltip"
|
||||
data-tip="Editar"
|
||||
>
|
||||
<x-heroicon-o-pencil class="w-3.5 h-3.5" />
|
||||
</button>
|
||||
|
||||
{{-- Resolver --}}
|
||||
@if(in_array($issue->status, ['open', 'in_review']))
|
||||
<button
|
||||
wire:click="resolve({{ $issue->id }})"
|
||||
wire:loading.attr="disabled"
|
||||
wire:target="resolve({{ $issue->id }})"
|
||||
class="btn btn-xs btn-success tooltip"
|
||||
data-tip="Marcar como resuelto"
|
||||
>
|
||||
<x-heroicon-o-check class="w-3.5 h-3.5" />
|
||||
</button>
|
||||
@endif
|
||||
|
||||
{{-- Cerrar --}}
|
||||
@if($issue->status !== 'closed')
|
||||
<button
|
||||
wire:click="close({{ $issue->id }})"
|
||||
wire:loading.attr="disabled"
|
||||
wire:target="close({{ $issue->id }})"
|
||||
class="btn btn-xs btn-neutral tooltip"
|
||||
data-tip="Cerrar issue"
|
||||
>
|
||||
<x-heroicon-o-x-mark class="w-3.5 h-3.5" />
|
||||
</button>
|
||||
@endif
|
||||
|
||||
{{-- Eliminar --}}
|
||||
<button
|
||||
wire:click="delete({{ $issue->id }})"
|
||||
wire:loading.attr="disabled"
|
||||
wire:target="delete({{ $issue->id }})"
|
||||
wire:confirm="¿Eliminar este issue? Esta acción no se puede deshacer."
|
||||
class="btn btn-xs btn-error btn-outline tooltip"
|
||||
data-tip="Eliminar"
|
||||
>
|
||||
<x-heroicon-o-trash class="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{-- ================================================================
|
||||
MODAL FORM (create / edit)
|
||||
================================================================ --}}
|
||||
@if($showForm)
|
||||
{{-- Overlay --}}
|
||||
<div
|
||||
class="fixed inset-0 z-40 bg-black/50"
|
||||
wire:click="closeForm()"
|
||||
></div>
|
||||
|
||||
{{-- Modal panel --}}
|
||||
<div
|
||||
class="fixed inset-0 z-50 flex items-center justify-center p-4"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
>
|
||||
<div class="bg-base-100 rounded-box shadow-2xl w-full max-w-2xl max-h-[90vh] overflow-y-auto">
|
||||
|
||||
{{-- Modal header --}}
|
||||
<div class="flex items-center justify-between p-5 border-b border-base-300">
|
||||
<h3 class="text-lg font-bold">
|
||||
{{ $editingIssue ? 'Editar Issue' : 'Nuevo Issue' }}
|
||||
</h3>
|
||||
<button wire:click="closeForm()" class="btn btn-sm btn-ghost btn-circle">
|
||||
<x-heroicon-o-x-mark class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{{-- Modal body --}}
|
||||
<form wire:submit.prevent="save" class="p-5 space-y-4">
|
||||
|
||||
{{-- Título --}}
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Título <span class="text-error">*</span></span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
wire:model="title"
|
||||
class="input input-bordered w-full @error('title') input-error @enderror"
|
||||
placeholder="Describe brevemente el problema..."
|
||||
autofocus
|
||||
/>
|
||||
@error('title')
|
||||
<label class="label">
|
||||
<span class="label-text-alt text-error">{{ $message }}</span>
|
||||
</label>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
{{-- Descripción --}}
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Descripción</span>
|
||||
</label>
|
||||
<textarea
|
||||
wire:model="description"
|
||||
class="textarea textarea-bordered w-full h-24 resize-y @error('description') textarea-error @enderror"
|
||||
placeholder="Detalla el problema, contexto, pasos para reproducirlo..."
|
||||
></textarea>
|
||||
@error('description')
|
||||
<label class="label">
|
||||
<span class="label-text-alt text-error">{{ $message }}</span>
|
||||
</label>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
{{-- Prioridad + Estado --}}
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Prioridad <span class="text-error">*</span></span>
|
||||
</label>
|
||||
<select
|
||||
wire:model="priority"
|
||||
class="select select-bordered w-full @error('priority') select-error @enderror"
|
||||
>
|
||||
<option value="low">Baja</option>
|
||||
<option value="medium">Media</option>
|
||||
<option value="high">Alta</option>
|
||||
<option value="critical">Crítica</option>
|
||||
</select>
|
||||
@error('priority')
|
||||
<label class="label">
|
||||
<span class="label-text-alt text-error">{{ $message }}</span>
|
||||
</label>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Estado <span class="text-error">*</span></span>
|
||||
</label>
|
||||
<select
|
||||
wire:model.live="status"
|
||||
class="select select-bordered w-full @error('status') select-error @enderror"
|
||||
>
|
||||
<option value="open">Abierto</option>
|
||||
<option value="in_review">En revisión</option>
|
||||
<option value="resolved">Resuelto</option>
|
||||
<option value="closed">Cerrado</option>
|
||||
</select>
|
||||
@error('status')
|
||||
<label class="label">
|
||||
<span class="label-text-alt text-error">{{ $message }}</span>
|
||||
</label>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Asignado a --}}
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Asignado a</span>
|
||||
</label>
|
||||
<select
|
||||
wire:model="assignedTo"
|
||||
class="select select-bordered w-full @error('assignedTo') select-error @enderror"
|
||||
>
|
||||
<option value="">Sin asignar</option>
|
||||
@foreach($projectUsers as $user)
|
||||
<option value="{{ $user->id }}">{{ $user->name }} – {{ $user->email }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('assignedTo')
|
||||
<label class="label">
|
||||
<span class="label-text-alt text-error">{{ $message }}</span>
|
||||
</label>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
{{-- Notas de resolución (visible when status = resolved or closed) --}}
|
||||
@if(in_array($status, ['resolved', 'closed']))
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Notas de resolución</span>
|
||||
<span class="label-text-alt text-base-content/50">Opcional</span>
|
||||
</label>
|
||||
<textarea
|
||||
wire:model="resolutionNotes"
|
||||
class="textarea textarea-bordered w-full h-20 resize-y @error('resolutionNotes') textarea-error @enderror"
|
||||
placeholder="Describe cómo se resolvió el problema..."
|
||||
></textarea>
|
||||
@error('resolutionNotes')
|
||||
<label class="label">
|
||||
<span class="label-text-alt text-error">{{ $message }}</span>
|
||||
</label>
|
||||
@enderror
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{-- Modal footer --}}
|
||||
<div class="flex items-center justify-end gap-3 pt-2 border-t border-base-300">
|
||||
<button
|
||||
type="button"
|
||||
wire:click="closeForm()"
|
||||
class="btn btn-ghost"
|
||||
>
|
||||
Cancelar
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
wire:loading.attr="disabled"
|
||||
wire:target="save"
|
||||
class="btn btn-primary gap-2"
|
||||
>
|
||||
<span wire:loading.remove wire:target="save">
|
||||
<x-heroicon-o-check class="w-4 h-4" />
|
||||
</span>
|
||||
<span wire:loading wire:target="save" class="loading loading-spinner loading-sm"></span>
|
||||
{{ $editingIssue ? 'Actualizar Issue' : 'Crear Issue' }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
<livewire:issue-table :project-id="$project->id" :key="'issue-table-'.$project->id" />
|
||||
</div>
|
||||
|
||||
@@ -26,7 +26,7 @@ new class extends Component
|
||||
<!-- Logo -->
|
||||
<div class="shrink-0 flex items-center">
|
||||
<a href="{{ route('dashboard') }}" wire:navigate>
|
||||
<x-application-logo class="block h-9 w-auto fill-current text-gray-800" />
|
||||
<x-application-logo class="block h-10 w-auto object-contain" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -119,6 +119,9 @@ 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/{issue}', \App\Livewire\IssueDetail::class)->name('projects.issues.show');
|
||||
Route::get('/projects/{project}/issues/{issue}/edit', \App\Livewire\IssueForm::class)->name('projects.issues.edit');
|
||||
|
||||
// Dashboard por proyecto
|
||||
Route::get('/projects/{project}/dashboard', \App\Livewire\ProjectDashboard::class)->name('projects.dashboard');
|
||||
|
||||
@@ -6,6 +6,8 @@ use App\Models\Feature;
|
||||
use App\Models\Inspection;
|
||||
use App\Models\InspectionTemplate;
|
||||
use App\Models\Issue;
|
||||
use App\Models\IssueComment;
|
||||
use App\Models\IssueTask;
|
||||
use App\Models\Layer;
|
||||
use App\Models\Phase;
|
||||
use App\Models\Project;
|
||||
@@ -28,7 +30,7 @@ class MobileApiTest extends TestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
foreach (['update progress', 'manage all', 'create inspections', 'create issues', 'edit issues', 'upload media'] as $p) {
|
||||
foreach (['update progress', 'manage all', 'create inspections', 'view issues', 'create issues', 'edit issues', 'upload media'] as $p) {
|
||||
Permission::findOrCreate($p);
|
||||
}
|
||||
}
|
||||
@@ -407,6 +409,126 @@ class MobileApiTest extends TestCase
|
||||
$this->assertEquals(1, \App\Models\Media::where('uuid', $uuid)->count());
|
||||
}
|
||||
|
||||
// ── Issue tasks / comments (enriquecimiento incidencias) ─────────────────────
|
||||
|
||||
private function makeIssue(Project $project, ?User $reporter = null): Issue
|
||||
{
|
||||
return Issue::create([
|
||||
'project_id' => $project->id,
|
||||
'title' => 'Incidencia test',
|
||||
'status' => 'open',
|
||||
'priority' => 'medium',
|
||||
'reported_by' => $reporter?->id ?? $project->created_by,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_sync_creates_and_updates_an_issue_task(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$user->givePermissionTo('edit issues');
|
||||
$project = $this->makeProject($user);
|
||||
$issue = $this->makeIssue($project, $user);
|
||||
|
||||
Sanctum::actingAs($user, ['mobile-sync']);
|
||||
|
||||
// create task
|
||||
$uuid = (string) Str::uuid();
|
||||
$this->postJson('/api/v1/sync', ['operations' => [[
|
||||
'entity' => 'issue_task', 'op' => 'create', 'uuid' => $uuid,
|
||||
'data' => ['issue_id' => $issue->id, 'title' => 'Sanear zona'],
|
||||
]]])->assertOk()->assertJsonPath('results.0.status', 'applied');
|
||||
|
||||
$task = IssueTask::where('uuid', $uuid)->firstOrFail();
|
||||
$this->assertFalse($task->is_done);
|
||||
|
||||
// mark done via update
|
||||
$this->postJson('/api/v1/sync', ['operations' => [[
|
||||
'entity' => 'issue_task', 'op' => 'update', 'uuid' => (string) Str::uuid(),
|
||||
'data' => ['id' => $task->id, 'is_done' => true],
|
||||
]]])->assertOk()->assertJsonPath('results.0.status', 'applied');
|
||||
|
||||
$task->refresh();
|
||||
$this->assertTrue($task->is_done);
|
||||
$this->assertEquals($user->id, $task->done_by);
|
||||
$this->assertNotNull($task->done_at);
|
||||
}
|
||||
|
||||
public function test_sync_issue_task_is_forbidden_without_edit_permission(): void
|
||||
{
|
||||
$user = User::factory()->create(); // member but no 'edit issues'
|
||||
$project = $this->makeProject($user);
|
||||
$issue = $this->makeIssue($project, $user);
|
||||
|
||||
Sanctum::actingAs($user, ['mobile-sync']);
|
||||
$this->postJson('/api/v1/sync', ['operations' => [[
|
||||
'entity' => 'issue_task', 'op' => 'create', 'uuid' => (string) Str::uuid(),
|
||||
'data' => ['issue_id' => $issue->id, 'title' => 'X'],
|
||||
]]])->assertOk()->assertJsonPath('results.0.status', 'error');
|
||||
|
||||
$this->assertDatabaseCount('issue_tasks', 0);
|
||||
}
|
||||
|
||||
public function test_sync_creates_an_issue_comment(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$user->givePermissionTo('view issues');
|
||||
$project = $this->makeProject($user);
|
||||
$issue = $this->makeIssue($project, $user);
|
||||
|
||||
Sanctum::actingAs($user, ['mobile-sync']);
|
||||
$uuid = (string) Str::uuid();
|
||||
$this->postJson('/api/v1/sync', ['operations' => [[
|
||||
'entity' => 'issue_comment', 'op' => 'create', 'uuid' => $uuid,
|
||||
'data' => ['issue_id' => $issue->id, 'body' => 'Revisado en obra'],
|
||||
]]])->assertOk()->assertJsonPath('results.0.status', 'applied');
|
||||
|
||||
$this->assertDatabaseHas('issue_comments', [
|
||||
'uuid' => $uuid, 'issue_id' => $issue->id, 'user_id' => $user->id, 'body' => 'Revisado en obra',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_media_uploads_to_issue_task_and_comment(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
$user = User::factory()->create();
|
||||
$user->givePermissionTo('upload media');
|
||||
$project = $this->makeProject($user);
|
||||
$issue = $this->makeIssue($project, $user);
|
||||
$task = $issue->tasks()->create(['title' => 'T', 'uuid' => (string) Str::uuid()]);
|
||||
$comment = $issue->comments()->create(['user_id' => $user->id, 'body' => 'c', 'uuid' => (string) Str::uuid()]);
|
||||
|
||||
Sanctum::actingAs($user, ['mobile-sync']);
|
||||
|
||||
$this->post('/api/v1/media', [
|
||||
'uuid' => (string) Str::uuid(), 'parent_entity' => 'issue_task', 'parent_id' => $task->id,
|
||||
'file' => UploadedFile::fake()->image('a.jpg'),
|
||||
])->assertOk()->assertJsonPath('status', 'applied');
|
||||
|
||||
$this->post('/api/v1/media', [
|
||||
'uuid' => (string) Str::uuid(), 'parent_entity' => 'issue_comment', 'parent_id' => $comment->id,
|
||||
'file' => UploadedFile::fake()->image('b.jpg'),
|
||||
])->assertOk()->assertJsonPath('status', 'applied');
|
||||
|
||||
$this->assertDatabaseHas('media', ['mediable_type' => IssueTask::class, 'mediable_id' => $task->id]);
|
||||
$this->assertDatabaseHas('media', ['mediable_type' => IssueComment::class, 'mediable_id' => $comment->id]);
|
||||
}
|
||||
|
||||
public function test_bundle_includes_issue_tasks_and_comments(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = $this->makeProject($user);
|
||||
$issue = $this->makeIssue($project, $user);
|
||||
$task = $issue->tasks()->create(['title' => 'Tarea bundle', 'uuid' => (string) Str::uuid()]);
|
||||
$comment = $issue->comments()->create(['user_id' => $user->id, 'body' => 'Comentario bundle', 'uuid' => (string) Str::uuid()]);
|
||||
|
||||
Sanctum::actingAs($user, ['mobile-sync']);
|
||||
$res = $this->getJson("/api/v1/projects/{$project->id}/bundle")->assertOk();
|
||||
|
||||
$this->assertTrue(collect($res->json('issue_tasks'))->pluck('id')->contains($task->id));
|
||||
$this->assertTrue(collect($res->json('issue_comments'))->pluck('id')->contains($comment->id));
|
||||
}
|
||||
|
||||
public function test_sync_operation_is_idempotent_via_sync_logs(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Livewire\IssueManager;
|
||||
use App\Livewire\IssueTable;
|
||||
use App\Models\Issue;
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IssuesTablePageTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function memberWithIssue(): array
|
||||
{
|
||||
foreach (['view issues', 'create issues', 'edit issues', 'delete issues'] as $p) {
|
||||
Permission::findOrCreate($p);
|
||||
}
|
||||
|
||||
$user = User::factory()->create();
|
||||
$user->givePermissionTo(['view issues', 'edit issues', 'delete issues']);
|
||||
|
||||
$project = Project::create([
|
||||
'reference' => 'TBL-1',
|
||||
'name' => 'Proyecto Tabla',
|
||||
'address' => 'Calle Falsa 123',
|
||||
'lat' => 40.0,
|
||||
'lng' => -3.0,
|
||||
'start_date' => now()->toDateString(),
|
||||
'end_date_estimated' => now()->addMonths(6)->toDateString(),
|
||||
'status' => 'in_progress',
|
||||
'created_by' => $user->id,
|
||||
]);
|
||||
$project->users()->attach($user->id, ['role_in_project' => 'supervisor']);
|
||||
|
||||
$issue = Issue::create([
|
||||
'project_id' => $project->id,
|
||||
'title' => 'Grieta en muro',
|
||||
'status' => 'open',
|
||||
'priority' => 'high',
|
||||
'reported_by' => $user->id,
|
||||
]);
|
||||
|
||||
return [$user, $project, $issue];
|
||||
}
|
||||
|
||||
public function test_issue_manager_renders_stats_and_table(): void
|
||||
{
|
||||
[$user, $project, $issue] = $this->memberWithIssue();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(IssueManager::class, ['project' => $project])
|
||||
->assertOk()
|
||||
->assertSee('Incidencias del proyecto')
|
||||
->assertSeeLivewire(IssueTable::class);
|
||||
}
|
||||
|
||||
public function test_issue_table_lists_and_resolves_an_issue(): void
|
||||
{
|
||||
[$user, $project, $issue] = $this->memberWithIssue();
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(IssueTable::class, ['projectId' => $project->id])
|
||||
->assertOk()
|
||||
->assertSee('Grieta en muro')
|
||||
->call('resolve', $issue->id);
|
||||
|
||||
$this->assertEquals('resolved', $issue->fresh()->status);
|
||||
}
|
||||
|
||||
public function test_issue_table_forbidden_for_non_member(): void
|
||||
{
|
||||
[, $project] = $this->memberWithIssue();
|
||||
|
||||
$outsider = User::factory()->create();
|
||||
$outsider->givePermissionTo('view issues');
|
||||
|
||||
Livewire::actingAs($outsider)
|
||||
->test(IssueTable::class, ['projectId' => $project->id])
|
||||
->assertForbidden();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user