Display error message if import file deleted before it can be selected

This commit is contained in:
Marcus Moore 2023-09-20 17:22:12 -07:00
parent 439c2e095d
commit b1199100a0
3 changed files with 22 additions and 0 deletions

View file

@ -3,6 +3,7 @@
namespace App\Http\Livewire;
use App\Models\CustomField;
use Illuminate\Support\Facades\Session;
use Livewire\Component;
use App\Models\Import;
@ -161,6 +162,11 @@ class Importer extends Component
public function mount()
{
if (Session::has('error_message')) {
$this->message = Session::get('error_message');
$this->message_type = 'danger';
}
$this->authorize('import');
$this->progress = -1; // '-1' means 'don't show the progressbar'
$this->progress_bar_class = 'progress-bar-warning';
@ -484,8 +490,16 @@ class Importer extends Component
public function selectFile($id)
{
$this->clearMessage();
$this->activeFile = Import::find($id);
if (!$this->activeFile) {
Session::flash('error_message', trans('admin/hardware/message.import.file_missing'));
return redirect()->route('imports.index');
}
$this->field_map = null;
foreach($this->activeFile->header_row as $element) {
if(isset($this->activeFile->field_map[$element])) {
@ -520,6 +534,12 @@ class Importer extends Component
}
}
public function clearMessage()
{
$this->message = null;
$this->message_type = null;
}
public function render()
{
$this->files = Import::orderBy('id','desc')->get(); //HACK - slows down renders.

View file

@ -51,6 +51,7 @@ return [
'success' => 'Your file has been imported',
'file_delete_success' => 'Your file has been been successfully deleted',
'file_delete_error' => 'The file was unable to be deleted',
'file_missing' => 'The file selected is missing',
'header_row_has_malformed_characters' => 'One or more attributes in the header row contain malformed UTF-8 characters',
'content_row_has_malformed_characters' => 'One or more attributes in the first row of content contain malformed UTF-8 characters',
],

View file

@ -303,6 +303,7 @@
};
data.process().done( function () {data.submit();});
@this.progress = 0;
@this.clearMessage();
},
progress: function(e, data) {
@this.progress = parseInt((data.loaded / data.total * 100, 10));