chore: cleanup dead code + format with Pint

- Remove unused FeaturesController (empty stubs, no routes)
- Remove ConvertSpatialFile CLI command (unused; service used in LayerManager)
- Remove MigrateGeojsonToFeatures CLI command (one-shot migration, not referenced)
- Remove .claude/worktrees/ (11 old agent worktrees from June)
- Apply Laravel Pint formatting across 219 files (style only, no functional changes)

Tests: 101 passing (319 assertions)
API routes: unchanged (8 routes intact)
This commit is contained in:
Javier Braña
2026-08-28 13:04:28 +02:00
parent 2dccd59385
commit 90630379fb
139 changed files with 2888 additions and 2510 deletions
@@ -18,29 +18,35 @@ class GlobalTemplateManager extends Component
public $templates;
public $editingTemplate = null;
public $showForm = false;
public $form = [
'name' => '',
'name' => '',
'description' => '',
'fields' => [],
'fields' => [],
];
// ── Importar desde CSV/Excel ───────────────────────────────────────────
public $showImportFileModal = false;
public $importFile = null;
public $importPreviewFields = [];
public $importTemplateName = '';
public $importError = '';
public $showImportFileModal = false;
public $importFile = null;
public $importPreviewFields = [];
public $importTemplateName = '';
public $importError = '';
public $fieldTypes = [
'text' => 'Texto corto',
'textarea' => 'Texto largo',
'integer' => 'Número entero',
'decimal' => 'Número decimal',
'text' => 'Texto corto',
'textarea' => 'Texto largo',
'integer' => 'Número entero',
'decimal' => 'Número decimal',
'percentage' => 'Porcentaje (0-100)',
'boolean' => 'Sí/No (checkbox)',
'date' => 'Fecha',
'select' => 'Lista desplegable',
'boolean' => 'Sí/No (checkbox)',
'date' => 'Fecha',
'select' => 'Lista desplegable',
];
public function mount()
@@ -66,9 +72,9 @@ class GlobalTemplateManager extends Component
{
$template = InspectionTemplate::findOrFail($id);
$this->form = [
'name' => $template->name,
'name' => $template->name,
'description' => $template->description ?? '',
'fields' => $template->fields ?? [],
'fields' => $template->fields ?? [],
];
$this->editingTemplate = $id;
$this->showForm = true;
@@ -83,9 +89,9 @@ class GlobalTemplateManager extends Component
public function resetForm()
{
$this->form = [
'name' => '',
'name' => '',
'description' => '',
'fields' => [],
'fields' => [],
];
$this->editingTemplate = null;
}
@@ -93,17 +99,17 @@ class GlobalTemplateManager extends Component
public function addField()
{
$this->form['fields'][] = [
'group' => '',
'name' => '',
'label' => '',
'group' => '',
'name' => '',
'label' => '',
'question' => '',
'type' => 'text',
'options' => '',
'type' => 'text',
'options' => '',
'required' => false,
'min' => null,
'max' => null,
'step' => null,
'help' => '',
'min' => null,
'max' => null,
'step' => null,
'help' => '',
];
}
@@ -116,15 +122,15 @@ class GlobalTemplateManager extends Component
public function saveTemplate()
{
$this->validate([
'form.name' => 'required|string|max:255',
'form.name' => 'required|string|max:255',
'form.fields' => 'array',
]);
$data = [
'name' => $this->form['name'],
'name' => $this->form['name'],
'description' => $this->form['description'],
'project_id' => null,
'fields' => array_values($this->form['fields']),
'project_id' => null,
'fields' => array_values($this->form['fields']),
];
if ($this->editingTemplate) {
@@ -153,10 +159,10 @@ class GlobalTemplateManager extends Component
public function openImportFileModal()
{
$this->importFile = null;
$this->importFile = null;
$this->importPreviewFields = [];
$this->importTemplateName = '';
$this->importError = '';
$this->importTemplateName = '';
$this->importError = '';
$this->showImportFileModal = true;
}
@@ -164,31 +170,34 @@ class GlobalTemplateManager extends Component
{
$headers = ['Content-Type' => 'text/csv'];
$csv = "\xEF\xBB\xBF" // BOM UTF-8 (para que Excel respete los acentos)
. "group,name,label,question,type,required,options,min,max,step,help\n"
. "Dimensiones,altura,Altura (m),¿Cumple la altura de proyecto?,decimal,1,,0,100,0.1,Medir con flexómetro\n"
. "Dimensiones,material,Material,,select,1,Hormigón|Acero|Madera,,,,\n"
. "Acabados,ok,¿Acabado correcto?,,boolean,1,,,,,\n";
return response()->streamDownload(fn () => print($csv), 'plantilla_ejemplo.csv', $headers);
."group,name,label,question,type,required,options,min,max,step,help\n"
."Dimensiones,altura,Altura (m),¿Cumple la altura de proyecto?,decimal,1,,0,100,0.1,Medir con flexómetro\n"
."Dimensiones,material,Material,,select,1,Hormigón|Acero|Madera,,,,\n"
."Acabados,ok,¿Acabado correcto?,,boolean,1,,,,,\n";
return response()->streamDownload(fn () => print ($csv), 'plantilla_ejemplo.csv', $headers);
}
public function parseImportFile()
{
$this->importError = '';
$this->validate([
'importFile' => 'required|file|mimes:csv,txt,xlsx,xls|max:5120',
'importFile' => 'required|file|mimes:csv,txt,xlsx,xls|max:5120',
'importTemplateName' => 'required|string|max:255',
]);
try {
$rows = $this->readFileRows();
} catch (\Throwable $e) {
$this->importError = 'No se pudo leer el archivo: ' . $e->getMessage();
$this->importError = 'No se pudo leer el archivo: '.$e->getMessage();
return;
}
$fields = $this->parseRows($rows);
if (empty($fields)) {
$this->importError = 'No se encontraron filas válidas.';
return;
}
$this->importPreviewFields = $fields;
@@ -196,19 +205,21 @@ class GlobalTemplateManager extends Component
public function confirmImportFile()
{
if (empty($this->importPreviewFields) || empty($this->importTemplateName)) return;
if (empty($this->importPreviewFields) || empty($this->importTemplateName)) {
return;
}
InspectionTemplate::create([
'name' => $this->importTemplateName,
'name' => $this->importTemplateName,
'description' => 'Importado desde archivo',
'project_id' => null,
'fields' => array_values($this->importPreviewFields),
'project_id' => null,
'fields' => array_values($this->importPreviewFields),
]);
$this->showImportFileModal = false;
$this->importPreviewFields = [];
$this->importTemplateName = '';
$this->importFile = null;
$this->importTemplateName = '';
$this->importFile = null;
$this->loadTemplates();
$this->dispatch('templates-changed');
$this->dispatch('notify', 'Plantilla importada');
@@ -216,7 +227,7 @@ class GlobalTemplateManager extends Component
private function readFileRows(): array
{
$ext = strtolower($this->importFile->getClientOriginalExtension());
$ext = strtolower($this->importFile->getClientOriginalExtension());
$path = $this->importFile->getRealPath();
// Fila no vacía = tiene al menos una celda con contenido (no filtramos por
@@ -226,21 +237,27 @@ class GlobalTemplateManager extends Component
if ($ext === 'xlsx' || $ext === 'xls') {
$spreadsheet = IOFactory::load($path);
$sheet = $spreadsheet->getActiveSheet();
$rows = $sheet->toArray(null, true, true, false);
$sheet = $spreadsheet->getActiveSheet();
$rows = $sheet->toArray(null, true, true, false);
array_shift($rows);
return array_values(array_filter($rows, $notEmpty));
}
$rows = [];
$rows = [];
$handle = fopen($path, 'r');
$bom = fread($handle, 3);
if ($bom !== "\xEF\xBB\xBF") rewind($handle);
if ($bom !== "\xEF\xBB\xBF") {
rewind($handle);
}
fgetcsv($handle);
while (($row = fgetcsv($handle)) !== false) {
if ($notEmpty($row)) $rows[] = $row;
if ($notEmpty($row)) {
$rows[] = $row;
}
}
fclose($handle);
return $rows;
}
@@ -250,24 +267,27 @@ class GlobalTemplateManager extends Component
// group, name, label, question, type, required, options, min, max, step, help
$fields = [];
foreach ($rows as $row) {
$row = array_values((array) $row);
$row = array_values((array) $row);
$rawName = trim($row[1] ?? '');
if ($rawName === '') continue;
if ($rawName === '') {
continue;
}
$fields[] = [
'group' => trim($row[0] ?? ''),
'name' => $this->slugify($rawName),
'label' => trim($row[2] ?? '') ?: $rawName,
'group' => trim($row[0] ?? ''),
'name' => $this->slugify($rawName),
'label' => trim($row[2] ?? '') ?: $rawName,
'question' => trim($row[3] ?? ''),
'type' => $this->normalizeType($row[4] ?? 'text'),
'type' => $this->normalizeType($row[4] ?? 'text'),
'required' => in_array(strtolower(trim($row[5] ?? '0')), ['1', 'si', 'sí', 'yes', 'true']),
'options' => trim($row[6] ?? ''),
'min' => ($row[7] ?? '') !== '' ? $row[7] : null,
'max' => ($row[8] ?? '') !== '' ? $row[8] : null,
'step' => ($row[9] ?? '') !== '' ? $row[9] : null,
'help' => trim($row[10] ?? ''),
'options' => trim($row[6] ?? ''),
'min' => ($row[7] ?? '') !== '' ? $row[7] : null,
'max' => ($row[8] ?? '') !== '' ? $row[8] : null,
'step' => ($row[9] ?? '') !== '' ? $row[9] : null,
'help' => trim($row[10] ?? ''),
];
}
return $fields;
}
@@ -276,6 +296,7 @@ class GlobalTemplateManager extends Component
$str = mb_strtolower(trim($str));
$str = preg_replace('/\s+/', '_', $str);
$str = preg_replace('/[^a-z0-9_]/i', '', $str);
return trim($str, '_') ?: 'campo';
}
@@ -291,6 +312,7 @@ class GlobalTemplateManager extends Component
'date' => 'date', 'fecha' => 'date',
'select' => 'select', 'lista' => 'select', 'dropdown' => 'select', 'opciones' => 'select',
];
return $map[strtolower(trim($type))] ?? 'text';
}