3f240e5277
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>
127 lines
4.3 KiB
PHP
127 lines
4.3 KiB
PHP
<?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');
|
|
}
|
|
}
|