Skip to content

A free open source IT asset/license management system

WIP: trying to merge two LW components into one, not working yet

Brady Wetherington704a2ad858b2
diff --git a/app/Http/Livewire/Importer.php b/app/Http/Livewire/Importer.php
index 237ebe5501..e54bf20252 100644
--- a/app/Http/Livewire/Importer.php
+++ b/app/Http/Livewire/Importer.php
@@ -2,6 +2,7 @@
namespace App\Http\Livewire;
+use App\Models\CustomField;
use Livewire\Component;
use App\Models\Import;
@@ -25,25 +26,248 @@ class Importer extends Component
public $message; //status/error message?
public $message_type; //success/error?
+ //originally from ImporterFile
public $import_errors; //
+ public $activeFile; //this gets automatically populated on instantiation (no, it doesn't)
+ public $importTypes;
+ public $columnOptions;
+ public $statusType;
+ public $statusText;
+ public $update;
+ public $send_welcome;
+ public $run_backup;
+ public $field_map; // we need a separate variable for the field-mapping, because the keys in the normal array are too complicated for Livewire to understand
protected $rules = [
'files.*.file_path' => 'required|string',
'files.*.created_at' => 'required|string',
- 'files.*.filesize' => 'required|integer'
+ 'files.*.filesize' => 'required|integer',
+ 'activeFile.import_type' => 'string',
+ 'activeFile.field_map' => 'array',
+ 'activeFile.header_row' => 'array',
+ 'field_map' => 'array'
];
protected $listeners = [
'hideDetails' => 'hideDetails',
'importError' => 'importError',
- 'alert' => 'alert'
+ 'alert' => 'alert',
+ 'refreshMe' => '$refresh'
]; // TODO - try using the 'short' form of this?
+
+
+ public function generate_field_map()
+ {
+ $tmp = array_combine($this->activeFile->header_row, $this->field_map);
+ return json_encode(array_filter($tmp));
+ }
+
+ static $general = [
+ 'category' => 'Category',
+ 'company' => 'Company',
+ 'email' => 'Email',
+ 'item_name' => 'Item Name',
+ 'location' => 'Location',
+ 'maintained' => 'Maintained',
+ 'manufacturer' => 'Manufacturer',
+ 'notes' => 'Notes',
+ 'order_number' => 'Order Number',
+ 'purchase_cost' => 'Purchase Cost',
+ 'purchase_date' => 'Purchase Date',
+ 'quantity' => 'Quantity',
+ 'requestable' => 'Requestable',
+ 'serial' => 'Serial Number',
+ 'supplier' => 'Supplier',
+ 'username' => 'Username',
+ 'department' => 'Department',
+ ];
+
+ static $accessories = [
+ 'model_number' => 'Model Number',
+ ];
+
+ static $assets = [
+ 'asset_tag' => 'Asset Tag',
+ 'asset_model' => 'Model Name',
+ 'byod' => 'BYOD',
+ 'checkout_class' => 'Checkout Type',
+ 'checkout_location' => 'Checkout Location',
+ 'image' => 'Image Filename',
+ 'model_number' => 'Model Number',
+ 'full_name' => 'Full Name',
+ 'status' => 'Status',
+ 'warranty_months' => 'Warranty Months',
+ ];
+
+ static $consumables = [
+ 'item_no' => "Item Number",
+ 'model_number' => "Model Number",
+ 'min_amt' => "Minimum Quantity",
+ ];
+
+ static $licenses = [
+ 'asset_tag' => 'Assigned To Asset',
+ 'expiration_date' => 'Expiration Date',
+ 'full_name' => 'Full Name',
+ 'license_email' => 'Licensed To Email',
+ 'license_name' => 'Licensed To Name',
+ 'purchase_order' => 'Purchase Order',
+ 'reassignable' => 'Reassignable',
+ 'seats' => 'Seats',
+ ];
+
+ static $users = [
+ 'employee_num' => 'Employee Number',
+ 'first_name' => 'First Name',
+ 'jobtitle' => 'Job Title',
+ 'last_name' => 'Last Name',
+ 'phone_number' => 'Phone Number',
+ 'manager_first_name' => 'Manager First Name',
+ 'manager_last_name' => 'Manager Last Name',
+ 'activated' => 'Activated',
+ 'address' => 'Address',
+ 'city' => 'City',
+ 'state' => 'State',
+ 'country' => 'Country',
+ 'vip' => 'VIP'
+ ];
+
+ //array of "real fieldnames" to a list of aliases for that field
+ static $aliases = [
+ 'model_number' =>
+ [
+ 'model',
+ 'model no',
+ 'model no.',
+ 'model number',
+ 'model num',
+ 'model num.'
+ ],
+ 'warranty_months' =>
+ [
+ 'Warranty',
+ 'Warranty Months'
+ ],
+ 'qty' =>
+ [
+ 'QTY',
+ 'Quantity'
+ ],
+ 'min_amt' =>
+ [
+ 'Min Amount',
+ 'Min QTY'
+ ],
+ 'next_audit_date' =>
+ [
+ 'Next Audit',
+ ],
+
+
+ ];
+
+ private function getColumns($type)
+ {
+ switch($type) {
+ case 'asset':
+ $results = self::$general + self::$assets;
+ break;
+ case 'accessory':
+ $results = self::$general + self::$accessories;
+ break;
+ case 'consumable':
+ $results = self::$general + self::$consumables;
+ break;
+ case 'license':
+ $results = self::$general + self::$licenses;
+ break;
+ case 'user':
+ $results = self::$general + self::$users;
+ break;
+ default:
+ $results = self::$general;
+ }
+ asort($results, SORT_FLAG_CASE|SORT_STRING);
+ if($type == "asset") {
+ // add Custom Fields after a horizontal line
+ $results['-'] = "———".trans('admin/custom_fields/general.custom_fields')."———’";
+ foreach(CustomField::orderBy('name')->get() AS $field) {
+ $results[$field->db_column_name()] = $field->name;
+ }
+ }
+ return $results;
+ }
+
+ public function updating($name, $new_import_type)
+ {
+ if ($name == "activeFile.import_type") {
+ \Log::info("WE ARE CHANGING THE import_type!!!!! TO: ".$new_import_type);
+ // go through each header, find a matching field to try and map it to.
+ foreach($this->activeFile->header_row as $i => $header) {
+ // do we have something mapped already?
+ if (array_key_exists($i, $this->field_map)) {
+ // yes, we do. Is it valid for this type of import?
+ // (e.g. the import type might have been changed...?)
+ if (array_key_exists($this->field_map[$i], $this->columnOptions[$new_import_type])) {
+ //yes, this key *is* valid. Continue on to the next field.
+ continue;
+ } else {
+ //no, this key is *INVALID* for this import type. Better set it to null
+ // and we'll hope that the aliases or something else picks it up.
+ $this->field_map[$i] = null; // fingers crossed! But it's not likely, tbh.
+ } // TODO - strictly speaking, this isn't necessary here I don't think.
+ }
+ // first, check for exact matches
+ foreach ($this->columnOptions[$new_import_type] AS $value => $text) {
+ if (strcasecmp($text, $header) === 0) { // case-INSENSITIVe on purpose!
+ $this->field_map[$i] = $value;
+ continue 2; //don't bother with the alias check, go to the next header
+ }
+ }
+ // if you got here, we didn't find a match. Try the aliases
+ foreach(self::$aliases as $key => $alias_values) {
+ foreach($alias_values as $alias_value) {
+ if (strcasecmp($alias_value,$header) === 0) { // aLsO CaSe-INSENSitiVE!
+ // Make *absolutely* sure that this key actually _exists_ in this import type -
+ // you can trigger this by importing accessories with a 'Warranty' column (which don't exist
+ // in "Accessories"!)
+ if (array_key_exists($key, $this->columnOptions[$new_import_type])) {
+ $this->field_map[$i] = $key;
+ continue 3; // bust out of both of these loops; as well as the surrounding one - e.g. move on to the next header
+ }
+ }
+ }
+ }
+ // and if you got here, we got nothing. Let's recommend 'null'
+ $this->field_map[$i] = null; // Booooo :(
+ }
+ }
+ }
+
+
public function mount()
{
$this->authorize('import');
$this->progress = -1; // '-1' means 'don't show the progressbar'
$this->progress_bar_class = 'progress-bar-warning';
+ \Log::info("Hey, we are calling MOUNT (in the importer-file) !!!!!!!!"); //fcuk
+ $this->importTypes = [
+ 'asset' => trans('general.assets'),
+ 'accessory' => trans('general.accessories'),
+ 'consumable' => trans('general.consumables'),
+ 'component' => trans('general.components'),
+ 'license' => trans('general.licenses'),
+ 'user' => trans('general.users'),
+ ];
+
+ $this->columnOptions[''] = $this->getColumns(''); //blank mode? I don't know what this is supposed to mean
+ foreach($this->importTypes AS $type => $name) {
+ $this->columnOptions[$type] = $this->getColumns($type);
+ }
+ if ($this->activeFile) {
+ $this->field_map = $this->activeFile->field_map ? array_values($this->activeFile->field_map) : [];
+ }
}
public function hideMessages()
@@ -65,9 +289,28 @@ class Importer extends Component
$this->message_type = "danger";
}
+ public function boot() // well, fuck.
+ {
+ \Log::error("HEY WE ARE DOING FOR THE BOOOTTS!!!!");
+ $this->processDetails = null;
+ }
+
public function toggleEvent($id)
{
+ // do something here?
+ // I mean, I kinda don't get it?
+ $gonna_refresh = !!$this->processDetails;
+ if($this->processDetails) {
+ $this->processDetails = null;
+ }
+ \Log::error("The ID we are trying to find is AS FOLLOWS: ".$id);
$this->processDetails = Import::find($id);
+// $this->emit('refreshFile'); ///FUUUUUUUUUUUUUU
+ ///
+// }
+ /// Just literally none of this fucking shit works.
+ \Log::error("The import type we are about to try and load up is gonna be this: ".$this->processDetails->import_type);
+
}
public function hideDetails()
diff --git a/app/Http/Livewire/ImporterFile.php b/app/Http/Livewire/ImporterFile.php
index c065cbbb87..e29320d6b9 100644
--- a/app/Http/Livewire/ImporterFile.php
+++ b/app/Http/Livewire/ImporterFile.php
@@ -10,232 +10,32 @@ use Log;
class ImporterFile extends Component
{
- public $activeFile; //this gets automatically populated on instantiation
- public $importTypes;
- public $columnOptions;
- public $statusType;
- public $statusText;
- public $update;
- public $send_welcome;
- public $run_backup;
- public $field_map; // we need a separate variable for the field-mapping, because the keys in the normal array are too complicated for Livewire to understand
-
- protected $rules = [
- 'activeFile.import_type' => 'string',
- 'activeFile.field_map' => 'array',
- 'activeFile.header_row' => 'array',
- 'field_map' => 'array'
- ];
-
-
- public function generate_field_map()
- {
- $tmp = array_combine($this->activeFile->header_row, $this->field_map);
- return json_encode(array_filter($tmp));
- }
- static $general = [
- 'category' => 'Category',
- 'company' => 'Company',
- 'email' => 'Email',
- 'item_name' => 'Item Name',
- 'location' => 'Location',
- 'maintained' => 'Maintained',
- 'manufacturer' => 'Manufacturer',
- 'notes' => 'Notes',
- 'order_number' => 'Order Number',
- 'purchase_cost' => 'Purchase Cost',
- 'purchase_date' => 'Purchase Date',
- 'quantity' => 'Quantity',
- 'requestable' => 'Requestable',
- 'serial' => 'Serial Number',
- 'supplier' => 'Supplier',
- 'username' => 'Username',
- 'department' => 'Department',
+ protected $listeners = [
+ 'refreshFile' => '$refresh'
];
- static $accessories = [
- 'model_number' => 'Model Number',
- ];
- static $assets = [
- 'asset_tag' => 'Asset Tag',
- 'asset_model' => 'Model Name',
- 'byod' => 'BYOD',
- 'checkout_class' => 'Checkout Type',
- 'checkout_location' => 'Checkout Location',
- 'image' => 'Image Filename',
- 'model_number' => 'Model Number',
- 'full_name' => 'Full Name',
- 'status' => 'Status',
- 'warranty_months' => 'Warranty Months',
- ];
-
- static $consumables = [
- 'item_no' => "Item Number",
- 'model_number' => "Model Number",
- 'min_amt' => "Minimum Quantity",
- ];
- static $licenses = [
- 'asset_tag' => 'Assigned To Asset',
- 'expiration_date' => 'Expiration Date',
- 'full_name' => 'Full Name',
- 'license_email' => 'Licensed To Email',
- 'license_name' => 'Licensed To Name',
- 'purchase_order' => 'Purchase Order',
- 'reassignable' => 'Reassignable',
- 'seats' => 'Seats',
- ];
+ public function updatedActiveFile()
+ {
+ \Log::error("We have updated the active file! WHOOOO!!");
- static $users = [
- 'employee_num' => 'Employee Number',
- 'first_name' => 'First Name',
- 'jobtitle' => 'Job Title',
- 'last_name' => 'Last Name',
- 'phone_number' => 'Phone Number',
- 'manager_first_name' => 'Manager First Name',
- 'manager_last_name' => 'Manager Last Name',
- 'activated' => 'Activated',
- 'address' => 'Address',
- 'city' => 'City',
- 'state' => 'State',
- 'country' => 'Country',
- 'vip' => 'VIP'
- ];
+ // unset all of the input doodads,
+ // maybe unset or reset some properties up in here.
- //array of "real fieldnames" to a list of aliases for that field
- static $aliases = [
- 'model_number' =>
- [
- 'model',
- 'model no',
- 'model no.',
- 'model number',
- 'model num',
- 'model num.'
- ],
- 'warranty_months' =>
- [
- 'Warranty',
- 'Warranty Months'
- ],
- 'qty' =>
- [
- 'QTY',
- 'Quantity'
- ],
- 'min_amt' =>
- [
- 'Min Amount',
- 'Min QTY'
- ],
- 'next_audit_date' =>
- [
- 'Next Audit',
- ],
-
+ }
- ];
- private function getColumns($type)
- {
- switch($type) {
- case 'asset':
- $results = self::$general + self::$assets;
- break;
- case 'accessory':
- $results = self::$general + self::$accessories;
- break;
- case 'consumable':
- $results = self::$general + self::$consumables;
- break;
- case 'license':
- $results = self::$general + self::$licenses;
- break;
- case 'user':
- $results = self::$general + self::$users;
- break;
- default:
- $results = self::$general;
- }
- asort($results, SORT_FLAG_CASE|SORT_STRING);
- if($type == "asset") {
- // add Custom Fields after a horizontal line
- $results['-'] = "———".trans('admin/custom_fields/general.custom_fields')."———’";
- foreach(CustomField::orderBy('name')->get() AS $field) {
- $results[$field->db_column_name()] = $field->name;
- }
- }
- return $results;
- }
- public function updating($name, $new_import_type)
- {
- if ($name == "activeFile.import_type") {
- \Log::info("WE ARE CHANGING THE import_type!!!!! TO: ".$new_import_type);
- // go through each header, find a matching field to try and map it to.
- foreach($this->activeFile->header_row as $i => $header) {
- // do we have something mapped already?
- if (array_key_exists($i, $this->field_map)) {
- // yes, we do. Is it valid for this type of import?
- // (e.g. the import type might have been changed...?)
- if (array_key_exists($this->field_map[$i], $this->columnOptions[$new_import_type])) {
- //yes, this key *is* valid. Continue on to the next field.
- continue;
- } else {
- //no, this key is *INVALID* for this import type. Better set it to null
- // and we'll hope that the aliases or something else picks it up.
- $this->field_map[$i] = null; // fingers crossed! But it's not likely, tbh.
- } // TODO - strictly speaking, this isn't necessary here I don't think.
- }
- // first, check for exact matches
- foreach ($this->columnOptions[$new_import_type] AS $value => $text) {
- if (strcasecmp($text, $header) === 0) { // case-INSENSITIVe on purpose!
- $this->field_map[$i] = $value;
- continue 2; //don't bother with the alias check, go to the next header
- }
- }
- // if you got here, we didn't find a match. Try the aliases
- foreach(self::$aliases as $key => $alias_values) {
- foreach($alias_values as $alias_value) {
- if (strcasecmp($alias_value,$header) === 0) { // aLsO CaSe-INSENSitiVE!
- // Make *absolutely* sure that this key actually _exists_ in this import type -
- // you can trigger this by importing accessories with a 'Warranty' column (which don't exist
- // in "Accessories"!)
- if (array_key_exists($key, $this->columnOptions[$new_import_type])) {
- $this->field_map[$i] = $key;
- continue 3; // bust out of both of these loops; as well as the surrounding one - e.g. move on to the next header
- }
- }
- }
- }
- // and if you got here, we got nothing. Let's recommend 'null'
- $this->field_map[$i] = null; // Booooo :(
- }
- }
- }
public function mount()
{
- $this->importTypes = [
- 'asset' => trans('general.assets'),
- 'accessory' => trans('general.accessories'),
- 'consumable' => trans('general.consumables'),
- 'component' => trans('general.components'),
- 'license' => trans('general.licenses'),
- 'user' => trans('general.users'),
- ];
-
- $this->columnOptions[''] = $this->getColumns(''); //blank mode? I don't know what this is supposed to mean
- foreach($this->importTypes AS $type => $name) {
- $this->columnOptions[$type] = $this->getColumns($type);
- }
- $this->field_map = $this->activeFile->field_map ? array_values($this->activeFile->field_map): [];
}
public function postSave()
{
+ //does this, like, do anything, or get used by anything?
if (!$this->activeFile->import_type) {
Log::error("didn't find an import type :(");
$this->statusType ='error';
diff --git a/resources/views/livewire/importer-file.blade.php b/resources/views/livewire/importer-file.blade.php
index a61daf2d4b..e69de29bb2 100644
--- a/resources/views/livewire/importer-file.blade.php
+++ b/resources/views/livewire/importer-file.blade.php
@@ -1,179 +0,0 @@
-
- <div class="col-md-12">
-
- <div class="form-group col-md-12">
-
- <label for="activeFile.import_type" class="col-md-3 col-xs-12 text-right">
- Import Type
- </label>
-
- <div class="col-md-9 col-xs-12">
- {{ Form::select('activeFile.import_type', $importTypes, $activeFile->import_type, [
- 'id' => 'import_type',
- 'class' => 'livewire-select2',
- 'style' => 'min-width: 350px',
- 'data-placeholder' => trans('general.select_var', ['thing' => trans('general.import_type')]), /* TODO: translate me */
- 'placeholder' => '', //needed so that the form-helper will put an empty option first
- 'data-minimum-results-for-search' => '-1', // Remove this if the list gets long enough that we need to search
- 'data-livewire-component' => $_instance->id
- ]) }}
- </div>
- </div>
-
- <div class="form-group col-md-12">
- <label for="update" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
- <input type="checkbox" class="minimal livewire-icheck" name="update" data-livewire-component="{{ $_instance->id }}">
- Update Existing Values?
- </label>
- </div>
-
- <div class="form-group col-md-12">
- <label for="send_welcome" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
- <input type="checkbox" class="minimal livewire-icheck" name="send_welcome" data-livewire-component="{{ $_instance->id }}">
- Send Welcome Email for new Users?
- </label>
- </div>
-
- <div class="form-group col-md-12">
- <label for="run_backup" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
- <input type="checkbox" class="minimal livewire-icheck" name="run_backup" data-livewire-component="{{ $_instance->id }}">
- Backup before importing?
- </label>
- </div>
-
-
- @if ($statusText)
- <div class="form-group">
- <div class="alert col-md-8 col-md-offset-2 {{ $statusType == 'success' ? 'alert-success' : ($statusType == 'error' ? 'alert-danger' : 'alert-info') }}" style="text-align:left">
- {{ $statusText }}
- </div><!-- /alert -->
- </div>
- @endif
-
-
- @if ($activeFile->import_type)
- <div class="form-group col-md-12">
- <hr style="border-top: 1px solid lightgray">
- <h3><i class="{{ Helper::iconTypeByItem($activeFile->import_type) }}"></i> Map {{ ucwords($activeFile->import_type) }} Import Fields</h3>
- <hr style="border-top: 1px solid lightgray">
- </div>
- <div class="form-group col-md-12">
- <div class="col-md-3 text-right">
- <strong>CSV Header Field</strong>
- </div>
- <div class="col-md-4">
- <strong>Import Field</strong>
- </div>
- <div class="col-md-5">
- <strong>Sample Value</strong>
- </div>
- </div><!-- /div row -->
-
- @if($activeFile->header_row)
-
- @foreach($activeFile->header_row as $index => $header)
-
- <div class="form-group col-md-12" wire:key="header-row-{{ $index }}">
-
- <label for="field_map.{{ $index }}" class="col-md-3 control-label text-right">{{ $header }}</label>
- <div class="col-md-4">
-
- {{ Form::select('field_map.'.$index, $columnOptions[$activeFile->import_type], @$field_map[$index],
- [
- 'class' => 'mappings livewire-select2',
- 'placeholder' => 'Do Not Import',
- 'style' => 'min-width: 100%',
- 'data-livewire-component' => $_instance->id
- ],[
- '-' => ['disabled' => true] // this makes the "-----" line unclickable
- ])
- }}
- </div>
- <div class="col-md-5">
- <p class="form-control-static">{{ str_limit($activeFile->first_row[$index], 50, '...') }}</p>
- </div>
- </div><!-- /div row -->
- @endforeach
- @else
- No Columns Found!
- @endif
-
- <div class="form-group col-md-12">
- <div class="col-md-3 text-left">
- <a href="#" wire:click="$emit('hideDetails')">{{ trans('general.cancel') }}</a>
- </div>
- <div class="col-md-9">
- <button type="submit" class="btn btn-primary col-md-5" id="import">Import</button>
- <br><br>
- </div>
- </div>
-
- @if($statusText)
- <div class="alert col-md-12 col-md-offset-2 {{ $statusType == 'success' ? 'alert-success' : ($statusType == 'error' ? 'alert-danger' : 'alert-info') }}" style="padding-top: 20px;">
- {{ $statusText }}
- </div>
- @endif
- @endif {{-- end of if ... activeFile->import_type --}}
-
- </div><!-- /div v-show -->
-
-<script>
-$(function () {
- // initialize iCheck for use with livewire
- $('.minimal.livewire-icheck').iCheck({
- checkboxClass: 'icheckbox_minimal-blue',
- })
-
- // we have to hook up to the `<tr id='importer-file'>` at the root of this display,
- // because the #import button isn't visible until you click an import_type
- $('#importer-file').on('click', '#import', function () {
- console.warn("You clicked it!!!!")
- if([email protected]_type) {
- @this.statusType='error';
- @this.statusText= "An import type is required... "; //TODO: translate?
- return;
- }
- @this.statusType ='pending';
- @this.statusText = "{{ trans('admin/hardware/form.processing_spinner') }}";
- @this.generate_field_map().then(function (mappings_raw) {
- var mappings = JSON.parse(mappings_raw)
- // console.warn("Here is the mappings:")
- // console.dir(mappings)
- $.post({
- url: "{{ route('api.imports.importFile', $activeFile->id) }}",
- contentType: 'application/json',
- data: JSON.stringify({
- 'import-update': [email protected],
- 'send-welcome': [email protected]_welcome,
- 'import-type': @this.activeFile.import_type,
- 'run-backup': [email protected]_backup,
- 'column-mappings': mappings
- }),
- headers: {
- "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
- }
- }).done( function (body) {
- // Success
- @this.statusType="success";
- @this.statusText = "Success... Redirecting.";
- console.dir(body)
- window.location.href = body.messages.redirect_url;
- }).fail( function (jqXHR, textStatus, error) {
- // Failure
- var body = jqXHR.responseJSON
- if(body.status == 'import-errors') {
- @this.emit('importError', body.messages);
- @this.statusType='error';
- @this.statusText = "Error";
- } else {
- console.warn("Not import-errors, just regular errors")
- console.dir(body)
- @this.emit('alert', body.error)
- }
- @this.emit('hideDetails')
- });
- })
- return false;
- });})
-
-</script>
\ No newline at end of file
diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php
index 18eeebaedd..3e80d9b2c5 100644
--- a/resources/views/livewire/importer.blade.php
+++ b/resources/views/livewire/importer.blade.php
@@ -112,12 +112,12 @@
@foreach($files as $currentFile)
- <tr style="{{ ($processDetails && ($currentFile->id == $processDetails->id)) ? 'font-weight: bold' : '' }}" class="{{ ($processDetails && ($currentFile->id == $processDetails->id)) ? 'warning' : '' }}">
+ <tr wire:key="current-file-selection-{{ $currentFile->id }}" style="{{ ($processDetails && ($currentFile->id == $processDetails->id)) ? 'font-weight: bold' : '' }}" class="{{ ($processDetails && ($currentFile->id == $processDetails->id)) ? 'warning' : '' }}">
<td class="col-md-6">{{ $currentFile->file_path }}</td>
<td class="col-md-3">{{ Helper::getFormattedDateObject($currentFile->created_at, 'datetime', false) }}</td>
<td class="col-md-1">{{ Helper::formatFilesizeUnits($currentFile->filesize) }}</td>
<td class="col-md-1 text-right">
- <button class="btn btn-sm btn-info" wire:click="toggleEvent({{ $currentFile->id }})">
+ <button class="btn btn-sm btn-info" wire:click="$set('activeFile',{{ $currentFile->id }})">
<i class="fas fa-retweet fa-fw" aria-hidden="true"></i>
<span class="sr-only">{{ trans('general.import') }}</span>
</button>
@@ -125,15 +125,195 @@
<i class="fas fa-trash icon-white" aria-hidden="true"></i><span class="sr-only"></span></button>
</td>
</tr>
-
+ <?php
+ \Log::error("Current file is: ".$currentFile->id);
+ ?>
@if( $currentFile && $processDetails && ($currentFile->id == $processDetails->id))
<tr class="warning">
- <td colspan="4">
- @livewire('importer-file', ['activeFile' => $currentFile])
+ <td colspan="4" >
+
+ <div class="col-md-12">
+
+ <div class="form-group col-md-12">
+
+ <label for="activeFile.import_type" class="col-md-3 col-xs-12 text-right">
+ Import Type
+ </label>
+
+ <div class="col-md-9 col-xs-12">
+ {{ Form::select('activeFile.import_type', $importTypes, $activeFile->import_type, [
+ 'id' => 'import_type',
+ 'class' => 'livewire-select2',
+ 'style' => 'min-width: 350px',
+ 'data-placeholder' => trans('general.select_var', ['thing' => trans('general.import_type')]), /* TODO: translate me */
+ 'placeholder' => '', //needed so that the form-helper will put an empty option first
+ 'data-minimum-results-for-search' => '-1', // Remove this if the list gets long enough that we need to search
+ 'data-livewire-component' => $_instance->id,
+ 'onchange' => "console.log('FAAAAAAAARTs');return true"
+ ]) }}
+ </div>
+ </div>
+
+ <div class="form-group col-md-12">
+ <label for="update" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
+ <input type="checkbox" class="minimal livewire-icheck" name="update" data-livewire-component="{{ $_instance->id }}">
+ Update Existing Values?
+ </label>
+ </div>
+
+ <div class="form-group col-md-12">
+ <label for="send_welcome" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
+ <input type="checkbox" class="minimal livewire-icheck" name="send_welcome" data-livewire-component="{{ $_instance->id }}">
+ Send Welcome Email for new Users?
+ </label>
+ </div>
+
+ <div class="form-group col-md-12">
+ <label for="run_backup" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
+ <input type="checkbox" class="minimal livewire-icheck" name="run_backup" data-livewire-component="{{ $_instance->id }}">
+ Backup before importing?
+ </label>
+ </div>
+
+
+ @if ($statusText)
+ <div class="form-group">
+ <div class="alert col-md-8 col-md-offset-2 {{ $statusType == 'success' ? 'alert-success' : ($statusType == 'error' ? 'alert-danger' : 'alert-info') }}" style="text-align:left">
+ {{ $statusText }}
+ </div><!-- /alert -->
+ </div>
+ @endif
+
+
+ @if ($activeFile->import_type)
+ <div class="form-group col-md-12">
+ <hr style="border-top: 1px solid lightgray">
+ <h3><i class="{{ Helper::iconTypeByItem($activeFile->import_type) }}"></i> Map {{ ucwords($activeFile->import_type) }} Import Fields</h3>
+ <hr style="border-top: 1px solid lightgray">
+ </div>
+ <div class="form-group col-md-12">
+ <div class="col-md-3 text-right">
+ <strong>CSV Header Field</strong>
+ </div>
+ <div class="col-md-4">
+ <strong>Import Field</strong>
+ </div>
+ <div class="col-md-5">
+ <strong>Sample Value</strong>
+ </div>
+ </div><!-- /div row -->
+
+ @if($activeFile->header_row)
+
+ @foreach($activeFile->header_row as $index => $header)
+
+ <div class="form-group col-md-12" wire:key="header-row-{{ $index }}">
+
+ <label for="field_map.{{ $index }}" class="col-md-3 control-label text-right">{{ $header }}</label>
+ <div class="col-md-4">
+
+ {{ Form::select('field_map.'.$index, $columnOptions[$activeFile->import_type], @$field_map[$index],
+ [
+ 'class' => 'mappings livewire-select2',
+ 'placeholder' => 'Do Not Import',
+ 'style' => 'min-width: 100%',
+ 'data-livewire-component' => $_instance->id
+ ],[
+ '-' => ['disabled' => true] // this makes the "-----" line unclickable
+ ])
+ }}
+ </div>
+ <div class="col-md-5">
+ <p class="form-control-static">{{ str_limit($activeFile->first_row[$index], 50, '...') }}</p>
+ </div>
+ </div><!-- /div row -->
+ @endforeach
+ @else
+ No Columns Found!
+ @endif
+
+ <div class="form-group col-md-12">
+ <div class="col-md-3 text-left">
+ <a href="#" wire:click="$emit('hideDetails')">{{ trans('general.cancel') }}</a>
+ </div>
+ <div class="col-md-9">
+ <button type="submit" class="btn btn-primary col-md-5" id="import">Import</button>
+ <br><br>
+ </div>
+ </div>
+
+ @if($statusText)
+ <div class="alert col-md-12 col-md-offset-2 {{ $statusType == 'success' ? 'alert-success' : ($statusType == 'error' ? 'alert-danger' : 'alert-info') }}" style="padding-top: 20px;">
+ {{ $statusText }}
+ </div>
+ @endif
+ @endif {{-- end of if ... activeFile->import_type --}}
+
+ <script>
+ $(function () {
+ // initialize iCheck for use with livewire
+ $('.minimal.livewire-icheck').iCheck({
+ checkboxClass: 'icheckbox_minimal-blue',
+ })
+
+ // we have to hook up to the `<tr id='importer-file'>` at the root of this display,
+ // because the #import button isn't visible until you click an import_type
+ $('#importer-file').on('click', '#import', function () {
+ console.warn("You clicked it!!!!")
+ if([email protected]_type) {
+ @this.statusType='error';
+ @this.statusText= "An import type is required... "; //TODO: translate?
+ return;
+ }
+ @this.statusType ='pending';
+ @this.statusText = "{{ trans('admin/hardware/form.processing_spinner') }}";
+ @this.generate_field_map().then(function (mappings_raw) {
+ var mappings = JSON.parse(mappings_raw)
+ // console.warn("Here is the mappings:")
+ // console.dir(mappings)
+ $.post({
+ url: "{{ route('api.imports.importFile', $activeFile->id) }}",
+ contentType: 'application/json',
+ data: JSON.stringify({
+ 'import-update': [email protected],
+ 'send-welcome': [email protected]_welcome,
+ 'import-type': @this.activeFile.import_type,
+ 'run-backup': [email protected]_backup,
+ 'column-mappings': mappings
+ }),
+ headers: {
+ "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
+ }
+ }).done( function (body) {
+ // Success
+ @this.statusType="success";
+ @this.statusText = "Success... Redirecting.";
+ console.dir(body)
+ window.location.href = body.messages.redirect_url;
+ }).fail( function (jqXHR, textStatus, error) {
+ // Failure
+ var body = jqXHR.responseJSON
+ if(body.status == 'import-errors') {
+ @this.emit('importError', body.messages);
+ @this.statusType='error';
+ @this.statusText = "Error";
+ } else {
+ console.warn("Not import-errors, just regular errors")
+ console.dir(body)
+ @this.emit('alert', body.error)
+ }
+ @this.emit('hideDetails')
+ });
+ })
+ return false;
+ });})
+
+ </script>
+ </div><!-- /div v-show -->
+
</td>
</tr>
@endif
- </tr>
@endforeach
</table>
</div>
@@ -148,6 +328,7 @@
</div>
</div>
+</div> {{-- DID I HAVE A MISSING CLOSING DIV HERE? PROBABLY!!!! --}}
@push('js')
<script>