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
|
||||
|
||||
Reference in New Issue
Block a user