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;
|
2023-02-28 22:34:44 -08:00
|
|
|
$this->message_type = "danger";
|
2023-02-28 18:36:52 -08:00
|
|
|
}
|
|
|
|
|
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) {
|
2023-02-28 22:34:44 -08:00
|
|
|
if(Storage::delete('private_uploads/imports/'.$file->file_path)) {
|
|
|
|
$file->delete();
|
|
|
|
|
|
|
|
$this->message = trans('admin/hardware/message.import.file_delete_success');
|
|
|
|
$this->message_type = 'success';
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
$this->message = trans('admin/hardware/message.import.file_delete_error');
|
|
|
|
$this->message_type = 'danger';
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|