Migrate header row to component

This commit is contained in:
Marcus Moore 2024-07-16 13:30:29 -07:00
parent 017530ba4b
commit 69263f0e5b
No known key found for this signature in database
2 changed files with 9 additions and 5 deletions

View file

@ -21,6 +21,7 @@ class Importer extends Component
//originally from ImporterFile //originally from ImporterFile
public $import_errors; // public $import_errors; //
public ?Import $activeFile = null; public ?Import $activeFile = null;
public $headerRow = [];
public $importTypes; public $importTypes;
public $columnOptions; public $columnOptions;
public $statusType; public $statusType;
@ -49,6 +50,7 @@ class Importer extends Component
'activeFile.import_type' => 'string', 'activeFile.import_type' => 'string',
'activeFile.field_map' => 'array', 'activeFile.field_map' => 'array',
'activeFile.header_row' => 'array', 'activeFile.header_row' => 'array',
'headerRow' => 'array',
'field_map' => 'array' 'field_map' => 'array'
]; ];
@ -62,7 +64,7 @@ class Importer extends Component
{ {
$tmp = array(); $tmp = array();
if ($this->activeFile) { if ($this->activeFile) {
$tmp = array_combine($this->activeFile->header_row, $this->field_map); $tmp = array_combine($this->headerRow, $this->field_map);
$tmp = array_filter($tmp); $tmp = array_filter($tmp);
} }
return json_encode($tmp); return json_encode($tmp);
@ -112,7 +114,7 @@ class Importer extends Component
if ($propertyKey == "import_type") { if ($propertyKey == "import_type") {
// go through each header, find a matching field to try and map it to. // go through each header, find a matching field to try and map it to.
foreach ($this->activeFile->header_row as $i => $header) { foreach ($this->headerRow as $i => $header) {
// do we have something mapped already? // do we have something mapped already?
if (array_key_exists($i, $this->field_map)) { if (array_key_exists($i, $this->field_map)) {
// yes, we do. Is it valid for this type of import? // yes, we do. Is it valid for this type of import?
@ -510,8 +512,10 @@ class Importer extends Component
return; return;
} }
$this->headerRow = $this->activeFile->header_row;
$this->field_map = null; $this->field_map = null;
foreach($this->activeFile->header_row as $element) { foreach ($this->headerRow as $element) {
if(isset($this->activeFile->field_map[$element])) { if(isset($this->activeFile->field_map[$element])) {
$this->field_map[] = $this->activeFile->field_map[$element]; $this->field_map[] = $this->activeFile->field_map[$element];
} else { } else {

View file

@ -213,9 +213,9 @@
</div> </div>
</div><!-- /div row --> </div><!-- /div row -->
@if($activeFile->header_row) @if(! empty($headerRow))
@foreach($activeFile->header_row as $index => $header) @foreach($headerRow as $index => $header)
<div class="form-group col-md-12" wire:key="header-row-{{ $index }}"> <div class="form-group col-md-12" wire:key="header-row-{{ $index }}">