From 804a788a27535a57662dac8e660749d60e53ae6c Mon Sep 17 00:00:00 2001 From: slong753 Date: Tue, 28 Mar 2023 20:31:24 -0500 Subject: [PATCH 01/38] initial fetch working --- .../Controllers/Assets/BulkAssetsController.php | 15 ++++++++++++++- resources/views/hardware/bulk.blade.php | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 7f9e812ab4..f0f01c6577 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -13,6 +13,8 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Session; use App\Http\Requests\AssetCheckoutRequest; +use App\Models\CustomField; +use Illuminate\Support\Collection; class BulkAssetsController extends Controller { @@ -40,6 +42,16 @@ class BulkAssetsController extends Controller session(['bulk_back_url' => $bulk_back_url]); $asset_ids = array_values(array_unique($request->input('ids'))); + + //custom fields logic for bulk edit + $asset_custom_field = Asset::whereIn('id', $asset_ids)->whereHas('model', function ($query) { + return $query->where('fieldset_id', '!=', null); + })->get(); + $custom_fields = new Collection(); + foreach ($asset_custom_field as $asset_key => $asset) { + $custom_fields->push($asset->model->fieldset->fields); + } + $custom_fields = $custom_fields->flatten()->unique('id'); if ($request->filled('bulk_actions')) { switch ($request->input('bulk_actions')) { @@ -59,7 +71,8 @@ class BulkAssetsController extends Controller case 'edit': return view('hardware/bulk') ->with('assets', $asset_ids) - ->with('statuslabel_list', Helper::statusLabelList()); + ->with('statuslabel_list', Helper::statusLabelList()) + ->with('custom_fields', $custom_fields); } } diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index 1cacc4086f..76299871c3 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -28,6 +28,8 @@
+ +
@@ -181,6 +183,16 @@
+ @foreach ($custom_fields as $key => $value) +

+ +

+ @endforeach + + + @foreach ($assets as $key => $value) @endforeach From 032ae4348e64172d163c65298359601a737deb05 Mon Sep 17 00:00:00 2001 From: slong753 Date: Tue, 28 Mar 2023 21:45:31 -0500 Subject: [PATCH 02/38] custom fields display, need to get saving +some clean up --- .../Controllers/Assets/BulkAssetsController.php | 7 ++++++- resources/views/hardware/bulk.blade.php | 15 +++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index f0f01c6577..42c0f96d4c 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -47,6 +47,10 @@ class BulkAssetsController extends Controller $asset_custom_field = Asset::whereIn('id', $asset_ids)->whereHas('model', function ($query) { return $query->where('fieldset_id', '!=', null); })->get(); + + $models1 = $asset_custom_field->unique('model_id'); + $models = $models1->pluck('model'); + $custom_fields = new Collection(); foreach ($asset_custom_field as $asset_key => $asset) { $custom_fields->push($asset->model->fieldset->fields); @@ -72,7 +76,8 @@ class BulkAssetsController extends Controller return view('hardware/bulk') ->with('assets', $asset_ids) ->with('statuslabel_list', Helper::statusLabelList()) - ->with('custom_fields', $custom_fields); + ->with('custom_fields', $custom_fields) + ->with('models', $models); } } diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index 76299871c3..eefa247602 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -183,13 +183,20 @@
- @foreach ($custom_fields as $key => $value) -

