From: Vincent Vanwaelscappel Date: Mon, 9 Jan 2023 17:15:49 +0000 (+0100) Subject: wait #5672 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=598ed501805c454a1beaa4de9e9486de7c8aa8fd;p=fluidbook-toolbox.git wait #5672 --- diff --git a/app/Http/Controllers/Admin/Operations/Tools/Excel2JSON.php b/app/Http/Controllers/Admin/Operations/Tools/Excel2JSON.php index 0079eec50..59fbbf795 100644 --- a/app/Http/Controllers/Admin/Operations/Tools/Excel2JSON.php +++ b/app/Http/Controllers/Admin/Operations/Tools/Excel2JSON.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin\Operations\Tools; use Cubist\Backpack\Magic\Fields\SelectFromArray; use Cubist\Backpack\Magic\Fields\StandardFile; +use Cubist\Backpack\Magic\Fields\Text; use Cubist\Backpack\Magic\Form; use Cubist\Excel\ExcelToArray; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -16,7 +17,7 @@ trait Excel2JSON { return [ 'excelToArray' => ['label' => __('Conforme à la source'), 'function' => 'excelToArrayRaw'], - 'excelToArrayFirstSheet' => ['label' => __('Conforme à la source') . ' (' . __('Première feuille uniquement') . ')', 'function' => 'excelToArrayFirstSheet'], + 'excelToArrayFirstSheet' => ['label' => __('Conforme à la source') . ' (' . __('Une feuille uniquement') . ')', 'function' => 'excelToArrayFirstSheet'], 'excelToArrayKeyVars' => ['label' => __('Liste nommée par le titre de colonne') . ' (' . __('Clés = valeur de la colonne A') . ')'], 'excelToArrayIndexKeyVars' => ['label' => __('Liste nommée par le titre de colonne') . ' (' . __('Clés = nombres séquentiels') . ')'], 'excelToArrayKeyVal' => ['label' => __('Couples clé (colonne A) / valeur (colonne B)')], @@ -39,6 +40,7 @@ trait Excel2JSON } $form->addField('dataorg', SelectFromArray::class, __('Type'), ['allows_null' => false, 'default' => 'excelToArray', 'options' => $options]); + $form->addField('sheet', Text::class, __('Feuille'), ['hint' => __('Laisser vide pour utiliser la première feuille'), 'when' => ['dataorg' => ['excelToArrayFirstSheet', 'excelToArrayIndexKeyVars', 'excelToArrayIndexKeyVars', 'excelToArrayKeyVal', 'excelToArrayKeyValMulti']]]); $form->addField('format', SelectFromArray::class, __('Format de sortie'), ['allows_null' => false, 'default' => 'json', 'options' => [ 'json' => 'JSON', @@ -46,6 +48,7 @@ trait Excel2JSON ] ] ); + $form->addField('varname', Text::class, __('Nom de la variable'), ['when' => ['format' => 'js'], 'default' => 'DATA']); return view('tools.form', ['form' => $form]); } @@ -64,13 +67,13 @@ trait Excel2JSON } $function = $dataOrgs[$dataorg]['function'] ?? $dataorg; - $res = ExcelToArray::$function($file->getPathname()); + $res = ExcelToArray::$function($file->getPathname(), request()->input('sheet', '')); if ($format === 'json') { return response()->json($res); } if ($format === 'js') { - return response('var DATA=' . json_encode($res) . ';')->header('Content-Type', 'text/plain'); + return response('var ' . request()->input('varname', 'DATA') . '=' . json_encode($res) . ';')->header('Content-Type', 'text/plain'); } } }