Compare commits
3 Commits
#18172-bet
...
csv_import
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8052447de6 | ||
|
|
b4f9284d41 | ||
|
|
aac876eaa8 |
@@ -65,7 +65,7 @@ class ImportController extends Controller
|
||||
ini_set('auto_detect_line_endings', '1');
|
||||
}
|
||||
$reader = Reader::createFromFileObject($file->openFile('r')); //file pointer leak?
|
||||
|
||||
$reader->setDelimiter(request('delimiter', ','));
|
||||
try {
|
||||
$import->header_row = $reader->fetchOne(0);
|
||||
} catch (JsonEncodingException $e) {
|
||||
@@ -133,6 +133,7 @@ class ImportController extends Controller
|
||||
}
|
||||
|
||||
$import->filesize = filesize($path.'/'.$file_name);
|
||||
$import->delimiter = request('delimiter');
|
||||
|
||||
$import->save();
|
||||
$results[] = $import;
|
||||
|
||||
@@ -129,8 +129,10 @@ abstract class Importer
|
||||
// However, for testing we also support passing a string directly
|
||||
if (is_file($file)) {
|
||||
$this->csv = Reader::createFromPath($file);
|
||||
$this->csv->setDelimiter($this->delimiter);
|
||||
} else {
|
||||
$this->csv = Reader::createFromString($file);
|
||||
$this->csv->setDelimiter($this->delimiter);
|
||||
}
|
||||
$this->tempPassword = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 40);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ class Importer extends Component
|
||||
public $consumables_fields;
|
||||
public $components_fields;
|
||||
public $aliases_fields;
|
||||
public $delimiter;
|
||||
|
||||
protected $rules = [
|
||||
'files.*.file_path' => 'required|string',
|
||||
@@ -47,7 +48,8 @@ class Importer extends Component
|
||||
'files.*.filesize' => 'required|integer',
|
||||
'headerRow' => 'array',
|
||||
'typeOfImport' => 'string',
|
||||
'field_map' => 'array'
|
||||
'field_map' => 'array',
|
||||
'delimiter' => 'in:comma,semicolon,pipe',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Import extends Model
|
||||
@@ -11,4 +12,36 @@ class Import extends Model
|
||||
'first_row' => 'array',
|
||||
'field_map' => 'json',
|
||||
];
|
||||
|
||||
protected function delimiter(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
set: function ($value) {
|
||||
if ($value == 'semicolon') {
|
||||
return ';';
|
||||
}
|
||||
if ($value == 'pipe') {
|
||||
return '|';
|
||||
}
|
||||
|
||||
return ',';
|
||||
|
||||
},
|
||||
|
||||
get: function ($value) {
|
||||
if ($value == 'semicolon') {
|
||||
return ';';
|
||||
}
|
||||
if ($value == 'pipe') {
|
||||
return '|';
|
||||
}
|
||||
|
||||
return ',';
|
||||
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('imports', function (Blueprint $table) {
|
||||
$table->string('delimiter', 1)->nullable()->default(',');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('imports', function (Blueprint $table) {
|
||||
$table->dropColumn('delimiter');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -26,7 +26,10 @@
|
||||
<div class="box-body">
|
||||
<div class="alert alert-warning">
|
||||
|
||||
<i class="fa fa-warning info" aria-hidden="true"></i> <strong>{{ trans('general.warning', ['warning'=> trans('general.errors_importing')]) }}</strong>
|
||||
<i class="fa fa-warning info" aria-hidden="true"></i>
|
||||
<strong>
|
||||
{{ trans('general.warning', ['warning'=> trans('general.errors_importing')]) }}
|
||||
</strong>
|
||||
</div>
|
||||
|
||||
<div class="errors-table">
|
||||
@@ -59,41 +62,19 @@
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="col-md-9">
|
||||
<div class="col-md-8">
|
||||
<div class="box">
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-12">
|
||||
|
||||
@if($progress != -1)
|
||||
<div class="col-md-10 col-sm-5 col-xs-12" style="height: 35px;" id='progress-container'>
|
||||
<div class="progress progress-striped-active" style="height: 100%;">
|
||||
<div id='progress-bar' class="progress-bar {{ $progress_bar_class }}" role="progressbar" style="width: {{ $progress }}%">
|
||||
<h4 id="progress-text">{!! $progress_message !!}</h4>
|
||||
</div>
|
||||
@if($progress != -1)
|
||||
<div class="col-md-12" style="height: 35px;" id='progress-container'>
|
||||
<div class="progress progress-striped-active" style="height: 100%;">
|
||||
<div id='progress-bar' class="progress-bar {{ $progress_bar_class }}" role="progressbar" style="width: {{ $progress }}%">
|
||||
<h4 id="progress-text">{!! $progress_message !!}</h4>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="col-md-4 col-sm-5 col-xs-12 text-right pull-right">
|
||||
|
||||
<!-- The fileinput-button span is used to style the file input field as button -->
|
||||
@if (!config('app.lock_passwords'))
|
||||
<span class="btn btn-primary fileinput-button">
|
||||
<span>{{ trans('button.select_file') }}</span>
|
||||
<!-- The file input field used as target for the file upload widget -->
|
||||
<label for="files[]"><span class="sr-only">{{ trans('admin/importer/general.select_file') }}</span></label>
|
||||
<input id="fileupload" type="file" name="files[]" data-url="{{ route('api.imports.index') }}" accept="text/csv" aria-label="files[]">
|
||||
</span>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@endif
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12 table-responsive" style="padding-top: 30px;">
|
||||
@@ -288,13 +269,75 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<h2>{{ trans('general.importing') }}</h2>
|
||||
<p>{!! trans('general.importing_help') !!}</p>
|
||||
<div class="col-md-4">
|
||||
|
||||
<div class="box box-default">
|
||||
<div class="box-header with-border">
|
||||
<h2 class="box-title">
|
||||
<x-icon type="import"/>
|
||||
{{ trans('general.importing') }}
|
||||
</h2>
|
||||
<div class="box-tools pull-right">
|
||||
</div>
|
||||
</div><!-- /.box-header -->
|
||||
|
||||
<div class="box-body">
|
||||
|
||||
<p>{!! trans('general.importing_help') !!}</p>
|
||||
|
||||
@if (config('app.lock_passwords')===true)
|
||||
<p class="alert alert-warning">
|
||||
<i class="fas fa-lock">
|
||||
|
||||
</i>
|
||||
{{ trans('general.feature_disabled') }}
|
||||
</p>
|
||||
@else
|
||||
|
||||
<form class="form-horizontal">
|
||||
<fieldset>
|
||||
<legend style="border: 0px; font-size: 15px;">Select Delimiter:</legend>
|
||||
<label class="form-control">
|
||||
<input type="radio" name="delimiter" id="delimiter" value="comma" wire:model.live="delimiter">
|
||||
Comma
|
||||
</label>
|
||||
|
||||
<label class="form-control">
|
||||
<input type="radio" name="delimiter" id="delimiter" value="semicolon" wire:model.live="delimiter">
|
||||
Semicolon
|
||||
</label>
|
||||
|
||||
<label class="form-control">
|
||||
<input type="radio" name="delimiter" id="delimiter" value="pipe" wire:model.live="delimiter">
|
||||
Pipe
|
||||
</label>
|
||||
</fieldset>
|
||||
|
||||
<span class="btn btn-primary fileinput-button">
|
||||
<span>
|
||||
<x-icon type="paperclip" />
|
||||
{{ trans('button.select_file') }}
|
||||
</span>
|
||||
<!-- The file input field used as target for the file upload widget -->
|
||||
<label for="files[]">
|
||||
<span class="sr-only">{{ trans('admin/importer/general.select_file') }}
|
||||
</span>
|
||||
</label>
|
||||
<input id="fileupload" type="file" name="files[]" data-url="{{ route('api.imports.index').'?delimiter='.$delimiter }}" accept="text/csv" aria-label="files[]" data-maxsize="{{ Helper::file_upload_max_size() }}" aria-hidden="true">
|
||||
</span>
|
||||
</form>
|
||||
|
||||
<p class="help-block">{{ trans_choice('general.filetypes_accepted_help', 1, ['size' => Helper::file_upload_max_size_readable(), 'types' => 'csv']) }}</p>
|
||||
|
||||
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@script
|
||||
<script>
|
||||
|
||||
|
||||
@@ -169,8 +169,6 @@
|
||||
|
||||
<div class="form-group {{ $errors->has((isset($fieldname) ? $fieldname : 'file')) ? 'has-error' : '' }}" style="margin-bottom: 0px;">
|
||||
<div class="col-md-8 col-xs-8">
|
||||
|
||||
|
||||
<!-- displayed on screen -->
|
||||
<label class="btn btn-default col-md-12 col-xs-12" aria-hidden="true">
|
||||
<x-icon type="paperclip" />
|
||||
@@ -187,7 +185,9 @@
|
||||
<div class="col-md-12">
|
||||
|
||||
<p class="label label-default col-md-12" style="font-size: 120%!important; margin-top: 10px; margin-bottom: 10px;" id="uploadFile-info"></p>
|
||||
<p class="help-block" style="margin-top: 10px;" id="uploadFile-status">{{ trans_choice('general.filetypes_accepted_help', 1, ['size' => Helper::file_upload_max_size_readable(), 'types' => '.zip']) }}</p>
|
||||
<p class="help-block" style="margin-top: 10px;" id="uploadFile-status">
|
||||
{{ trans_choice('general.filetypes_accepted_help', 1, ['size' => Helper::file_upload_max_size_readable(), 'types' => '.zip']) }}
|
||||
</p>
|
||||
{!! $errors->first('file', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user