2022-01-13 01:19:13 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
use App\Models\Import;
|
2022-09-19 21:04:46 -07:00
|
|
|
use Storage;
|
2022-01-13 01:19:13 -08:00
|
|
|
|
|
|
|
use Log;
|
2023-02-28 21:58:02 -08:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
|
|
|
2022-01-13 01:19:13 -08:00
|
|
|
|
|
|
|
class Importer extends Component
|
|
|
|
{
|
2023-02-28 21:58:02 -08:00
|
|
|
use AuthorizesRequests;
|
|
|
|
|
2022-01-13 01:19:13 -08:00
|
|
|
public $files;
|
|
|
|
public $processDetails;
|
|
|
|
|
2022-09-19 21:04:46 -07:00
|
|
|
public $progress; //upload progress - '-1' means don't show
|
|
|
|
public $progress_message; //progress message
|
|
|
|
public $progress_bar_class;
|
|
|
|
|
|
|
|
public $message; //status/error message?
|
|
|
|
public $message_type; //success/error?
|
|
|
|
|
2022-12-14 10:55:50 -08:00
|
|
|
public $import_errors; //
|
|
|
|
|
2022-01-13 01:19:13 -08:00
|
|
|
protected $rules = [
|
|
|
|
'files.*.file_path' => 'required|string',
|
|
|
|
'files.*.created_at' => 'required|string',
|
|
|
|
'files.*.filesize' => 'required|integer'
|
|
|
|
];
|
|
|
|
|
2023-02-28 21:58:02 -08:00
|
|
|
protected $listeners = [
|
|
|
|
'hideDetails' => 'hideDetails',
|
|
|
|
'importError' => 'importError',
|
|
|
|
'alert' => 'alert'
|
|
|
|
]; // TODO - try using the 'short' form of this?
|
2022-11-22 12:41:25 -08:00
|
|
|
|
2022-01-13 01:19:13 -08:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-02-28 21:58:02 -08:00
|
|
|
$this->authorize('import');
|
2022-09-19 21:04:46 -07:00
|
|
|
$this->progress = -1; // '-1' means 'don't show the progressbar'
|
|
|
|
$this->progress_bar_class = 'progress-bar-warning';
|
2022-01-13 01:19:13 -08:00
|
|
|
}
|
|
|
|
|
2022-09-19 21:04:46 -07:00
|
|
|
public function hideMessages()
|
2022-01-13 01:19:13 -08:00
|
|
|
{
|
2022-09-19 21:04:46 -07:00
|
|
|
$this->message='';
|
2022-01-13 01:19:13 -08:00
|
|
|
}
|
|
|
|
|
2022-12-14 10:55:50 -08:00
|
|
|
public function importError($errors)
|
|
|
|
{
|
2023-02-28 21:58:02 -08:00
|
|
|
\Log::debug("Errors fired!!!!");
|
|
|
|
\Log::debug(" Here they are...".print_r($errors,true));
|
2022-12-14 10:55:50 -08:00
|
|
|
$this->import_errors = $errors;
|
|
|
|
}
|
|
|
|
|
2023-02-28 18:36:52 -08:00
|
|
|
public function alert($obj)
|
|
|
|
{
|
2023-02-28 21:58:02 -08:00
|
|
|
\Log::debug("Alert object received: ".print_r($obj,true));
|
2023-02-28 18:36:52 -08:00
|
|
|
$this->message = $obj;
|
|
|
|
$this->message_type = "danger"; // FIXME - when does this get reset? Only when you click the 'x'?
|
|
|
|
}
|
|
|
|
|
2022-01-13 01:19:13 -08:00
|
|
|
public function toggleEvent($id)
|
|
|
|
{
|
|
|
|
$this->processDetails = Import::find($id);
|
|
|
|
}
|
|
|
|
|
2022-11-22 12:41:25 -08:00
|
|
|
public function hideDetails()
|
|
|
|
{
|
|
|
|
$this->processDetails = null;
|
|
|
|
}
|
|
|
|
|
2022-09-19 21:04:46 -07:00
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
foreach($this->files as $file) {
|
|
|
|
\Log::debug("File id is: ".$file->id);
|
|
|
|
if($id == $file->id) {
|
|
|
|
// FIXME - should I do a try/catch on this and use the file_delete_failure or whatever, if needed?
|
|
|
|
Storage::delete('imports/'.$file->file_path); // FIXME - last time I ran this, it *didn't* delete the file?!
|
|
|
|
$file->delete();
|
|
|
|
|
|
|
|
$this->message = trans('admin/hardware/message.import.file_delete_success');
|
2023-02-28 21:58:02 -08:00
|
|
|
$this->message_type = 'success';
|
2022-09-19 21:04:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-13 01:19:13 -08:00
|
|
|
public function render()
|
|
|
|
{
|
2022-09-19 21:04:46 -07:00
|
|
|
$this->files = Import::orderBy('id','desc')->get(); //HACK - slows down renders.
|
2023-02-28 18:36:52 -08:00
|
|
|
return view('livewire.importer')
|
|
|
|
->extends('layouts.default')
|
2023-02-28 21:58:02 -08:00
|
|
|
->section('content');
|
2022-01-13 01:19:13 -08:00
|
|
|
}
|
|
|
|
}
|