From 0a085af0a0affd586cceab02e8ca1b2c5e0b9d43 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Thu, 13 Jan 2022 01:19:13 -0800 Subject: [PATCH 01/35] Getting the basic wiring of the importer over into Livewire WIP: Wiring up more and more of the actions on the importer Files now upload okay, a little glitchy on the display-side though add to readmes so i dont forget --- FIXME.txt | 11 + app/Http/Controllers/ImportsController.php | 4 +- app/Http/Livewire/Importer.php | 45 +++ app/Http/Livewire/ImporterFile.php | 151 ++++++++ app/Models/Setting.php | 3 +- resources/assets/js/components/alert.vue | 36 -- .../components/importer/importer-errors.vue | 42 --- .../js/components/importer/importer-file.vue | 325 ------------------ .../js/components/importer/importer.vue | 130 ------- resources/assets/js/vue.js | 9 +- resources/views/importer/import.blade.php | 104 +----- .../views/livewire/importer-file.blade.php | 207 +++++++++++ resources/views/livewire/importer.blade.php | 212 ++++++++++++ 13 files changed, 641 insertions(+), 638 deletions(-) create mode 100644 FIXME.txt create mode 100644 app/Http/Livewire/Importer.php create mode 100644 app/Http/Livewire/ImporterFile.php delete mode 100644 resources/assets/js/components/alert.vue delete mode 100644 resources/assets/js/components/importer/importer-errors.vue delete mode 100644 resources/assets/js/components/importer/importer-file.vue delete mode 100644 resources/assets/js/components/importer/importer.vue create mode 100644 resources/views/livewire/importer-file.blade.php create mode 100644 resources/views/livewire/importer.blade.php diff --git a/FIXME.txt b/FIXME.txt new file mode 100644 index 000000000..8f95bcb81 --- /dev/null +++ b/FIXME.txt @@ -0,0 +1,11 @@ +remove Ziggy +and ziggy-js too +And what is /public/js/snipeit.js ? That looks like a generated file + +The 'flash' (forced refresh/fake refresh) on uploads is dumb +I'm not sure if the order on the uploaded files is right? +The Livewire.first() thing is still dumb (but Id o'nt know that we can fix it). + +Deletes need to work (I got this working before using $.ajax; it's not even hard) + +Then mapping and so on. \ No newline at end of file diff --git a/app/Http/Controllers/ImportsController.php b/app/Http/Controllers/ImportsController.php index 5c2ca6175..342203846 100644 --- a/app/Http/Controllers/ImportsController.php +++ b/app/Http/Controllers/ImportsController.php @@ -15,8 +15,8 @@ class ImportsController extends Controller public function index() { $this->authorize('import'); - $imports = (new ImportsTransformer)->transformImports(Import::latest()->get()); + // $imports = (new ImportsTransformer)->transformImports(Import::latest()->get()); - return view('importer/import')->with('imports', $imports); + return view('importer/import'); //->with('imports', $imports); } } diff --git a/app/Http/Livewire/Importer.php b/app/Http/Livewire/Importer.php new file mode 100644 index 000000000..1bcd501ba --- /dev/null +++ b/app/Http/Livewire/Importer.php @@ -0,0 +1,45 @@ + 'required|string', + 'files.*.created_at' => 'required|string', + 'files.*.filesize' => 'required|integer' + ]; + + public function mount() + { + //$this->files = Import::all(); // this *SHOULD* be how it works, but...it doesn't? + $this->forcerefresh = 0; + } + + public function test() + { + Log::error("Test Button Clicked!!!!"); + } + + public function toggleEvent($id) + { + Log::error("toggled on: ".$id); + $this->processDetails = Import::find($id); + } + + public function render() + { + $this->files = Import::all(); //HACK - slows down renders. + return view('livewire.importer'); + } +} diff --git a/app/Http/Livewire/ImporterFile.php b/app/Http/Livewire/ImporterFile.php new file mode 100644 index 000000000..552db9837 --- /dev/null +++ b/app/Http/Livewire/ImporterFile.php @@ -0,0 +1,151 @@ + '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', +]; + +$accessories = [ + 'model_number' => 'Model Number', +]; + +$assets = [ + 'asset_tag' => 'Asset Tag', + 'asset_model' => 'Model Name', + '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', +]; + +$consumables = [ + 'item_no' => "Item Number", + 'model_number' => "Model Number", + 'min_amt' => "Minimum Quantity", +]; + +$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', +]; + +$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', +]; + +class ImporterFile extends Component +{ + public $activeFile; //should this get auto-filled? + public $customFields; + public $importTypes; + public $columnOptions; + public $importType; // too similar to 'TypeS'? + + private function getColumns($type) + { + global $general, $accessories, $assets, $consumables, $licenses, $users; + + $customFields = []; + foreach($this->customFields AS $field) { + $customFields[$field->id] = $field->name; + } + + switch($type) { + case 'asset': + $results = $general + $assets + $customFields; + break; + case 'accessory': + $results = $general + $accessories; + break; + case 'consumable': + $results = $general + $consumables; + break; + case 'license': + $results = $general + $licenses; + break; + case 'user': + $results = $general + $users; + break; + default: + $results = $general; + } + asort($results); // FIXME - this isn't sorting right yet. + return $results; + } + + public function mount() + { + $this->customFields = CustomField::all(); + + $this->importTypes = [ + 'asset' => 'Assets', // TODO - translate! + 'accessory' => 'Accessories', + 'consumable' => 'Consumables', + 'component' => 'Components', + 'license' => 'Licenses', + 'user' => 'Users' + ]; + Log::error("import types: ".print_r($this->importTypes,true)); + + $columnOptions = []; + $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); + } + } + + public function changeTypes() + { + Log::error("type changed!"); + } + + public function render() + { + return view('livewire.importer-file'); + } +} diff --git a/app/Models/Setting.php b/app/Models/Setting.php index fd02992f7..b0b4f2490 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -217,7 +217,7 @@ class Setting extends Model * * @author Mogilev Arseny */ - public static function fileSizeConvert($bytes): string + public static function fileSizeConvert(int $bytes): string { $result = 0; $bytes = floatval($bytes); @@ -244,6 +244,7 @@ class Setting extends Model ], ]; + $result = $bytes; // handles the zero case foreach ($arBytes as $arItem) { if ($bytes >= $arItem['VALUE']) { $result = $bytes / $arItem['VALUE']; diff --git a/resources/assets/js/components/alert.vue b/resources/assets/js/components/alert.vue deleted file mode 100644 index 1a2033465..000000000 --- a/resources/assets/js/components/alert.vue +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - diff --git a/resources/assets/js/components/importer/importer-errors.vue b/resources/assets/js/components/importer/importer-errors.vue deleted file mode 100644 index adc6841d4..000000000 --- a/resources/assets/js/components/importer/importer-errors.vue +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - diff --git a/resources/assets/js/components/importer/importer-file.vue b/resources/assets/js/components/importer/importer-file.vue deleted file mode 100644 index eeeed7c72..000000000 --- a/resources/assets/js/components/importer/importer-file.vue +++ /dev/null @@ -1,325 +0,0 @@ - - - diff --git a/resources/assets/js/components/importer/importer.vue b/resources/assets/js/components/importer/importer.vue deleted file mode 100644 index 474f8f145..000000000 --- a/resources/assets/js/components/importer/importer.vue +++ /dev/null @@ -1,130 +0,0 @@ - - - diff --git a/resources/assets/js/vue.js b/resources/assets/js/vue.js index 65cd4393c..a5b903e51 100644 --- a/resources/assets/js/vue.js +++ b/resources/assets/js/vue.js @@ -26,10 +26,11 @@ Vue.component( require('./components/passport/PersonalAccessTokens.vue').default ); -Vue.component( - 'importer', - require('./components/importer/importer.vue').default -); +// This component has been removed and replaced with a Livewire implementation +// Vue.component( +// 'importer', +// require('./components/importer/importer.vue').default +// ); // This component has been removed and replaced with a Livewire implementation // Vue.component( diff --git a/resources/views/importer/import.blade.php b/resources/views/importer/import.blade.php index 950f4d73f..0ec213753 100644 --- a/resources/views/importer/import.blade.php +++ b/resources/views/importer/import.blade.php @@ -9,112 +9,20 @@ {{-- Page content --}} @section('content') {{-- Hide importer until vue has rendered it, if we continue using vue for other things we should move this higher in the style --}} - - -
- -
- @{{ alert.message }} - - -
-
-
-
- -
- -
-
-
- @{{ progress.statusText }} -
-
-
- -
- - - @if (!config('app.lock_passwords')) - - {{ trans('button.select_file') }} - - - - - @endif - -
- -
- - - -
-
-
- - - - - - - - - - - -
{{ trans('general.file_name') }}{{ trans('general.created_at') }}{{ trans('general.filesize') }}{{ trans('general.actions') }}
-
-
-
-
-
-
-

{{ trans('general.importing') }}

-

{!! trans('general.importing_help') !!}

-
- -
-
-
+THIS IS VUE STUFF ISNT IT? + --}} +@livewire('importer') {{-- Yes, this is stupid - we should be able to route straight over and not have this, but Livewire doesn't work in this app that way :/ --}} @stop @section('moar_scripts') - + --}} @endsection diff --git a/resources/views/livewire/importer-file.blade.php b/resources/views/livewire/importer-file.blade.php new file mode 100644 index 000000000..3218648fe --- /dev/null +++ b/resources/views/livewire/importer-file.blade.php @@ -0,0 +1,207 @@ +{{-- --}} diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php new file mode 100644 index 000000000..f998d6363 --- /dev/null +++ b/resources/views/livewire/importer.blade.php @@ -0,0 +1,212 @@ +
+ {{-- --}} {{-- like, this, here, that's a literal Vue directive --}} +
+ {{-- @{{ alert.message }} --}} + + +{{-- alert --}} + + + + {{-- errors thing that's built-in maybe? --}} + {{-- --}} + +
+
+
+
+ +
+ + + +
+ + + @if (!config('app.lock_passwords')) + + {{ trans('admin/importer/general.select_import_file') }} + + + + + @endif + +
+ +
+ + + +
+
+
+
+ + + + + + + + + + + {{-- --}} +
{{ trans('admin/importer/table.file') }}{{ trans('admin/importer/table.created') }}{{ trans('admin/importer/table.size') }}{{ trans('admin/importer/table.process') }}{{ trans('admin/importer/table.delete') }}
+
+
+
+
+
+
+

{{ trans('general.importing') }}

+

{!! trans('general.importing_help') !!}

+
+ +
+ {{--
--}} +
+@push('js') + +@endpush \ No newline at end of file From 8009ee79db0599bf762c59876bd78b2c65739c80 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Mon, 19 Sep 2022 21:04:46 -0700 Subject: [PATCH 02/35] I think I have, now, full parity on the base Importer level Meaning that you can upload new files, delete old files, have error messages, have status updates - and all of them seem to work. --- FIXME.txt | 18 +++-- app/Http/Livewire/Importer.php | 37 ++++++++-- resources/views/livewire/importer.blade.php | 82 +++++++++++++-------- 3 files changed, 93 insertions(+), 44 deletions(-) diff --git a/FIXME.txt b/FIXME.txt index 8f95bcb81..1a644d9b5 100644 --- a/FIXME.txt +++ b/FIXME.txt @@ -1,11 +1,15 @@ -remove Ziggy -and ziggy-js too -And what is /public/js/snipeit.js ? That looks like a generated file +X - remove Ziggy +X - and ziggy-js too +X - And what is /public/js/snipeit.js ? That looks like a generated file The 'flash' (forced refresh/fake refresh) on uploads is dumb -I'm not sure if the order on the uploaded files is right? -The Livewire.first() thing is still dumb (but Id o'nt know that we can fix it). +X - the order on the uploaded files is wrong (backwards) +X - (fixed somehow?!) The Livewire.first() thing is still dumb (but Id o'nt know that we can fix it). -Deletes need to work (I got this working before using $.ajax; it's not even hard) +X - Deletes need to work (I got this working before using $.ajax; it's not even hard) -Then mapping and so on. \ No newline at end of file +Then mapping and so on. + +Can we potentially delete whatever that this.$http thing? Or is that some side-effect of Vue.js that we don't get for free? (yes, it was that) + +I suspect the Alert section is not yet wired up - but should be. Doesn't seem too hard? \ No newline at end of file diff --git a/app/Http/Livewire/Importer.php b/app/Http/Livewire/Importer.php index 1bcd501ba..32f0d5035 100644 --- a/app/Http/Livewire/Importer.php +++ b/app/Http/Livewire/Importer.php @@ -5,6 +5,7 @@ namespace App\Http\Livewire; use Livewire\Component; use App\Models\Import; +use Storage; use Log; @@ -14,6 +15,13 @@ class Importer extends Component public $processDetails; public $forcerefresh; + 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? + protected $rules = [ 'files.*.file_path' => 'required|string', 'files.*.created_at' => 'required|string', @@ -22,13 +30,15 @@ class Importer extends Component public function mount() { - //$this->files = Import::all(); // this *SHOULD* be how it works, but...it doesn't? - $this->forcerefresh = 0; + //$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'; } - public function test() + public function hideMessages() { - Log::error("Test Button Clicked!!!!"); + $this->message=''; } public function toggleEvent($id) @@ -37,9 +47,26 @@ class Importer extends Component $this->processDetails = Import::find($id); } + 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? + } + } + } + public function render() { - $this->files = Import::all(); //HACK - slows down renders. + $this->files = Import::orderBy('id','desc')->get(); //HACK - slows down renders. return view('livewire.importer'); } } diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index f998d6363..8a2b3832e 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -32,16 +32,18 @@ {{-- alert --}} - + +@endif @endpush \ No newline at end of file From 5c97e45d00ab490ee6cba2bfb70c1c06d3d4c599 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Tue, 27 Sep 2022 16:37:39 -0700 Subject: [PATCH 03/35] WIP - trying to get select2 wired up for importer --- .../views/livewire/importer-file.blade.php | 16 ++++++++++++- resources/views/livewire/importer.blade.php | 23 +------------------ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/resources/views/livewire/importer-file.blade.php b/resources/views/livewire/importer-file.blade.php index 3218648fe..e2e3440fb 100644 --- a/resources/views/livewire/importer-file.blade.php +++ b/resources/views/livewire/importer-file.blade.php @@ -10,7 +10,9 @@
- {{ Form::select('importType', $importTypes, 0 /* FIXME whats' the old value? */, ['placeholder' => '', 'wire:model' => 'importType', 'wire:change' => 'changeTypes']) }} + + {{ Form::select('importType', $importTypes, 0 /* FIXME whats' the old value? */, ['class' => 'livewire-select2', 'placeholder' => '', 'data-livewire-model' => 'importType']) }} + {{-- --}} {{-- --}} {{-- --}} @@ -205,3 +207,15 @@ {{-- --}} + \ No newline at end of file diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index 8a2b3832e..ccef721b2 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -2,7 +2,7 @@ {{-- --}} {{-- like, this, here, that's a literal Vue directive --}}
{{-- @{{ alert.message }} --}} -