+ {{-- @foreach ($custom_fields as $key => $value) +

-

- @endforeach +

+ @endforeach --}} + + @foreach ($models as $model) + + @include("models/custom_fields_form",["model" => $model]) + @endforeach From 65bbecd145524ca9e5a23b6f7e7d8dac9fee886e Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 29 Mar 2023 14:46:31 -0500 Subject: [PATCH 03/38] this all works - could use some eyes --- .../Assets/BulkAssetsController.php | 45 ++++++++++++++----- resources/views/hardware/bulk.blade.php | 5 ++- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 42c0f96d4c..98494fcb76 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -48,8 +48,7 @@ class BulkAssetsController extends Controller return $query->where('fieldset_id', '!=', null); })->get(); - $models1 = $asset_custom_field->unique('model_id'); - $models = $models1->pluck('model'); + $models = $asset_custom_field->unique('model_id')->pluck('model'); $custom_fields = new Collection(); foreach ($asset_custom_field as $asset_key => $asset) { @@ -103,12 +102,19 @@ class BulkAssetsController extends Controller } + $custom_field_columns = CustomField::all()->pluck('db_column')->toArray(); + if (! $request->filled('ids') || count($request->input('ids')) <= 0) { return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected')); } $assets = array_keys($request->input('ids')); - + + if ($request->anyFilled($custom_field_columns)) { + $custom_fields_present = true; + } else { + $custom_fields_present = false; + } if (($request->filled('purchase_date')) || ($request->filled('expected_checkin')) || ($request->filled('purchase_cost')) @@ -124,6 +130,7 @@ class BulkAssetsController extends Controller || ($request->filled('null_purchase_date')) || ($request->filled('null_expected_checkin_date')) || ($request->filled('null_next_audit_date')) + || ($request->anyFilled($custom_field_columns)) ) { foreach ($assets as $assetId) { @@ -139,6 +146,9 @@ class BulkAssetsController extends Controller ->conditionallyAddItem('supplier_id') ->conditionallyAddItem('warranty_months') ->conditionallyAddItem('next_audit_date'); + foreach ($custom_field_columns as $key => $custom_field_column) { + $this->conditionallyAddItem($custom_field_column); + } if ($request->input('null_purchase_date')=='1') { $this->update_array['purchase_date'] = null; @@ -187,17 +197,28 @@ class BulkAssetsController extends Controller $logAction->user_id = Auth::id(); $logAction->log_meta = json_encode($changed); $logAction->logaction('update'); - - DB::table('assets') - ->where('id', $assetId) - ->update($this->update_array); - } // endforeach - + + if($custom_fields_present) { + $asset = Asset::find($assetId); + $assetCustomFields = $asset->model()->first()->fieldset; + foreach ($assetCustomFields->fields as $field) { + if (array_key_exists($field->db_column, $this->update_array)) { + $asset->{$field->db_column} = $this->update_array[$field->db_column]; + $asset->save(); + continue; + } else { + $array = $this->update_array; + array_except($array, $field->db_column); + $asset->update($array); + $asset->save(); + } + } + } else { + Asset::find($assetId)->update($this->update_array); + } + } // endforeach ($assets) return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success')); - - } - // no values given, nothing to update return redirect($bulk_back_url)->with('warning', trans('admin/hardware/message.update.nothing_updated')); } diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index eefa247602..c1283c1e02 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -21,6 +21,9 @@
{{ trans_choice('admin/hardware/form.bulk_update_warn', count($assets), ['asset_count' => count($assets)]) }} + @if (count($models) > 0) + made up of {{count($models)}} models + @endif
@@ -192,7 +195,7 @@ @endforeach --}} @foreach ($models as $model) - --}} + {{-- @include("models/custom_fields_form",["model" => $model]) --}} + @include("models/custom_fields_form_bulk_edit",["models" => $models]) + {{-- @endforeach --}} @foreach ($assets as $key => $value) diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php new file mode 100644 index 0000000000..d94a261281 --- /dev/null +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -0,0 +1,119 @@ +@php +$fields = []; +@endphp +@foreach($models as $model) +
{{$model->name}}
+ +@if (($model) && ($model->fieldset)) + @foreach($model->fieldset->fields AS $field) + {{-- if field has already been displayed, skip --}} + {{-- @php + if (in_array($field->db_column_name(), $fields)) { + $duplicate = true; + ray($field->db_column_name() . ' is a duplicate'); + continue; + } else { + $duplicate = false; + } + $fields[] = $field->db_column_name(); + ray($fields); + @endphp --}} + + +
+ + {{--hmmm, this doesn't make sense, duh. + need to determine duplicates _before_ any rendering --}} + {{-- @if($duplicate) --}} + {{--

On Models: {{$model->name}}

--}} + {{-- @endif --}} +
+ + + @if ($field->element!='text') + + @if ($field->element=='listbox') + {{ Form::select($field->db_column_name(), $field->formatFieldValuesAsArray(), + Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} + + @elseif ($field->element=='textarea') + + + @elseif ($field->element=='checkbox') + + @foreach ($field->formatFieldValuesAsArray() as $key => $value) +
+ +
+ @endforeach + + @elseif ($field->element=='radio') + @foreach ($field->formatFieldValuesAsArray() as $value) + +
+ +
+ @endforeach + + @endif + + + @else + + + @if ($field->format=='DATE') + +
+
+ + +
+
+ + + @else + @if (($field->field_encrypted=='0') || (Gate::allows('admin'))) + + @else + + @endif + @endif + + @endif + + @if ($field->help_text!='') +

{{ $field->help_text }}

+ @endif + + @if($duplicate) +

This custom field is present on multiple models

+ @endif + + + + first($field->db_column_name()); + if ($errormessage) { + $errormessage=preg_replace('/ snipeit /', '', $errormessage); + print(''); + } + ?> +
+ + @if ($field->field_encrypted) +
+ +
+ @endif + + +
+ @endforeach +@endif + @endforeach From 3929526a570aed663ca9eb00d8633a62de7c98eb Mon Sep 17 00:00:00 2001 From: slong753 Date: Tue, 4 Apr 2023 18:57:51 -0500 Subject: [PATCH 06/38] ok, this works but needs to be tested more --- app/Models/AssetModel.php | 5 +++ app/Models/CustomField.php | 5 +++ resources/views/hardware/bulk.blade.php | 4 +- .../views/models/custom_fields_form.blade.php | 9 ++++ .../custom_fields_form_bulk_edit.blade.php | 42 +++++++++---------- 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/app/Models/AssetModel.php b/app/Models/AssetModel.php index e4e5ac720a..aed1b925ef 100755 --- a/app/Models/AssetModel.php +++ b/app/Models/AssetModel.php @@ -150,6 +150,11 @@ class AssetModel extends SnipeModel { return $this->belongsTo(\App\Models\CustomFieldset::class, 'fieldset_id'); } + + public function customFields() + { + return $this->fieldset()->first()->fields(); + } /** * Establishes the model -> custom field default values relationship diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index fcab5b25ff..ea62c4fa65 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -177,6 +177,11 @@ class CustomField extends Model { return $this->belongsToMany(\App\Models\CustomFieldset::class); } + + public function assetModels() + { + return $this->fieldset()->with('models')->get()->pluck('models')->flatten()->unique('id'); + } /** * Establishes the customfield -> admin user relationship diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index 53f8ab1d80..95e2d250ee 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -187,8 +187,8 @@ {{-- @foreach ($models as $model) --}} - {{-- @include("models/custom_fields_form",["model" => $model]) --}} + + @include("models/custom_fields_form",["model" => $model]) --}} @include("models/custom_fields_form_bulk_edit",["models" => $models]) {{-- @endforeach --}} diff --git a/resources/views/models/custom_fields_form.blade.php b/resources/views/models/custom_fields_form.blade.php index f73a93903f..e63aa3d272 100644 --- a/resources/views/models/custom_fields_form.blade.php +++ b/resources/views/models/custom_fields_form.blade.php @@ -1,3 +1,12 @@ +@php + $fields = []; + foreach($model->fieldset->fields AS $field) { + $fields[] = $field->db_column_name(); + } + ray($fields); + $duplicates = array_diff_assoc($fields, array_unique($fields)); + ray($duplicates); +@endphp @if (($model) && ($model->fieldset)) @foreach($model->fieldset->fields AS $field)
diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index d94a261281..97b32d1134 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -1,32 +1,28 @@ @php $fields = []; +$modelNames = []; +foreach($models as $model) { + $modelNames[] = $model->name; +} + @endphp @foreach($models as $model) -
{{$model->name}}
- + @if (($model) && ($model->fieldset)) - @foreach($model->fieldset->fields AS $field) - {{-- if field has already been displayed, skip --}} - {{-- @php + @foreach($model->customFields AS $field) + @php if (in_array($field->db_column_name(), $fields)) { $duplicate = true; - ray($field->db_column_name() . ' is a duplicate'); continue; } else { $duplicate = false; } - $fields[] = $field->db_column_name(); - ray($fields); - @endphp --}} - + $fields[] = $field->db_column_name(); +@endphp +
- {{--hmmm, this doesn't make sense, duh. - need to determine duplicates _before_ any rendering --}} - {{-- @if($duplicate) --}} - {{--

On Models: {{$model->name}}

--}} - {{-- @endif --}}
@@ -87,13 +83,17 @@ $fields = []; @endif - @if ($field->help_text!='') -

{{ $field->help_text }}

- @endif + @if ($field->help_text!='') +

{{ $field->help_text }}

+ @endif + + + @foreach($field->assetModels() as $assetModel) + @if(in_array($assetModel->name, $modelNames)) +

{{$assetModel->name}}

+ @endif + @endforeach - @if($duplicate) -

This custom field is present on multiple models

- @endif From d56a4e717332de2c22b3e2837977065b4b789483 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 5 Apr 2023 15:16:46 -0500 Subject: [PATCH 07/38] cleanup+formatting --- .../custom_fields_form_bulk_edit.blade.php | 66 +++++++++---------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index 97b32d1134..c0c26db1cc 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -1,26 +1,24 @@ @php -$fields = []; -$modelNames = []; -foreach($models as $model) { - $modelNames[] = $model->name; -} - + $fields = []; + $modelNames = []; + foreach($models as $model) { + $modelNames[] = $model->name; + } @endphp @foreach($models as $model) - @if (($model) && ($model->fieldset)) - @foreach($model->customFields AS $field) - @php - if (in_array($field->db_column_name(), $fields)) { - $duplicate = true; - continue; - } else { - $duplicate = false; - } - $fields[] = $field->db_column_name(); + @foreach($model->customFields AS $field) + +@php + if (in_array($field->db_column_name(), $fields)) { + $duplicate = true; + continue; + } else { + $duplicate = false; + } + $fields[] = $field->db_column_name(); @endphp -
@@ -29,12 +27,11 @@ foreach($models as $model) { @if ($field->element!='text') @if ($field->element=='listbox') - {{ Form::select($field->db_column_name(), $field->formatFieldValuesAsArray(), + {{ Form::select($field->db_column_name(), $field->formatFieldValuesAsArray(), Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} @elseif ($field->element=='textarea') - @elseif ($field->element=='checkbox') @foreach ($field->formatFieldValuesAsArray() as $key => $value) @@ -45,32 +42,29 @@ foreach($models as $model) {
@endforeach - - @elseif ($field->element=='radio') - @foreach ($field->formatFieldValuesAsArray() as $value) - + @elseif ($field->element=='radio') + @foreach ($field->formatFieldValuesAsArray() as $value)
- @endforeach + @endforeach - @endif + @endif - - @else + @else - @if ($field->format=='DATE') + @if ($field->format=='DATE') -
-
- - -
-
+
+
+ + +
+
@else @@ -88,11 +82,13 @@ foreach($models as $model) { @endif +

On Models: @foreach($field->assetModels() as $assetModel) @if(in_array($assetModel->name, $modelNames)) -

{{$assetModel->name}}

+ {{$assetModel->name}}{{($loop->last) ? '' : ', '}} @endif @endforeach +

From 830e3e55947306850855b31e73b274058c0e9a68 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 5 Apr 2023 15:27:28 -0500 Subject: [PATCH 08/38] cleanup --- resources/views/hardware/bulk.blade.php | 6 ------ resources/views/models/custom_fields_form.blade.php | 9 --------- 2 files changed, 15 deletions(-) diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index 95e2d250ee..dfbbf6df0b 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -184,13 +184,7 @@
- {{-- @foreach ($models as $model) - - @include("models/custom_fields_form",["model" => $model]) --}} @include("models/custom_fields_form_bulk_edit",["models" => $models]) - {{-- @endforeach --}} @foreach ($assets as $key => $value) diff --git a/resources/views/models/custom_fields_form.blade.php b/resources/views/models/custom_fields_form.blade.php index e63aa3d272..f73a93903f 100644 --- a/resources/views/models/custom_fields_form.blade.php +++ b/resources/views/models/custom_fields_form.blade.php @@ -1,12 +1,3 @@ -@php - $fields = []; - foreach($model->fieldset->fields AS $field) { - $fields[] = $field->db_column_name(); - } - ray($fields); - $duplicates = array_diff_assoc($fields, array_unique($fields)); - ray($duplicates); -@endphp @if (($model) && ($model->fieldset)) @foreach($model->fieldset->fields AS $field)
From 8b9aea8874070d3fff237f3fad2dafc6cdd017f3 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 12 Apr 2023 14:46:48 -0500 Subject: [PATCH 09/38] very much WIP, but dupe queries reduced but i think this can be cleaned up a bit more --- .../Assets/BulkAssetsController.php | 20 ++++++++++--------- app/Models/CustomField.php | 4 +++- .../custom_fields_form_bulk_edit.blade.php | 20 +++++++++---------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 98494fcb76..8a32dc3e44 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -44,17 +44,19 @@ class BulkAssetsController extends Controller $asset_ids = array_values(array_unique($request->input('ids'))); //custom fields logic for bulk edit - $asset_custom_field = Asset::whereIn('id', $asset_ids)->whereHas('model', function ($query) { + $asset_custom_field = Asset::with('model.fieldset.fields')->whereIn('id', $asset_ids)->whereHas('model', function ($query) { return $query->where('fieldset_id', '!=', null); })->get(); - $models = $asset_custom_field->unique('model_id')->pluck('model'); + $models = $asset_custom_field->unique('model_id'); - $custom_fields = new Collection(); - foreach ($asset_custom_field as $asset_key => $asset) { - $custom_fields->push($asset->model->fieldset->fields); - } - $custom_fields = $custom_fields->flatten()->unique('id'); + ray($asset_custom_field); + ray($models); + // $custom_fields = new Collection(); + // foreach ($models as $asset_key => $asset) { + // $custom_fields->push($asset->model->customFields); + // } + $custom_fields = $asset_custom_field->pluck('model.fieldset.fields')->flatten()->unique('id'); if ($request->filled('bulk_actions')) { switch ($request->input('bulk_actions')) { @@ -75,8 +77,8 @@ class BulkAssetsController extends Controller return view('hardware/bulk') ->with('assets', $asset_ids) ->with('statuslabel_list', Helper::statusLabelList()) - ->with('custom_fields', $custom_fields) - ->with('models', $models); + // ->with('custom_fields', $custom_fields) + ->with('models', $models->pluck('model')); } } diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index ea62c4fa65..46a33548dd 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Validation\Rule; use Schema; use Watson\Validating\ValidatingTrait; - +// use App\Models\SnipeModel; class CustomField extends Model { use HasFactory; @@ -181,6 +181,8 @@ class CustomField extends Model public function assetModels() { return $this->fieldset()->with('models')->get()->pluck('models')->flatten()->unique('id'); + + // return $this->models->where(, AssetModel::class); } /** diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index c0c26db1cc..c932c0be41 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -7,17 +7,17 @@ @endphp @foreach($models as $model) @if (($model) && ($model->fieldset)) - @foreach($model->customFields AS $field) + @foreach($model->fieldset->fields AS $field) -@php - if (in_array($field->db_column_name(), $fields)) { - $duplicate = true; - continue; - } else { - $duplicate = false; - } - $fields[] = $field->db_column_name(); -@endphp + @php + if (in_array($field->db_column_name(), $fields)) { + $duplicate = true; + continue; + } else { + $duplicate = false; + } + $fields[] = $field->db_column_name(); + @endphp
From 52dc99588e2757b4c0b8729757fc52794b0a689b Mon Sep 17 00:00:00 2001 From: slong753 Date: Mon, 17 Apr 2023 13:57:48 -0500 Subject: [PATCH 10/38] pushing for now, needs validation work --- .../Assets/BulkAssetsController.php | 7 ++++- app/Models/CustomField.php | 2 -- .../custom_fields_form_bulk_edit.blade.php | 26 +++++++++---------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 8a32dc3e44..f3c65541da 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -49,6 +49,10 @@ class BulkAssetsController extends Controller })->get(); $models = $asset_custom_field->unique('model_id'); + $modelNames = []; + foreach($models as $model) { + $modelNames[] = $model->name; + } ray($asset_custom_field); ray($models); @@ -78,7 +82,8 @@ class BulkAssetsController extends Controller ->with('assets', $asset_ids) ->with('statuslabel_list', Helper::statusLabelList()) // ->with('custom_fields', $custom_fields) - ->with('models', $models->pluck('model')); + ->with('models', $models->pluck('model')) + ->with('modelNames', $modelNames); } } diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index 46a33548dd..55738cd034 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -181,8 +181,6 @@ class CustomField extends Model public function assetModels() { return $this->fieldset()->with('models')->get()->pluck('models')->flatten()->unique('id'); - - // return $this->models->where(, AssetModel::class); } /** diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index c932c0be41..123472830c 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -1,23 +1,21 @@ @php +//set array up before loop so it doesn't get wiped at every iteration $fields = []; - $modelNames = []; - foreach($models as $model) { - $modelNames[] = $model->name; - } @endphp @foreach($models as $model) @if (($model) && ($model->fieldset)) @foreach($model->fieldset->fields AS $field) - - @php - if (in_array($field->db_column_name(), $fields)) { - $duplicate = true; - continue; - } else { - $duplicate = false; - } - $fields[] = $field->db_column_name(); - @endphp + @php + //prevents some duplicate queries - open to a better way of skipping dupes in output + //its ugly, but if we'd rather deal with duplicate queries we can get rid of this. + if (in_array($field->db_column_name(), $fields)) { + $duplicate = true; + continue; + } else { + $duplicate = false; + } + $fields[] = $field->db_column_name(); + @endphp
From 6bec9cf88035615a4601051165cf3b2099c229e4 Mon Sep 17 00:00:00 2001 From: slong753 Date: Tue, 25 Apr 2023 23:26:16 -0500 Subject: [PATCH 11/38] fix a couple things --- .../Assets/BulkAssetsController.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index f3c65541da..e8e9cc43b8 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -43,19 +43,17 @@ class BulkAssetsController extends Controller $asset_ids = array_values(array_unique($request->input('ids'))); - //custom fields logic for bulk edit - $asset_custom_field = Asset::with('model.fieldset.fields')->whereIn('id', $asset_ids)->whereHas('model', function ($query) { + //custom fields logic + $asset_custom_field = Asset::with(['model.fieldset.fields', 'model'])->whereIn('id', $asset_ids)->whereHas('model', function ($query) { return $query->where('fieldset_id', '!=', null); })->get(); $models = $asset_custom_field->unique('model_id'); $modelNames = []; foreach($models as $model) { - $modelNames[] = $model->name; + $modelNames[] = $model->model->name; } - ray($asset_custom_field); - ray($models); // $custom_fields = new Collection(); // foreach ($models as $asset_key => $asset) { // $custom_fields->push($asset->model->customFields); @@ -82,7 +80,7 @@ class BulkAssetsController extends Controller ->with('assets', $asset_ids) ->with('statuslabel_list', Helper::statusLabelList()) // ->with('custom_fields', $custom_fields) - ->with('models', $models->pluck('model')) + ->with('models', $models->pluck(['model'])) ->with('modelNames', $modelNames); } } @@ -101,6 +99,7 @@ class BulkAssetsController extends Controller public function update(Request $request) { $this->authorize('update', Asset::class); + $error_bag = []; // Get the back url from the session and then destroy the session $bulk_back_url = route('hardware.index'); @@ -219,7 +218,14 @@ class BulkAssetsController extends Controller $asset->update($array); $asset->save(); } + if (!$asset->save()) { + $error_bag[] = $asset; + } } + if (!$asset->save()) { + return redirect()->back()->withInput()->withErrors('One of your custom fields is not valid.'); + } + } else { Asset::find($assetId)->update($this->update_array); } From 52c9fefbe015598b6204500da689c8b3e62e4ae5 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 26 Apr 2023 15:06:50 -0500 Subject: [PATCH 12/38] ok, this works except error display --- .../Controllers/Assets/BulkAssetsController.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index e8e9cc43b8..9af84d34b8 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -187,11 +187,11 @@ class BulkAssetsController extends Controller } $changed = []; - $asset = Asset::where('id' ,$assetId)->get(); + $assetCollection = Asset::where('id' ,$assetId)->get(); foreach ($this->update_array as $key => $value) { - if ($this->update_array[$key] != $asset->toArray()[0][$key]) { - $changed[$key]['old'] = $asset->toArray()[0][$key]; + if ($this->update_array[$key] != $assetCollection->toArray()[0][$key]) { + $changed[$key]['old'] = $assetCollection->toArray()[0][$key]; $changed[$key]['new'] = $this->update_array[$key]; } } @@ -219,17 +219,16 @@ class BulkAssetsController extends Controller $asset->save(); } if (!$asset->save()) { - $error_bag[] = $asset; + $error_bag[] = $asset->getErrors(); } - } - if (!$asset->save()) { - return redirect()->back()->withInput()->withErrors('One of your custom fields is not valid.'); } - } else { Asset::find($assetId)->update($this->update_array); } } // endforeach ($assets) + if(!empty($error_bag)) { + return redirect($bulk_back_url)->withErrors($error_bag); + } return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success')); } // no values given, nothing to update From b2c2097e8bf91b44207bfdb24ce1046302c0b56c Mon Sep 17 00:00:00 2001 From: slong753 Date: Tue, 2 May 2023 18:54:20 -0500 Subject: [PATCH 13/38] just more troubleshooting stuff, still no solution --- .../Controllers/Assets/BulkAssetsController.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 9af84d34b8..8854463488 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -31,8 +31,10 @@ class BulkAssetsController extends Controller */ public function edit(Request $request) { + // dd($request->all()); + $this->authorize('update', Asset::class); - + if (! $request->filled('ids')) { return redirect()->back()->with('error', trans('admin/hardware/message.update.no_assets_selected')); } @@ -98,6 +100,7 @@ class BulkAssetsController extends Controller */ public function update(Request $request) { + // dd(request()->headers->get('referer')); $this->authorize('update', Asset::class); $error_bag = []; @@ -139,6 +142,7 @@ class BulkAssetsController extends Controller || ($request->anyFilled($custom_field_columns)) ) { + // dd($assets); foreach ($assets as $assetId) { $this->update_array = []; @@ -227,7 +231,14 @@ class BulkAssetsController extends Controller } } // endforeach ($assets) if(!empty($error_bag)) { - return redirect($bulk_back_url)->withErrors($error_bag); + $ids = array_values($assets); + // dd($ids); + return redirect()->back() + ->withInput(["ids" => $ids, "bulk_actions" => "edit"]) + ->withErrors($error_bag); + // return $error_bag; + + // return redirect($bulk_back_url)->withErrors($error_bag); } return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success')); } From cdda4a56d873de4a8966279a1e544ea9da355eb4 Mon Sep 17 00:00:00 2001 From: slong753 Date: Tue, 2 May 2023 19:11:43 -0500 Subject: [PATCH 14/38] aha, ok thisd kind of works --- app/Http/Controllers/Assets/BulkAssetsController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 8854463488..24712da278 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -233,12 +233,12 @@ class BulkAssetsController extends Controller if(!empty($error_bag)) { $ids = array_values($assets); // dd($ids); - return redirect()->back() - ->withInput(["ids" => $ids, "bulk_actions" => "edit"]) - ->withErrors($error_bag); + // return redirect()->back() + // ->withInput(["ids" => $ids, "bulk_actions" => "edit"]) + // ->with('error_messages', $error_bag); // return $error_bag; - // return redirect($bulk_back_url)->withErrors($error_bag); + return redirect($bulk_back_url)->with('error_messages', $error_bag); } return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success')); } From 815c77f9436bf2cc332aeb1e70101ac851e18886 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 3 May 2023 14:49:31 -0500 Subject: [PATCH 15/38] wip --- .../Assets/BulkAssetsController.php | 22 +++++++++++-------- resources/views/notifications.blade.php | 15 +++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 24712da278..1e1e765ea1 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -223,7 +223,7 @@ class BulkAssetsController extends Controller $asset->save(); } if (!$asset->save()) { - $error_bag[] = $asset->getErrors(); + $error_bag[] = $asset->getErrors()->toArray(); } } } else { @@ -231,14 +231,18 @@ class BulkAssetsController extends Controller } } // endforeach ($assets) if(!empty($error_bag)) { - $ids = array_values($assets); - // dd($ids); - // return redirect()->back() - // ->withInput(["ids" => $ids, "bulk_actions" => "edit"]) - // ->with('error_messages', $error_bag); - // return $error_bag; - - return redirect($bulk_back_url)->with('error_messages', $error_bag); + // $errors = collect($error_bag)->unique(); + // foreach ($errors as $key => $value) { + // ray($value->message); + // } + $errors = []; + foreach ($error_bag as $key => $value) { + foreach($value as $key => $value) { + $errors[] = $value; + } + } + ray($errors); + return redirect($bulk_back_url)->with('bulk_errors', $errors); } return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success')); } diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 0935c28582..4599577a1b 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -115,6 +115,21 @@ @endif +@if ($messages = Session::get('bulk_errors')) +
+
+ + + {{ trans('general.notification_error') }} + The following fields had validation errors and were not edited: + @foreach($messages as $message => $value) +
{{ $value. }} + @endforeach +
+
+@endif + + @if ($message = Session::get('warning'))
From 1d2596fc54ff01560cb6a132ad3e1887349a8664 Mon Sep 17 00:00:00 2001 From: slong753 Date: Tue, 9 May 2023 14:58:59 -0500 Subject: [PATCH 16/38] wip --- .../Assets/BulkAssetsController.php | 70 +++++++++++-------- resources/views/notifications.blade.php | 4 +- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 1e1e765ea1..33160f1106 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -16,6 +16,8 @@ use App\Http\Requests\AssetCheckoutRequest; use App\Models\CustomField; use Illuminate\Support\Collection; +use function Amp\Promise\wait; + class BulkAssetsController extends Controller { use CheckInOutRequest; @@ -32,6 +34,7 @@ class BulkAssetsController extends Controller public function edit(Request $request) { // dd($request->all()); + // dd(Session::get('ids')); $this->authorize('update', Asset::class); @@ -52,9 +55,9 @@ class BulkAssetsController extends Controller $models = $asset_custom_field->unique('model_id'); $modelNames = []; - foreach($models as $model) { - $modelNames[] = $model->model->name; - } + foreach($models as $model) { + $modelNames[] = $model->model->name; + } // $custom_fields = new Collection(); // foreach ($models as $asset_key => $asset) { @@ -112,11 +115,13 @@ class BulkAssetsController extends Controller $custom_field_columns = CustomField::all()->pluck('db_column')->toArray(); - - if (! $request->filled('ids') || count($request->input('ids')) <= 0) { + + if(Session::exists('ids')) { + $assets = Session::get('ids'); + } elseif (! $request->filled('ids') || count($request->input('ids')) <= 0) { return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected')); } - + $assets = array_keys($request->input('ids')); if ($request->anyFilled($custom_field_columns)) { @@ -211,38 +216,45 @@ class BulkAssetsController extends Controller if($custom_fields_present) { $asset = Asset::find($assetId); $assetCustomFields = $asset->model()->first()->fieldset; - foreach ($assetCustomFields->fields as $field) { - if (array_key_exists($field->db_column, $this->update_array)) { - $asset->{$field->db_column} = $this->update_array[$field->db_column]; - $asset->save(); - continue; - } else { - $array = $this->update_array; - array_except($array, $field->db_column); - $asset->update($array); - $asset->save(); - } - if (!$asset->save()) { - $error_bag[] = $asset->getErrors()->toArray(); - } - } + if($assetCustomFields?->fields) { + foreach ($assetCustomFields?->fields as $field) { + if (array_key_exists($field->db_column, $this->update_array)) { + $asset->{$field->db_column} = $this->update_array[$field->db_column]; + $asset->save(); + continue; + } else { + $array = $this->update_array; + array_except($array, $field->db_column); + $asset->update($array); + //call update on parent model + $asset->save(); + } + if (!$asset->save()) { + $error_bag[] = $asset->getErrors(); + } + } + } } else { Asset::find($assetId)->update($this->update_array); } } // endforeach ($assets) + ray($error_bag); if(!empty($error_bag)) { // $errors = collect($error_bag)->unique(); // foreach ($errors as $key => $value) { // ray($value->message); // } - $errors = []; - foreach ($error_bag as $key => $value) { - foreach($value as $key => $value) { - $errors[] = $value; - } - } - ray($errors); - return redirect($bulk_back_url)->with('bulk_errors', $errors); + $errors = []; + foreach ($error_bag as $key => $value) { + foreach($value as $key => $value) { + $errors[] = $value; + } + } + ray($error_bag); + Session::save('ids', $assets); + + // return redirect()->route('hardware/bulkedit'); + return redirect()->back()->with('bulk_errors', $errors); } return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success')); } diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 4599577a1b..26f432c3d9 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -115,7 +115,7 @@ @endif -@if ($messages = Session::get('bulk_errors')) +{{-- @if ($messages = Session::get('bulk_errors'))
@@ -127,7 +127,7 @@ @endforeach
-@endif +@endif --}} @if ($message = Session::get('warning')) From 5e34ffa2b090435306dcedb8ddbaa1b9f3fe033c Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 10 May 2023 14:08:12 -0500 Subject: [PATCH 17/38] wip --- .../Assets/BulkAssetsController.php | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 33160f1106..1171cdb8fd 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -216,22 +216,23 @@ class BulkAssetsController extends Controller if($custom_fields_present) { $asset = Asset::find($assetId); $assetCustomFields = $asset->model()->first()->fieldset; - if($assetCustomFields?->fields) { - foreach ($assetCustomFields?->fields as $field) { - if (array_key_exists($field->db_column, $this->update_array)) { - $asset->{$field->db_column} = $this->update_array[$field->db_column]; - $asset->save(); - continue; - } else { - $array = $this->update_array; - array_except($array, $field->db_column); - $asset->update($array); - //call update on parent model - $asset->save(); - } - if (!$asset->save()) { - $error_bag[] = $asset->getErrors(); - } + if($assetCustomFields?->fields) { + foreach ($assetCustomFields?->fields as $field) { + if (array_key_exists($field->db_column, $this->update_array)) { + $asset->{$field->db_column} = $this->update_array[$field->db_column]; + $asset->save(); + continue; + } else { + $array = $this->update_array; + array_except($array, $field->db_column); + // $asset->update($array); + $asset->save($array); + //call update on parent model + // $asset->save(); + } + if (!$asset->save()) { + $error_bag[] = $asset->getErrors(); + } } } } else { From 691faf6340d62e9567e24b16a589c368d70f69f2 Mon Sep 17 00:00:00 2001 From: slong753 Date: Mon, 26 Jun 2023 14:56:07 -0500 Subject: [PATCH 18/38] ok, this kind of works - pr needs some clean up --- .../Assets/BulkAssetsController.php | 22 ++++++++++++------- resources/views/notifications.blade.php | 8 +++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index c291a7fad0..67bb3a8076 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -253,23 +253,29 @@ class BulkAssetsController extends Controller Asset::find($assetId)->update($this->update_array); } } // endforeach ($assets) - ray($error_bag); + ray(['error_bag1' => $error_bag]); if(!empty($error_bag)) { // $errors = collect($error_bag)->unique(); // foreach ($errors as $key => $value) { // ray($value->message); // } $errors = []; - foreach ($error_bag as $key => $value) { - foreach($value as $key => $value) { - $errors[] = $value; + //find the customfield name from the name of the messagebag items + foreach ($error_bag as $key => $bag) { + ray($bag->keys()); + foreach($bag->keys() as $key => $value) { + CustomField::where('db_column', $value)->get()->map(function($item) use (&$errors) { + $errors[] = $item->name; + }); } - } - ray($error_bag); - Session::save('ids', $assets); + } + ray(['error_bag2' => $errors]); + + // Session::save('ids', $assets); + // return redirect()->route('hardware/bulkedit'); - return redirect()->back()->with('bulk_errors', $errors); + return redirect($bulk_back_url)->with('bulk_errors', array_unique($errors)); } return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success')); } diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 26f432c3d9..b0630f8583 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -115,19 +115,19 @@ @endif -{{-- @if ($messages = Session::get('bulk_errors')) +@if ($messages = Session::get('bulk_errors'))
{{ trans('general.notification_error') }} The following fields had validation errors and were not edited: - @foreach($messages as $message => $value) -
{{ $value. }} + @foreach($messages as $message) +
{{ $message }} @endforeach
-@endif --}} +@endif @if ($message = Session::get('warning')) From 2a352619f74005c870734af600166a2daba78475 Mon Sep 17 00:00:00 2001 From: slong753 Date: Mon, 26 Jun 2023 16:25:48 -0500 Subject: [PATCH 19/38] clean up --- .../Assets/BulkAssetsController.php | 29 +------------------ app/Models/CustomField.php | 1 - 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 67bb3a8076..4df2a0c60a 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -14,9 +14,6 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Session; use App\Http\Requests\AssetCheckoutRequest; use App\Models\CustomField; -use Illuminate\Support\Collection; - -use function Amp\Promise\wait; class BulkAssetsController extends Controller { @@ -33,9 +30,6 @@ class BulkAssetsController extends Controller */ public function edit(Request $request) { - // dd($request->all()); - // dd(Session::get('ids')); - $this->authorize('view', Asset::class); if (! $request->filled('ids')) { @@ -59,12 +53,6 @@ class BulkAssetsController extends Controller $modelNames[] = $model->model->name; } - // $custom_fields = new Collection(); - // foreach ($models as $asset_key => $asset) { - // $custom_fields->push($asset->model->customFields); - // } - $custom_fields = $asset_custom_field->pluck('model.fieldset.fields')->flatten()->unique('id'); - if ($request->filled('bulk_actions')) { switch ($request->input('bulk_actions')) { case 'labels': @@ -98,7 +86,6 @@ class BulkAssetsController extends Controller return view('hardware/bulk') ->with('assets', $asset_ids) ->with('statuslabel_list', Helper::statusLabelList()) - // ->with('custom_fields', $custom_fields) ->with('models', $models->pluck(['model'])) ->with('modelNames', $modelNames); } @@ -117,7 +104,6 @@ class BulkAssetsController extends Controller */ public function update(Request $request) { - // dd(request()->headers->get('referer')); $this->authorize('update', Asset::class); $error_bag = []; @@ -161,7 +147,6 @@ class BulkAssetsController extends Controller || ($request->anyFilled($custom_field_columns)) ) { - // dd($assets); foreach ($assets as $assetId) { $this->update_array = []; @@ -252,29 +237,17 @@ class BulkAssetsController extends Controller } else { Asset::find($assetId)->update($this->update_array); } - } // endforeach ($assets) - ray(['error_bag1' => $error_bag]); + } if(!empty($error_bag)) { - // $errors = collect($error_bag)->unique(); - // foreach ($errors as $key => $value) { - // ray($value->message); - // } $errors = []; //find the customfield name from the name of the messagebag items foreach ($error_bag as $key => $bag) { - ray($bag->keys()); foreach($bag->keys() as $key => $value) { CustomField::where('db_column', $value)->get()->map(function($item) use (&$errors) { $errors[] = $item->name; }); } } - ray(['error_bag2' => $errors]); - - // Session::save('ids', $assets); - - - // return redirect()->route('hardware/bulkedit'); return redirect($bulk_back_url)->with('bulk_errors', array_unique($errors)); } return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success')); diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index 60f726de92..7f8b299d7a 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Validation\Rule; use Schema; use Watson\Validating\ValidatingTrait; -// use App\Models\SnipeModel; class CustomField extends Model { use HasFactory; From 8cbff0179c4a570f29fbee9811c59aaab51eff20 Mon Sep 17 00:00:00 2001 From: slong753 Date: Mon, 26 Jun 2023 16:35:53 -0500 Subject: [PATCH 20/38] translation strings --- resources/lang/en/admin/hardware/form.php | 1 + resources/lang/en/general.php | 1 + resources/views/hardware/bulk.blade.php | 2 +- resources/views/notifications.blade.php | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/lang/en/admin/hardware/form.php b/resources/lang/en/admin/hardware/form.php index 6bcb884bab..8159732d08 100644 --- a/resources/lang/en/admin/hardware/form.php +++ b/resources/lang/en/admin/hardware/form.php @@ -10,6 +10,7 @@ return [ 'bulk_update' => 'Bulk Update Assets', 'bulk_update_help' => 'This form allows you to update multiple assets at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged. ', 'bulk_update_warn' => 'You are about to edit the properties of a single asset.|You are about to edit the properties of :asset_count assets.', + 'bulk_update_with_custom_field' => 'made up of :asset_model_count models.', 'checkedout_to' => 'Checked Out To', 'checkout_date' => 'Checkout Date', 'checkin_date' => 'Checkin Date', diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 28f9fd82ba..7bd13d100a 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -364,6 +364,7 @@ return [ 'licenses_count' => 'Licenses Count', 'notification_error' => 'Error:', 'notification_error_hint' => 'Please check the form below for errors', + 'notification_bulk_error_hint' => 'The following fields had validation errors and were not edited:', 'notification_success' => 'Success:', 'notification_warning' => 'Warning:', 'notification_info' => 'Info:', diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index 963d6debfe..667126ec99 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -22,7 +22,7 @@
{{ trans_choice('admin/hardware/form.bulk_update_warn', count($assets), ['asset_count' => count($assets)]) }} @if (count($models) > 0) - made up of {{count($models)}} models + {{ trans_choice('admin/hardware/form.bulk_update_with_custom_field', count($models), ['asset_model_count' => count($models)]) }} @endif
diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index b0630f8583..69cecc284c 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -121,7 +121,7 @@ {{ trans('general.notification_error') }} - The following fields had validation errors and were not edited: + trans('general.notification_bulk_error_hint') @foreach($messages as $message)
{{ $message }} @endforeach From 273616190921211a4cd0333a4e0d7f4a820d6ce3 Mon Sep 17 00:00:00 2001 From: slong753 Date: Mon, 26 Jun 2023 16:37:06 -0500 Subject: [PATCH 21/38] oops, fixed translation --- resources/views/notifications.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 69cecc284c..574aaf8331 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -121,7 +121,7 @@ {{ trans('general.notification_error') }} - trans('general.notification_bulk_error_hint') + {{ trans('general.notification_bulk_error_hint') }} @foreach($messages as $message)
{{ $message }} @endforeach From e8988bf51e7cafabd3fc269acfbafddae51fd987 Mon Sep 17 00:00:00 2001 From: slong753 Date: Mon, 26 Jun 2023 20:22:27 -0500 Subject: [PATCH 22/38] add list --- resources/views/notifications.blade.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 574aaf8331..ca7945d563 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -123,7 +123,9 @@ {{ trans('general.notification_error') }} {{ trans('general.notification_bulk_error_hint') }} @foreach($messages as $message) -
{{ $message }} +
    +
  • {{ $message }}
  • +
@endforeach
From 8b8e7cb5ee6296fb5b4483c3f553fac06edc7c40 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 28 Jun 2023 10:17:28 -0500 Subject: [PATCH 23/38] couple translation strings --- resources/lang/en/admin/hardware/form.php | 3 ++- resources/views/models/custom_fields_form_bulk_edit.blade.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/lang/en/admin/hardware/form.php b/resources/lang/en/admin/hardware/form.php index 8159732d08..679f0d94ae 100644 --- a/resources/lang/en/admin/hardware/form.php +++ b/resources/lang/en/admin/hardware/form.php @@ -10,7 +10,8 @@ return [ 'bulk_update' => 'Bulk Update Assets', 'bulk_update_help' => 'This form allows you to update multiple assets at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged. ', 'bulk_update_warn' => 'You are about to edit the properties of a single asset.|You are about to edit the properties of :asset_count assets.', - 'bulk_update_with_custom_field' => 'made up of :asset_model_count models.', + 'bulk_update_with_custom_field' => 'Note the assets are :asset_model_count different types of models.', + 'bulk_update_model_prefix' => 'On Models:', 'checkedout_to' => 'Checked Out To', 'checkout_date' => 'Checkout Date', 'checkin_date' => 'Checkin Date', diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index 123472830c..da62d2acf9 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -80,7 +80,7 @@ @endif -

On Models: +

{{ trans('admin/hardware/form.bulk_update_model_prefix') }} @foreach($field->assetModels() as $assetModel) @if(in_array($assetModel->name, $modelNames)) {{$assetModel->name}}{{($loop->last) ? '' : ', '}} From 50a518e5f359b4d8f0db6ba9c6fe5d20c6b0a20f Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 28 Jun 2023 12:57:23 -0500 Subject: [PATCH 24/38] disable input when field is unique --- .../custom_fields_form_bulk_edit.blade.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index da62d2acf9..f4ab9bf93e 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -20,6 +20,14 @@

+ {{-- @if ($field->is_unique) +
+ +
+ @else --}} @if ($field->element!='text') @@ -66,11 +74,18 @@ @else + @if (($field->field_encrypted=='0') || (Gate::allows('admin'))) + @if ($field->is_unique) + + @endif + @if(!$field->is_unique) + @endif @else @endif + @endif @endif @@ -78,6 +93,9 @@ @if ($field->help_text!='')

{{ $field->help_text }}

@endif + {{-- @if ($field->is_unique) +

Unique, Can't Be Bulk Updated

+ @endif --}}

{{ trans('admin/hardware/form.bulk_update_model_prefix') }} @@ -108,6 +126,7 @@

+ {{-- @endif --}} @endforeach @endif @endforeach From 2d27941105582465103ff39c1d7e8650441aab0c Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 28 Jun 2023 12:59:54 -0500 Subject: [PATCH 25/38] added to textarea too --- .../views/models/custom_fields_form_bulk_edit.blade.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index f4ab9bf93e..aa24b0ac3a 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -37,7 +37,12 @@ Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} @elseif ($field->element=='textarea') + @if($field->is_unique) + + @endif + @if(!$field->is_unique) + @endif @elseif ($field->element=='checkbox') @foreach ($field->formatFieldValuesAsArray() as $key => $value) From 3b8ab2d682cf9ad059dc09dd3e06b31907f18284 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 28 Jun 2023 13:00:59 -0500 Subject: [PATCH 26/38] clean formatting a little --- .../custom_fields_form_bulk_edit.blade.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index aa24b0ac3a..ee05fa4aab 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -38,11 +38,11 @@ @elseif ($field->element=='textarea') @if($field->is_unique) - + @endif @if(!$field->is_unique) - - @endif + + @endif @elseif ($field->element=='checkbox') @foreach ($field->formatFieldValuesAsArray() as $key => $value) @@ -81,14 +81,14 @@ @else @if (($field->field_encrypted=='0') || (Gate::allows('admin'))) - @if ($field->is_unique) - - @endif - @if(!$field->is_unique) - - @endif - @else - + @if ($field->is_unique) + + @endif + @if(!$field->is_unique) + + @endif + @else + @endif @endif From 8923206ac86e3c8732637b57cd391cc4c0ce08c9 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 28 Jun 2023 13:08:34 -0500 Subject: [PATCH 27/38] translation string --- resources/lang/en/admin/hardware/form.php | 1 + .../custom_fields_form_bulk_edit.blade.php | 18 ++---------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/resources/lang/en/admin/hardware/form.php b/resources/lang/en/admin/hardware/form.php index 679f0d94ae..b6fabe57a2 100644 --- a/resources/lang/en/admin/hardware/form.php +++ b/resources/lang/en/admin/hardware/form.php @@ -12,6 +12,7 @@ return [ 'bulk_update_warn' => 'You are about to edit the properties of a single asset.|You are about to edit the properties of :asset_count assets.', 'bulk_update_with_custom_field' => 'Note the assets are :asset_model_count different types of models.', 'bulk_update_model_prefix' => 'On Models:', + 'bulk_update_custom_field_unique' => 'This is a unique field and can not be bulk edited.', 'checkedout_to' => 'Checked Out To', 'checkout_date' => 'Checkout Date', 'checkin_date' => 'Checkin Date', diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index ee05fa4aab..9652d35d8d 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -20,15 +20,6 @@
- {{-- @if ($field->is_unique) -
- -
- @else --}} - @if ($field->element!='text') @@ -38,7 +29,7 @@ @elseif ($field->element=='textarea') @if($field->is_unique) - + @endif @if(!$field->is_unique) @@ -82,7 +73,7 @@ @if (($field->field_encrypted=='0') || (Gate::allows('admin'))) @if ($field->is_unique) - + @endif @if(!$field->is_unique) @@ -98,10 +89,6 @@ @if ($field->help_text!='')

{{ $field->help_text }}

@endif - {{-- @if ($field->is_unique) -

Unique, Can't Be Bulk Updated

- @endif --}} -

{{ trans('admin/hardware/form.bulk_update_model_prefix') }} @foreach($field->assetModels() as $assetModel) @@ -131,7 +118,6 @@

- {{-- @endif --}} @endforeach @endif @endforeach From afe6fe207ae72ff2be5a4e873470740fcfe84c96 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 28 Jun 2023 16:45:18 -0500 Subject: [PATCH 28/38] resolved, missed adding errors in a case --- app/Http/Controllers/Assets/BulkAssetsController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 4df2a0c60a..d30df20da8 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -219,15 +219,15 @@ class BulkAssetsController extends Controller foreach ($assetCustomFields?->fields as $field) { if (array_key_exists($field->db_column, $this->update_array)) { $asset->{$field->db_column} = $this->update_array[$field->db_column]; - $asset->save(); + $saved = $asset->save(); + if(!$saved) { + $error_bag[] = $asset->getErrors(); + } continue; } else { $array = $this->update_array; array_except($array, $field->db_column); - // $asset->update($array); $asset->save($array); - //call update on parent model - // $asset->save(); } if (!$asset->save()) { $error_bag[] = $asset->getErrors(); From ea61f634fbf486905b7e7299a27dafbc615803d5 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 28 Jun 2023 16:48:52 -0500 Subject: [PATCH 29/38] get rid of nice nullsafe --- app/Http/Controllers/Assets/BulkAssetsController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index d30df20da8..f68516b62b 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -215,8 +215,8 @@ class BulkAssetsController extends Controller if($custom_fields_present) { $asset = Asset::find($assetId); $assetCustomFields = $asset->model()->first()->fieldset; - if($assetCustomFields?->fields) { - foreach ($assetCustomFields?->fields as $field) { + if($assetCustomFields && $assetCustomFields->fields) { + foreach ($assetCustomFields->fields as $field) { if (array_key_exists($field->db_column, $this->update_array)) { $asset->{$field->db_column} = $this->update_array[$field->db_column]; $saved = $asset->save(); From 826ea0ded892df52ced6138049bbb591b52b2428 Mon Sep 17 00:00:00 2001 From: slong753 Date: Thu, 29 Jun 2023 10:40:04 -0500 Subject: [PATCH 30/38] move colon to blade based on a comment --- resources/lang/en/admin/hardware/form.php | 2 +- resources/views/models/custom_fields_form_bulk_edit.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/lang/en/admin/hardware/form.php b/resources/lang/en/admin/hardware/form.php index b6fabe57a2..ef877c8377 100644 --- a/resources/lang/en/admin/hardware/form.php +++ b/resources/lang/en/admin/hardware/form.php @@ -11,7 +11,7 @@ return [ 'bulk_update_help' => 'This form allows you to update multiple assets at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged. ', 'bulk_update_warn' => 'You are about to edit the properties of a single asset.|You are about to edit the properties of :asset_count assets.', 'bulk_update_with_custom_field' => 'Note the assets are :asset_model_count different types of models.', - 'bulk_update_model_prefix' => 'On Models:', + 'bulk_update_model_prefix' => 'On Models', 'bulk_update_custom_field_unique' => 'This is a unique field and can not be bulk edited.', 'checkedout_to' => 'Checked Out To', 'checkout_date' => 'Checkout Date', diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index 9652d35d8d..2e210948b8 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -90,7 +90,7 @@

{{ $field->help_text }}

@endif -

{{ trans('admin/hardware/form.bulk_update_model_prefix') }} +

{{ trans('admin/hardware/form.bulk_update_model_prefix') }}: @foreach($field->assetModels() as $assetModel) @if(in_array($assetModel->name, $modelNames)) {{$assetModel->name}}{{($loop->last) ? '' : ', '}} From 8cee3a821862fc033b1eafa6c7c9af2a44279423 Mon Sep 17 00:00:00 2001 From: slong753 Date: Thu, 29 Jun 2023 14:06:52 -0500 Subject: [PATCH 31/38] ok, @marcusmoore was right all along i just didn't get it --- .../views/models/custom_fields_form_bulk_edit.blade.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index 2e210948b8..e974c3f6eb 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -91,12 +91,8 @@ @endif

{{ trans('admin/hardware/form.bulk_update_model_prefix') }}: - @foreach($field->assetModels() as $assetModel) - @if(in_array($assetModel->name, $modelNames)) - {{$assetModel->name}}{{($loop->last) ? '' : ', '}} - @endif - @endforeach -

+ {{$field->assetModels()->pluck('name')->intersect($modelNames)->implode(', ')}} +

From 6b6bb61400532dac9de613400b118f8ae898451d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 10 Aug 2023 11:52:42 -0700 Subject: [PATCH 32/38] Bump nyholm/psr7 to 1.6.1 --- composer.lock | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index 46cb36476c..bddf161439 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ba3150255e8c263677ad9bc203852fb0", + "content-hash": "117e3e13f1e5354b18e6a5a7ad38641b", "packages": [ { "name": "alek13/slack", @@ -6130,16 +6130,16 @@ }, { "name": "nyholm/psr7", - "version": "1.5.1", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/Nyholm/psr7.git", - "reference": "f734364e38a876a23be4d906a2a089e1315be18a" + "reference": "e874c8c4286a1e010fb4f385f3a55ac56a05cc93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Nyholm/psr7/zipball/f734364e38a876a23be4d906a2a089e1315be18a", - "reference": "f734364e38a876a23be4d906a2a089e1315be18a", + "url": "https://api.github.com/repos/Nyholm/psr7/zipball/e874c8c4286a1e010fb4f385f3a55ac56a05cc93", + "reference": "e874c8c4286a1e010fb4f385f3a55ac56a05cc93", "shasum": "" }, "require": { @@ -6149,6 +6149,7 @@ "psr/http-message": "^1.0" }, "provide": { + "php-http/message-factory-implementation": "1.0", "psr/http-factory-implementation": "1.0", "psr/http-message-implementation": "1.0" }, @@ -6161,7 +6162,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.6-dev" } }, "autoload": { @@ -6191,7 +6192,7 @@ ], "support": { "issues": "https://github.com/Nyholm/psr7/issues", - "source": "https://github.com/Nyholm/psr7/tree/1.5.1" + "source": "https://github.com/Nyholm/psr7/tree/1.6.1" }, "funding": [ { @@ -6203,7 +6204,7 @@ "type": "github" } ], - "time": "2022-06-22T07:13:36+00:00" + "time": "2023-04-17T16:03:48+00:00" }, { "name": "onelogin/php-saml", From 3a2b15313cbb2308e18cca690ea3961f0a8328a7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 10 Aug 2023 11:53:20 -0700 Subject: [PATCH 33/38] Bump guzzlehttp/psr7 to 2.4.5 --- composer.lock | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/composer.lock b/composer.lock index bddf161439..9c695b6ef0 100644 --- a/composer.lock +++ b/composer.lock @@ -2948,16 +2948,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "2.4.0", + "version": "2.4.5", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "13388f00956b1503577598873fffb5ae994b5737" + "reference": "0454e12ef0cd597ccd2adb036f7bda4e7fface66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/13388f00956b1503577598873fffb5ae994b5737", - "reference": "13388f00956b1503577598873fffb5ae994b5737", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/0454e12ef0cd597ccd2adb036f7bda4e7fface66", + "reference": "0454e12ef0cd597ccd2adb036f7bda4e7fface66", "shasum": "" }, "require": { @@ -2971,17 +2971,18 @@ "psr/http-message-implementation": "1.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.4.1", + "bamarni/composer-bin-plugin": "^1.8.1", "http-interop/http-factory-tests": "^0.9", - "phpunit/phpunit": "^8.5.8 || ^9.3.10" + "phpunit/phpunit": "^8.5.29 || ^9.5.23" }, "suggest": { "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" }, "type": "library", "extra": { - "branch-alias": { - "dev-master": "2.4-dev" + "bamarni-bin": { + "bin-links": true, + "forward-command": false } }, "autoload": { @@ -3043,7 +3044,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.4.0" + "source": "https://github.com/guzzle/psr7/tree/2.4.5" }, "funding": [ { @@ -3059,7 +3060,7 @@ "type": "tidelift" } ], - "time": "2022-06-20T21:43:11+00:00" + "time": "2023-04-17T16:00:45+00:00" }, { "name": "intervention/image", From a62876d4bcc704911938c42b364850731d01438b Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 17 Aug 2023 16:14:01 -0700 Subject: [PATCH 34/38] Adds readable asset history in the action log transformer --- .../Transformers/ActionlogsTransformer.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 7b7a7fc011..b319e793d3 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -4,6 +4,10 @@ namespace App\Http\Transformers; use App\Helpers\Helper; use App\Models\Actionlog; use App\Models\Setting; +use App\Models\Company; +use App\Models\Supplier; +use App\Models\Location; +use App\Models\AssetModel; use Illuminate\Database\Eloquent\Collection; class ActionlogsTransformer @@ -53,6 +57,7 @@ class ActionlogsTransformer } } + $clean_meta= $this->changedInfo($clean_meta); } $file_url = ''; @@ -132,6 +137,49 @@ class ActionlogsTransformer } return (new DatatablesTransformer)->transformDatatables($array, $total); } + /** + * This takes the ids of the changed attributes and returns the names instead for the history view of an Asset + * + * @param array $clean_meta + * @return array + */ + public function changedInfo(array $clean_meta) + { + + if(array_key_exists('rtd_location_id',$clean_meta)) { + $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? Location::find($clean_meta['rtd_location_id']['old'])->name : trans('general.unassigned'); + $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? Location::find($clean_meta['rtd_location_id']['new'])->name : trans('general.unassigned'); + $clean_meta['Default Location'] = $clean_meta['rtd_location_id']; + unset($clean_meta['rtd_location_id']); + } + if(array_key_exists('location_id', $clean_meta)) { + $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? Location::find($clean_meta['location_id']['old'])->name : trans('general.unassigned'); + $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? Location::find($clean_meta['location_id']['new'])->name : trans('general.unassigned'); + $clean_meta['Current Location'] = $clean_meta['location_id']; + unset($clean_meta['location_id']); + } + if(array_key_exists('model_id', $clean_meta)) { + $clean_meta['model_id']['old'] = AssetModel::find($clean_meta['model_id']['old'])->name; + $clean_meta['model_id']['new'] = AssetModel::find($clean_meta['model_id']['new'])->name; /* model is required at asset creation */ + $clean_meta['Model'] = $clean_meta['model_id']; + unset($clean_meta['model_id']); + } + if(array_key_exists('company_id', $clean_meta)) { + $clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? Company::find($clean_meta['company_id']['old'])->name : trans('general.unassigned'); + $clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? Company::find($clean_meta['company_id']['new'])->name : trans('general.unassigned'); + $clean_meta['Company'] = $clean_meta['company_id']; + unset($clean_meta['company_id']); + } + if(array_key_exists('supplier_id', $clean_meta)) { + $clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? Supplier::find($clean_meta['supplier_id']['old'])->name : trans('general.unassigned'); + $clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? Supplier::find($clean_meta['supplier_id']['new'])->name : trans('general.unassigned'); + $clean_meta['Supplier'] = $clean_meta['supplier_id']; + unset($clean_meta['supplier_id']); + } + + return $clean_meta; + + } From 5076b45a0d30c7be79aa381a1a8600a08ac34170 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 21 Aug 2023 13:40:39 -0700 Subject: [PATCH 35/38] adds id to history info --- .../Transformers/ActionlogsTransformer.php | 20 +++++++++---------- resources/lang/en/general.php | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index b319e793d3..4cf66dbdd6 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -147,32 +147,32 @@ class ActionlogsTransformer { if(array_key_exists('rtd_location_id',$clean_meta)) { - $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? Location::find($clean_meta['rtd_location_id']['old'])->name : trans('general.unassigned'); - $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? Location::find($clean_meta['rtd_location_id']['new'])->name : trans('general.unassigned'); + $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."]". Location::find($clean_meta['rtd_location_id']['old'])->name : trans('general.unassigned'); + $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."]". Location::find($clean_meta['rtd_location_id']['new'])->name : trans('general.unassigned'); $clean_meta['Default Location'] = $clean_meta['rtd_location_id']; unset($clean_meta['rtd_location_id']); } if(array_key_exists('location_id', $clean_meta)) { - $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? Location::find($clean_meta['location_id']['old'])->name : trans('general.unassigned'); - $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? Location::find($clean_meta['location_id']['new'])->name : trans('general.unassigned'); + $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."]".Location::find($clean_meta['location_id']['old'])->name : trans('general.unassigned'); + $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."]".Location::find($clean_meta['location_id']['new'])->name : trans('general.unassigned'); $clean_meta['Current Location'] = $clean_meta['location_id']; unset($clean_meta['location_id']); } if(array_key_exists('model_id', $clean_meta)) { - $clean_meta['model_id']['old'] = AssetModel::find($clean_meta['model_id']['old'])->name; - $clean_meta['model_id']['new'] = AssetModel::find($clean_meta['model_id']['new'])->name; /* model is required at asset creation */ + $clean_meta['model_id']['old'] = "[id: ".$clean_meta['model_id']['old']."]".AssetModel::find($clean_meta['model_id']['old'])->name; + $clean_meta['model_id']['new'] = "[id: ".$clean_meta['model_id']['new']."]".AssetModel::find($clean_meta['model_id']['new'])->name; /* model is required at asset creation */ $clean_meta['Model'] = $clean_meta['model_id']; unset($clean_meta['model_id']); } if(array_key_exists('company_id', $clean_meta)) { - $clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? Company::find($clean_meta['company_id']['old'])->name : trans('general.unassigned'); - $clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? Company::find($clean_meta['company_id']['new'])->name : trans('general.unassigned'); + $clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? "[id: ".$clean_meta['company_id']['old']."]".Company::find($clean_meta['company_id']['old'])->name : trans('general.unassigned'); + $clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? "[id: ".$clean_meta['company_id']['new']."]".Company::find($clean_meta['company_id']['new'])->name : trans('general.unassigned'); $clean_meta['Company'] = $clean_meta['company_id']; unset($clean_meta['company_id']); } if(array_key_exists('supplier_id', $clean_meta)) { - $clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? Supplier::find($clean_meta['supplier_id']['old'])->name : trans('general.unassigned'); - $clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? Supplier::find($clean_meta['supplier_id']['new'])->name : trans('general.unassigned'); + $clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? "[id: ".$clean_meta['supplier_id']['old']."]".Supplier::find($clean_meta['supplier_id']['old'])->name : trans('general.unassigned'); + $clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? "[id: ".$clean_meta['supplier_id']['new']."]".Supplier::find($clean_meta['supplier_id']['new'])->name : trans('general.unassigned'); $clean_meta['Supplier'] = $clean_meta['supplier_id']; unset($clean_meta['supplier_id']); } diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 4831845721..632a0a590f 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -283,6 +283,7 @@ return [ 'user' => 'User', 'accepted' => 'accepted', 'declined' => 'declined', + 'unassigned' => 'Unassigned', 'unaccepted_asset_report' => 'Unaccepted Assets', 'users' => 'Users', 'viewall' => 'View All', From b54aaefefb40fb71c2580e0f02c65a7b76be15c4 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 21 Aug 2023 13:43:06 -0700 Subject: [PATCH 36/38] adds some spacing --- .../Transformers/ActionlogsTransformer.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 4cf66dbdd6..2a592e9c83 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -147,32 +147,32 @@ class ActionlogsTransformer { if(array_key_exists('rtd_location_id',$clean_meta)) { - $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."]". Location::find($clean_meta['rtd_location_id']['old'])->name : trans('general.unassigned'); - $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."]". Location::find($clean_meta['rtd_location_id']['new'])->name : trans('general.unassigned'); + $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."] ". Location::find($clean_meta['rtd_location_id']['old'])->name : trans('general.unassigned'); + $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."] ". Location::find($clean_meta['rtd_location_id']['new'])->name : trans('general.unassigned'); $clean_meta['Default Location'] = $clean_meta['rtd_location_id']; unset($clean_meta['rtd_location_id']); } if(array_key_exists('location_id', $clean_meta)) { - $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."]".Location::find($clean_meta['location_id']['old'])->name : trans('general.unassigned'); - $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."]".Location::find($clean_meta['location_id']['new'])->name : trans('general.unassigned'); + $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."] ".Location::find($clean_meta['location_id']['old'])->name : trans('general.unassigned'); + $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."] ".Location::find($clean_meta['location_id']['new'])->name : trans('general.unassigned'); $clean_meta['Current Location'] = $clean_meta['location_id']; unset($clean_meta['location_id']); } if(array_key_exists('model_id', $clean_meta)) { - $clean_meta['model_id']['old'] = "[id: ".$clean_meta['model_id']['old']."]".AssetModel::find($clean_meta['model_id']['old'])->name; - $clean_meta['model_id']['new'] = "[id: ".$clean_meta['model_id']['new']."]".AssetModel::find($clean_meta['model_id']['new'])->name; /* model is required at asset creation */ + $clean_meta['model_id']['old'] = "[id: ".$clean_meta['model_id']['old']."] ".AssetModel::find($clean_meta['model_id']['old'])->name; + $clean_meta['model_id']['new'] = "[id: ".$clean_meta['model_id']['new']."] ".AssetModel::find($clean_meta['model_id']['new'])->name; /* model is required at asset creation */ $clean_meta['Model'] = $clean_meta['model_id']; unset($clean_meta['model_id']); } if(array_key_exists('company_id', $clean_meta)) { $clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? "[id: ".$clean_meta['company_id']['old']."]".Company::find($clean_meta['company_id']['old'])->name : trans('general.unassigned'); - $clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? "[id: ".$clean_meta['company_id']['new']."]".Company::find($clean_meta['company_id']['new'])->name : trans('general.unassigned'); + $clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? "[id: ".$clean_meta['company_id']['new']."] ".Company::find($clean_meta['company_id']['new'])->name : trans('general.unassigned'); $clean_meta['Company'] = $clean_meta['company_id']; unset($clean_meta['company_id']); } if(array_key_exists('supplier_id', $clean_meta)) { - $clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? "[id: ".$clean_meta['supplier_id']['old']."]".Supplier::find($clean_meta['supplier_id']['old'])->name : trans('general.unassigned'); - $clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? "[id: ".$clean_meta['supplier_id']['new']."]".Supplier::find($clean_meta['supplier_id']['new'])->name : trans('general.unassigned'); + $clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? "[id: ".$clean_meta['supplier_id']['old']."] ".Supplier::find($clean_meta['supplier_id']['old'])->name : trans('general.unassigned'); + $clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? "[id: ".$clean_meta['supplier_id']['new']."] ".Supplier::find($clean_meta['supplier_id']['new'])->name : trans('general.unassigned'); $clean_meta['Supplier'] = $clean_meta['supplier_id']; unset($clean_meta['supplier_id']); } From 1e10a7ee23739c9ac9597d9d4dd89d2be6116c96 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 21 Aug 2023 14:45:21 -0700 Subject: [PATCH 37/38] Bump nyholm/psr7 to 1.6.1 --- composer.lock | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index 6221937a3d..0d7b651b73 100644 --- a/composer.lock +++ b/composer.lock @@ -6130,16 +6130,16 @@ }, { "name": "nyholm/psr7", - "version": "1.5.1", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/Nyholm/psr7.git", - "reference": "f734364e38a876a23be4d906a2a089e1315be18a" + "reference": "e874c8c4286a1e010fb4f385f3a55ac56a05cc93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Nyholm/psr7/zipball/f734364e38a876a23be4d906a2a089e1315be18a", - "reference": "f734364e38a876a23be4d906a2a089e1315be18a", + "url": "https://api.github.com/repos/Nyholm/psr7/zipball/e874c8c4286a1e010fb4f385f3a55ac56a05cc93", + "reference": "e874c8c4286a1e010fb4f385f3a55ac56a05cc93", "shasum": "" }, "require": { @@ -6149,6 +6149,7 @@ "psr/http-message": "^1.0" }, "provide": { + "php-http/message-factory-implementation": "1.0", "psr/http-factory-implementation": "1.0", "psr/http-message-implementation": "1.0" }, @@ -6161,7 +6162,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.6-dev" } }, "autoload": { @@ -6191,7 +6192,7 @@ ], "support": { "issues": "https://github.com/Nyholm/psr7/issues", - "source": "https://github.com/Nyholm/psr7/tree/1.5.1" + "source": "https://github.com/Nyholm/psr7/tree/1.6.1" }, "funding": [ { @@ -6203,7 +6204,7 @@ "type": "github" } ], - "time": "2022-06-22T07:13:36+00:00" + "time": "2023-04-17T16:03:48+00:00" }, { "name": "onelogin/php-saml", @@ -16736,5 +16737,5 @@ "ext-pdo": "*" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.3.0" } From 191c4f959f4148a191d91afadc9eb10cbead786f Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 21 Aug 2023 14:46:08 -0700 Subject: [PATCH 38/38] Bump guzzlehttp/psr7 to 2.4.5 --- composer.lock | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/composer.lock b/composer.lock index 0d7b651b73..54d3e556b6 100644 --- a/composer.lock +++ b/composer.lock @@ -2948,16 +2948,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "2.4.0", + "version": "2.4.5", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "13388f00956b1503577598873fffb5ae994b5737" + "reference": "0454e12ef0cd597ccd2adb036f7bda4e7fface66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/13388f00956b1503577598873fffb5ae994b5737", - "reference": "13388f00956b1503577598873fffb5ae994b5737", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/0454e12ef0cd597ccd2adb036f7bda4e7fface66", + "reference": "0454e12ef0cd597ccd2adb036f7bda4e7fface66", "shasum": "" }, "require": { @@ -2971,17 +2971,18 @@ "psr/http-message-implementation": "1.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.4.1", + "bamarni/composer-bin-plugin": "^1.8.1", "http-interop/http-factory-tests": "^0.9", - "phpunit/phpunit": "^8.5.8 || ^9.3.10" + "phpunit/phpunit": "^8.5.29 || ^9.5.23" }, "suggest": { "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" }, "type": "library", "extra": { - "branch-alias": { - "dev-master": "2.4-dev" + "bamarni-bin": { + "bin-links": true, + "forward-command": false } }, "autoload": { @@ -3043,7 +3044,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.4.0" + "source": "https://github.com/guzzle/psr7/tree/2.4.5" }, "funding": [ { @@ -3059,7 +3060,7 @@ "type": "tidelift" } ], - "time": "2022-06-20T21:43:11+00:00" + "time": "2023-04-17T16:00:45+00:00" }, { "name": "intervention/image",