feat(inspections): add photos support with edit + lightbox
- Validación robusta fotos (10MB, jpeg/png/webp, max 10) - Editar inspección existente: botón en historial, modal y tabla - Eliminación individual de fotos en edición (marcar + guardar) - Lightbox/carousel en modal ver + editar (Alpine.js) - Columna 'Fotos' en InspectionTable con thumbnails + contador - Permiso 'edit inspections' en seeders + checks en componente - Test actualizado: seed roles/permisos + attach template pivot - Fix: removed unsupported filterable() on secondaryHeaderFilter
This commit is contained in:
@@ -45,7 +45,7 @@ class InspectionTable extends DataTableComponent
|
||||
|
||||
return Inspection::query()
|
||||
->where('inspections.project_id', $this->projectId)
|
||||
->with(['feature', 'template', 'user']);
|
||||
->with(['feature', 'template', 'user', 'media']);
|
||||
}
|
||||
|
||||
public function columns(): array
|
||||
@@ -78,18 +78,48 @@ class InspectionTable extends DataTableComponent
|
||||
->secondaryHeaderFilter('usuario')
|
||||
->label(fn ($row) => e($row->user?->name ?? '—')),
|
||||
|
||||
Column::make('Fotos')
|
||||
->label(fn ($row) => $this->renderPhotosColumn($row))
|
||||
->html(),
|
||||
|
||||
Column::make('Acciones')
|
||||
->label(fn ($row) =>
|
||||
'<div class="flex justify-end">
|
||||
'<div class="flex justify-end gap-1">
|
||||
<button wire:click="$dispatch(\'map-view-inspection\', { id: ' . $row->id . ' })"
|
||||
class="btn btn-xs btn-ghost" title="Ver inspección">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/></svg>
|
||||
</button>
|
||||
@can("edit inspections")
|
||||
<button wire:click="$dispatch(\'edit-inspection\', { id: ' . $row->id . ' })"
|
||||
class="btn btn-xs btn-ghost" title="Editar inspección">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" 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>
|
||||
</button>
|
||||
@endcan
|
||||
</div>')
|
||||
->html(),
|
||||
];
|
||||
}
|
||||
|
||||
private function renderPhotosColumn($row): string
|
||||
{
|
||||
$images = $row->media->where('category', 'image')->values();
|
||||
$count = $images->count();
|
||||
|
||||
if ($count === 0) {
|
||||
return '<span class="text-base-content/30 text-xs">—</span>';
|
||||
}
|
||||
|
||||
$thumbnails = $images->take(3)->map(fn ($m) =>
|
||||
'<a href="' . $m->url . '" target="_blank" class="inline-block mr-1">
|
||||
<img src="' . $m->url . '" class="w-8 h-8 object-cover rounded border border-base-300" alt="' . e($m->name) . '" loading="lazy" />
|
||||
</a>'
|
||||
)->implode('');
|
||||
|
||||
$more = $count > 3 ? '<span class="text-xs text-base-content/50 ml-1">+' . ($count - 3) . '</span>' : '';
|
||||
|
||||
return '<div class="flex items-center">' . $thumbnails . $more . '</div>';
|
||||
}
|
||||
|
||||
public function filters(): array
|
||||
{
|
||||
$results = Inspection::where('project_id', $this->projectId)
|
||||
|
||||
Reference in New Issue
Block a user