feat(issues): tipo/categoría de incidencia (defecto/seguridad/calidad/documentación/otro)

- Issue::TYPES + typeLabels() (ES) + accessors type_label/type_color; columna type
  (string, default 'other') + fillable.
- IssueForm: select "Tipo de incidencia" con validación/carga/guardado.
- IssueTable: columna Tipo (badge) + SelectFilter por tipo.
- IssueDetail: badge de tipo en la cabecera.
- Sync offline: issue.create/update aceptan type; bundle (mapIssue) lo incluye.

Tests: IssuesEnhancementsTest (create muestra el campo vía HTTP, edición persiste) +
MobileApiTest (create con type). Suite 61 passing (solo 2 pre-existentes sqlite).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-18 13:30:54 +02:00
parent 19e1f57983
commit 3d0f4d5cad
10 changed files with 114 additions and 2 deletions
@@ -175,6 +175,7 @@ class ProjectApiController extends Controller
return [
'id' => $i->id, 'feature_id' => $i->feature_id, 'title' => $i->title,
'description' => $i->description, 'status' => $i->status, 'priority' => $i->priority,
'type' => $i->type,
'reported_by' => $i->reported_by, 'assigned_to' => $i->assigned_to,
'resolved_at' => $i->resolved_at?->toIso8601String(), 'updated_at' => $i->updated_at?->toIso8601String(),
];
@@ -189,6 +189,7 @@ class SyncController extends Controller
'description' => ['nullable', 'string'],
'priority' => ['nullable', 'in:' . implode(',', Issue::PRIORITIES)],
'status' => ['nullable', 'in:' . implode(',', Issue::STATUSES)],
'type' => ['nullable', 'in:' . implode(',', Issue::TYPES)],
]);
if ($v->fails()) {
return $this->error($uuid, 'validation: ' . $v->errors()->first());
@@ -208,6 +209,7 @@ class SyncController extends Controller
'description' => $d['description'] ?? null,
'priority' => $d['priority'] ?? 'medium',
'status' => $d['status'] ?? 'open',
'type' => $d['type'] ?? 'other',
'reported_by' => $user->id,
'client_updated_at' => $op['client_updated_at'] ?? null,
]);
@@ -223,6 +225,7 @@ class SyncController extends Controller
'description' => ['nullable', 'string'],
'priority' => ['nullable', 'in:' . implode(',', Issue::PRIORITIES)],
'status' => ['nullable', 'in:' . implode(',', Issue::STATUSES)],
'type' => ['nullable', 'in:' . implode(',', Issue::TYPES)],
'assigned_to' => ['nullable', 'integer', 'exists:users,id'],
'resolution_notes' => ['nullable', 'string'],
]);
+4
View File
@@ -23,6 +23,7 @@ class IssueForm extends Component
public $description = '';
public $status = 'open';
public $priority = 'medium';
public $type = 'defect';
public $assignedTo = '';
public $resolutionNotes = '';
@@ -48,6 +49,7 @@ class IssueForm extends Component
$this->description = $issue->description ?? '';
$this->status = $issue->status;
$this->priority = $issue->priority;
$this->type = $issue->type ?? 'defect';
$this->assignedTo = $issue->assigned_to ?? '';
$this->resolutionNotes = $issue->resolution_notes ?? '';
$this->featureId = $issue->feature_id;
@@ -77,6 +79,7 @@ class IssueForm extends Component
'description' => 'nullable|string',
'status' => 'required|in:' . implode(',', Issue::STATUSES),
'priority' => 'required|in:' . implode(',', Issue::PRIORITIES),
'type' => 'required|in:' . implode(',', Issue::TYPES),
'assignedTo' => 'nullable|exists:users,id',
'resolutionNotes' => 'nullable|string',
];
@@ -92,6 +95,7 @@ class IssueForm extends Component
'description' => $this->description,
'status' => $this->status,
'priority' => $this->priority,
'type' => $this->type,
'feature_id' => $this->featureId,
'inspection_id' => $this->inspectionId,
'assigned_to' => $this->assignedTo ?: null,
+10
View File
@@ -91,6 +91,12 @@ class IssueTable extends DataTableComponent
})
->html(),
Column::make('Tipo', 'type')
->sortable()
->format(fn ($value, $row) =>
'<span class="badge badge-sm" style="background-color:'.$row->type_color.';color:#fff;border-color:transparent;">'.e($row->type_label).'</span>')
->html(),
Column::make('Feature')
->label(fn ($row) => $row->feature
? '<span class="badge badge-outline badge-sm">'.e($row->feature->name).'</span>'
@@ -185,6 +191,10 @@ class IssueTable extends DataTableComponent
'low' => 'Baja',
])
->filter(fn (Builder $query, string $value) => $query->where('issues.priority', $value)),
SelectFilter::make('Tipo', 'type')
->options(['' => 'Tipo: todos'] + \App\Models\Issue::typeLabels())
->filter(fn (Builder $query, string $value) => $query->where('issues.type', $value)),
];
}
+30 -1
View File
@@ -12,10 +12,11 @@ class Issue extends Model
const STATUSES = ['open', 'in_review', 'resolved', 'closed'];
const PRIORITIES = ['low', 'medium', 'high', 'critical'];
const TYPES = ['defect', 'safety', 'quality', 'documentation', 'other'];
protected $fillable = [
'project_id', 'feature_id', 'inspection_id',
'title', 'description', 'status', 'priority',
'title', 'description', 'status', 'priority', 'type',
'reported_by', 'assigned_to', 'resolved_at', 'resolution_notes',
'uuid', 'client_updated_at',
];
@@ -71,4 +72,32 @@ class Issue extends Model
default => '#6b7280',
};
}
/** Human label (Spanish) for each issue type. */
public static function typeLabels(): array
{
return [
'defect' => 'Defecto',
'safety' => 'Seguridad',
'quality' => 'Calidad',
'documentation' => 'Documentación',
'other' => 'Otro',
];
}
public function getTypeLabelAttribute(): string
{
return self::typeLabels()[$this->type] ?? ucfirst((string) $this->type);
}
public function getTypeColorAttribute(): string
{
return match($this->type) {
'defect' => '#ef4444',
'safety' => '#f97316',
'quality' => '#0ea5e9',
'documentation' => '#8b5cf6',
default => '#6b7280',
};
}
}