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;
|
|
|
|
|
|
|
|
class Importer extends Component
|
|
|
|
{
|
|
|
|
public $files;
|
|
|
|
public $processDetails;
|
|
|
|
public $forcerefresh;
|
|
|
|
|
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-01-13 01:19:13 -08:00
|
|
|
protected $rules = [
|
|
|
|
'files.*.file_path' => 'required|string',
|
|
|
|
'files.*.created_at' => 'required|string',
|
|
|
|
'files.*.filesize' => 'required|integer'
|
|
|
|
];
|
|
|
|
|
2022-11-22 12:41:25 -08:00
|
|
|
protected $listeners = ['hideDetails' => 'hideDetails'];
|
|
|
|
|
2022-01-13 01:19:13 -08:00
|
|
|
public function mount()
|
|
|
|
{
|
2022-09-19 21:04:46 -07:00
|
|
|
//$this->files = Import::all(); // this *SHOULD* be how it works, but...it doesn't? (note orderBy/get, below)
|
|
|
|
//$this->forcerefresh = 0;
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
public function toggleEvent($id)
|
|
|
|
{
|
|
|
|
Log::error("toggled on: ".$id);
|
|
|
|
$this->processDetails = Import::find($id);
|
|
|
|
}
|
|
|
|
|
2022-11-22 12:41:25 -08:00
|
|
|
public function hideDetails()
|
|
|
|
{
|
|
|
|
Log::error("hiding details!");
|
|
|
|
$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);
|
|
|
|
//\Log::debug("File is: ".print_r($file,true));
|
|
|
|
if($id == $file->id) {
|
|
|
|
// FIXME - should I do a try/catch on this and use the file_delete_failure or whatever, if needed?
|
|
|
|
\Log::debug("I FOUND IT!!!!");
|
|
|
|
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');
|
|
|
|
$this->message_type = 'success'; // uhm, I mean, I guess?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
2022-01-13 01:19:13 -08:00
|
|
|
return view('livewire.importer');
|
|
|
|
}
|
|
|
|
}
|