From 804a788a27535a57662dac8e660749d60e53ae6c Mon Sep 17 00:00:00 2001 From: slong753 Date: Tue, 28 Mar 2023 20:31:24 -0500 Subject: [PATCH 01/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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/82] 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 fb52038e7ceadac9477244a27e4d458dfbbbb6a4 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 1 Aug 2023 09:39:58 -0700 Subject: [PATCH 32/82] applies a check if a sync field is designated --- app/Console/Commands/LdapSync.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index f77f5f8c48..3b497a45b0 100755 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -234,17 +234,37 @@ class LdapSync extends Command $item['createorupdate'] = 'created'; } - $user->first_name = $item['firstname']; - $user->last_name = $item['lastname']; + //If a sync option is not filled in on the LDAP settings don't populate the user field + if($ldap_result_username != null){ $user->username = $item['username']; - $user->email = $item['email']; + } + if($ldap_result_last_name != null){ + $user->last_name = $item['lastname']; + } + if($ldap_result_first_name != null){ + $user->first_name = $item['firstname']; + } + if($ldap_result_active_flag != null){ + } + if($ldap_result_emp_num != null){ $user->employee_num = e($item['employee_number']); + } + if($ldap_result_email != null){ + $user->email = $item['email']; + } + if($ldap_result_phone != null){ $user->phone = $item['telephone']; + } + if($ldap_result_jobtitle != null){ $user->jobtitle = $item['jobtitle']; + } + if($ldap_result_country != null){ $user->country = $item['country']; + } + if($ldap_result_dept != null){ $user->department_id = $department->id; - $user->location_id = $location->id; - + } + if($ldap_result_manager != null){ if($item['manager'] != null) { // Check Cache first if (isset($manager_cache[$item['manager']])) { @@ -284,6 +304,7 @@ class LdapSync extends Command } } + } // Sync activated state for Active Directory. if ( !empty($ldap_result_active_flag)) { // IF we have an 'active' flag set.... From 8a24a474758276589333b7f8a17ed2057c0d6baa Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 1 Aug 2023 09:45:48 -0700 Subject: [PATCH 33/82] removed unnecessary code --- app/Console/Commands/LdapSync.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index 3b497a45b0..136a81f62e 100755 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -244,8 +244,6 @@ class LdapSync extends Command if($ldap_result_first_name != null){ $user->first_name = $item['firstname']; } - if($ldap_result_active_flag != null){ - } if($ldap_result_emp_num != null){ $user->employee_num = e($item['employee_number']); } From 9ca163e8cf701b700c71f7f49d6848a13a145909 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Wed, 2 Aug 2023 19:22:35 -0600 Subject: [PATCH 34/82] Stop asset acceptances from shown to user if full company support is enabled and companies not match --- app/Http/Controllers/Account/AcceptanceController.php | 2 +- resources/lang/en/general.php | 1 + resources/views/account/accept/index.blade.php | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index 645e2624b2..99e4562888 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -69,7 +69,7 @@ class AcceptanceController extends Controller } if (! Company::isCurrentUserHasAccess($acceptance->checkoutable)) { - return redirect()->route('account.accept')->with('error', trans('general.insufficient_permissions')); + return redirect()->route('account.accept')->with('error', trans('general.error_user_company')); } return view('account/accept.create', compact('acceptance')); diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 4831845721..3b1d0787d5 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -452,6 +452,7 @@ return [ 'serial_number' => 'Serial Number', 'item_notes' => ':item Notes', 'item_name_var' => ':item Name', + 'error_user_company' => 'User and Asset companies missmatch', 'importer' => [ 'checked_out_to_fullname' => 'Checked Out to: Full Name', 'checked_out_to_first_name' => 'Checked Out to: First Name', diff --git a/resources/views/account/accept/index.blade.php b/resources/views/account/accept/index.blade.php index f2a9bc56f2..58ed542dc6 100755 --- a/resources/views/account/accept/index.blade.php +++ b/resources/views/account/accept/index.blade.php @@ -41,9 +41,11 @@ @foreach ($acceptances as $acceptance) + @if ($acceptance->checkoutable) {{ ($acceptance->checkoutable) ? $acceptance->checkoutable->present()->name : '' }} {{ trans('general.accept_decline') }} + @endif @endforeach From 053d3fc9ed55f8e687dc252f624128c7b3484b6e Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Wed, 2 Aug 2023 19:23:28 -0600 Subject: [PATCH 35/82] Prevent asset to be checked out if full company support is enabled and companies not match --- app/Http/Controllers/Assets/AssetCheckoutController.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php index e6326da6b1..bc5465e4be 100644 --- a/app/Http/Controllers/Assets/AssetCheckoutController.php +++ b/app/Http/Controllers/Assets/AssetCheckoutController.php @@ -89,6 +89,14 @@ class AssetCheckoutController extends Controller } } + $settings = \App\Models\Setting::getSettings(); + + if ($settings->full_multiple_companies_support){ + if ($target->company_id != $asset->company_id){ + return redirect()->to("hardware/$assetId/checkout")->with('error', trans('general.error_user_company')); + } + } + if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e($request->get('note')), $request->get('name'))) { return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkout.success')); } From 6b6bb61400532dac9de613400b118f8ae898451d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 10 Aug 2023 11:52:42 -0700 Subject: [PATCH 36/82] 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 37/82] 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 4796598bb6967eb569c0290e9c7ba4b9e3b4ae99 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Mon, 14 Aug 2023 14:35:31 -0600 Subject: [PATCH 38/82] Add declinedCheckout method to Accessory model --- app/Models/Accessory.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index 7576cc644f..e1da483b97 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -32,6 +32,16 @@ class Accessory extends SnipeModel use Searchable; use Acceptable; + + public function declinedCheckout(User $declinedBy, $signature) + { + if (is_null($accessory_user = \DB::table('accessories_users')->where('assigned_to', $declinedBy->id)->where('accessory_id', $this->id)->latest('created_at'))) { + // Redirect to the accessory management page with error + return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); + } + + $accessory_user->limit(1)->delete(); + } /** * The attributes that should be included when searching the model. From 8da2a8a79c6ca6592db4df6e11e5755a366a051f Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Mon, 14 Aug 2023 14:58:10 -0600 Subject: [PATCH 39/82] Allows to save signature for declined items --- .../Account/AcceptanceController.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index 645e2624b2..8ad24a60f2 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -245,6 +245,36 @@ class AcceptanceController extends Controller $return_msg = trans('admin/users/message.accepted'); } else { + + /** + * Check for the eula-pdfs directory + */ + if (! Storage::exists('private_uploads/eula-pdfs')) { + Storage::makeDirectory('private_uploads/eula-pdfs', 775); + } + + if (Setting::getSettings()->require_accept_signature == '1') { + + // Check if the signature directory exists, if not create it + if (!Storage::exists('private_uploads/signatures')) { + Storage::makeDirectory('private_uploads/signatures', 775); + } + + // The item was accepted, check for a signature + if ($request->filled('signature_output')) { + $sig_filename = 'siglog-' . Str::uuid() . '-' . date('Y-m-d-his') . '.png'; + $data_uri = $request->input('signature_output'); + $encoded_image = explode(',', $data_uri); + $decoded_image = base64_decode($encoded_image[1]); + Storage::put('private_uploads/signatures/' . $sig_filename, (string)$decoded_image); + + // No image data is present, kick them back. + // This mostly only applies to users on super-duper crapola browsers *cough* IE *cough* + } else { + return redirect()->back()->with('error', trans('general.shitty_browser')); + } + } + // Format the data to send the declined notification $branding_settings = SettingsController::getPDFBranding(); @@ -281,11 +311,18 @@ class AcceptanceController extends Controller 'item_model' => $display_model, 'item_serial' => $item->serial, 'declined_date' => Carbon::parse($acceptance->declined_at)->format('Y-m-d'), + 'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null, 'assigned_to' => $assigned_to, 'company_name' => $branding_settings->site_name, 'date_settings' => $branding_settings->date_display_format, ]; + if ($pdf_view_route!='') { + \Log::debug($pdf_filename.' is the filename, and the route was specified.'); + $pdf = Pdf::loadView($pdf_view_route, $data); + Storage::put('private_uploads/eula-pdfs/' .$pdf_filename, $pdf->output()); + } + $acceptance->decline($sig_filename); $acceptance->notify(new AcceptanceAssetDeclinedNotification($data)); event(new CheckoutDeclined($acceptance)); From 96440834bd1e354f126d94c4c4e4b40ffbf250d8 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Mon, 14 Aug 2023 16:16:28 -0600 Subject: [PATCH 40/82] Move the declinedCheckout function so it don/'t separate the class properties --- app/Models/Accessory.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index e1da483b97..86502dc7e7 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -32,16 +32,6 @@ class Accessory extends SnipeModel use Searchable; use Acceptable; - - public function declinedCheckout(User $declinedBy, $signature) - { - if (is_null($accessory_user = \DB::table('accessories_users')->where('assigned_to', $declinedBy->id)->where('accessory_id', $this->id)->latest('created_at'))) { - // Redirect to the accessory management page with error - return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); - } - - $accessory_user->limit(1)->delete(); - } /** * The attributes that should be included when searching the model. @@ -359,6 +349,22 @@ class Accessory extends SnipeModel return (int) $remaining; } + /** + * Run after the checkout acceptance was declined by the user + * + * @param User $acceptedBy + * @param string $signature + */ + public function declinedCheckout(User $declinedBy, $signature) + { + if (is_null($accessory_user = \DB::table('accessories_users')->where('assigned_to', $declinedBy->id)->where('accessory_id', $this->id)->latest('created_at'))) { + // Redirect to the accessory management page with error + return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); + } + + $accessory_user->limit(1)->delete(); + } + /** * Query builder scope to order on company * From dc1a8840f1f38a1f24d07e6c6a2cafc073fcb8b3 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 14 Aug 2023 16:40:34 -0700 Subject: [PATCH 41/82] Ensure empty string is not passed to strpos() --- app/Observers/AssetObserver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.php index 84595f04b3..636f159b65 100644 --- a/app/Observers/AssetObserver.php +++ b/app/Observers/AssetObserver.php @@ -74,9 +74,9 @@ class AssetObserver $tag = $asset->asset_tag; $prefix = $settings->auto_increment_prefix; $number = substr($tag, strlen($prefix)); - // IF - auto_increment_assets is on, AND (the prefix matches the start of the tag OR there is no prefix) + // IF - auto_increment_assets is on, AND (there is no prefix OR the prefix matches the start of the tag) // AND the rest of the string after the prefix is all digits, THEN... - if ($settings->auto_increment_assets && (strpos($tag, $prefix) === 0 || $prefix=='') && preg_match('/\d+/',$number) === 1) { + if ($settings->auto_increment_assets && ($prefix=='' || strpos($tag, $prefix) === 0) && preg_match('/\d+/',$number) === 1) { // new way of auto-trueing-up auto_increment ID's $next_asset_tag = intval($number, 10) + 1; // we had to use 'intval' because the $number could be '01234' and From d365565b6d0ff95b5ba843532c2d64fa95f00e0a Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Mon, 14 Aug 2023 20:51:04 -0600 Subject: [PATCH 42/82] Add message in the acceptance assets view to indicate when the user can\'t accept nor deny the asset --- resources/lang/en/general.php | 1 + resources/views/account/accept/index.blade.php | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 3b1d0787d5..2268008bf7 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -453,6 +453,7 @@ return [ 'item_notes' => ':item Notes', 'item_name_var' => ':item Name', 'error_user_company' => 'User and Asset companies missmatch', + 'error_user_company_accpept_view' => 'User and Asset companies doesn\'t match so you can\'t accept nor deny it, please check with your manager', 'importer' => [ 'checked_out_to_fullname' => 'Checked Out to: Full Name', 'checked_out_to_first_name' => 'Checked Out to: First Name', diff --git a/resources/views/account/accept/index.blade.php b/resources/views/account/accept/index.blade.php index 58ed542dc6..71949f6383 100755 --- a/resources/views/account/accept/index.blade.php +++ b/resources/views/account/accept/index.blade.php @@ -44,8 +44,11 @@ @if ($acceptance->checkoutable) {{ ($acceptance->checkoutable) ? $acceptance->checkoutable->present()->name : '' }} {{ trans('general.accept_decline') }} + @else + ----- + {{ trans('general.error_user_company_accpept_view') }} + @endif - @endif @endforeach From 71cb16118d6afb16deae916671f92e9b59d287df Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Mon, 14 Aug 2023 20:52:00 -0600 Subject: [PATCH 43/82] Change error string for a better (?) one --- resources/lang/en/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 2268008bf7..acbf23c2c2 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -453,7 +453,7 @@ return [ 'item_notes' => ':item Notes', 'item_name_var' => ':item Name', 'error_user_company' => 'User and Asset companies missmatch', - 'error_user_company_accpept_view' => 'User and Asset companies doesn\'t match so you can\'t accept nor deny it, please check with your manager', + 'error_user_company_accpept_view' => 'An Asset assigned to you belongs to a different company so you can\'t accept nor deny it, please check with your manager', 'importer' => [ 'checked_out_to_fullname' => 'Checked Out to: Full Name', 'checked_out_to_first_name' => 'Checked Out to: First Name', From 25c58a84864a4a2339f3c841a1a43b3a2f058c9b Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Tue, 15 Aug 2023 14:17:39 -0600 Subject: [PATCH 44/82] Fix typo in language variable name --- resources/lang/en/general.php | 2 +- resources/views/account/accept/index.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index acbf23c2c2..e4596d0cd0 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -453,7 +453,7 @@ return [ 'item_notes' => ':item Notes', 'item_name_var' => ':item Name', 'error_user_company' => 'User and Asset companies missmatch', - 'error_user_company_accpept_view' => 'An Asset assigned to you belongs to a different company so you can\'t accept nor deny it, please check with your manager', + 'error_user_company_accept_view' => 'An Asset assigned to you belongs to a different company so you can\'t accept nor deny it, please check with your manager', 'importer' => [ 'checked_out_to_fullname' => 'Checked Out to: Full Name', 'checked_out_to_first_name' => 'Checked Out to: First Name', diff --git a/resources/views/account/accept/index.blade.php b/resources/views/account/accept/index.blade.php index 71949f6383..b627135a4d 100755 --- a/resources/views/account/accept/index.blade.php +++ b/resources/views/account/accept/index.blade.php @@ -46,7 +46,7 @@ {{ trans('general.accept_decline') }} @else ----- - {{ trans('general.error_user_company_accpept_view') }} + {{ trans('general.error_user_company_accept_view') }} @endif @endforeach From 993918f47c7a04fbe2ad39326d0848ebcd1369c2 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Tue, 15 Aug 2023 15:31:36 -0600 Subject: [PATCH 45/82] Add query to search into the per-component view --- .../Controllers/Api/ComponentsController.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php index 4806caf8a3..d41459d2a7 100644 --- a/app/Http/Controllers/Api/ComponentsController.php +++ b/app/Http/Controllers/Api/ComponentsController.php @@ -13,6 +13,7 @@ use App\Events\CheckoutableCheckedIn; use App\Events\ComponentCheckedIn; use App\Models\Asset; use Illuminate\Support\Facades\Validator; +use Illuminate\Database\Query\Builder; class ComponentsController extends Controller { @@ -210,6 +211,21 @@ class ComponentsController extends Controller $total = $assets->count(); $assets = $assets->skip($offset)->take($limit)->get(); + if ($request->filled('search')) { + $assets = $component->assets() + ->where(function ($query) use ($request) { + $search_str = '%' . $request->input('search') . '%'; + $query->where('name', 'like', $search_str) + ->orWhereIn('model_id', function (Builder $query) use ($request) { + $search_str = '%' . $request->input('search') . '%'; + $query->selectRaw('id')->from('models')->where('name', 'like', $search_str); + }) + ->orWhere('asset_tag', 'like', $search_str); + }) + ->get(); + $total = $assets->count(); + } + return (new ComponentsTransformer)->transformCheckedoutComponents($assets, $total); } From 027afa71f191427bd8608a04889af09672b0ded4 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Aug 2023 01:09:22 +0100 Subject: [PATCH 46/82] Check that there is a company before trying to get name property Signed-off-by: snipe --- app/View/Label.php | 51 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/app/View/Label.php b/app/View/Label.php index 99da449827..d581548eb3 100644 --- a/app/View/Label.php +++ b/app/View/Label.php @@ -39,7 +39,7 @@ class Label implements View $assets = $this->data->get('assets'); $offset = $this->data->get('offset'); $template = $this->data->get('template'); - + // If disabled, pass to legacy view if ((!$settings->label2_enable) && (!$template)) { return view('hardware/labels') @@ -49,8 +49,12 @@ class Label implements View ->with('count', $this->data->get('count')); } - if (empty($template)) $template = LabelModel::find($settings->label2_template); - elseif (is_string($template)) $template = LabelModel::find($template); + // If a specific template was set, use it, otherwise fall back to default + if (empty($template)) { + $template = LabelModel::find($settings->label2_template); + } elseif (is_string($template)) { + $template = LabelModel::find($template); + } $template->validate(); @@ -87,25 +91,36 @@ class Label implements View $assetData->put('tag', $asset->asset_tag); if ($template->getSupportTitle()) { - $title = !empty($settings->label2_title) ? - str_ireplace('{COMPANY}', $asset->company->name, $settings->label2_title) : + + if ($asset->company && !empty($settings->label2_title)) { + $title = str_replace('{COMPANY}', $asset->company->name, $settings->label2_title); $settings->qr_text; - if (!empty($title)) $assetData->put('title', $title); + $assetData->put('title', $title); + } } if ($template->getSupportLogo()) { - $logo = $settings->label2_asset_logo ? - ( - !empty($asset->company->image) ? - Storage::disk('public')->path('companies/'.e($asset->company->image)) : - null - ) : - ( - !empty($settings->label_logo) ? - Storage::disk('public')->path(''.e($settings->label_logo)) : - null - ); - if (!empty($logo)) $assetData->put('logo', $logo); + + $logo = null; + + // Should we be trying to use a logo at all? + if ($settings->label2_asset_logo='1') { + + // If we don't have a company image, fall back to the general site label image + if (!empty($settings->label_logo)) { + $logo = Storage::disk('public')->path('/'.e($settings->label_logo)); + } + + // If we have a company logo, use that first + if (($asset->company) && ($asset->company->image!='')) { + $logo = Storage::disk('public')->path('companies/'.e($asset->company->image)); + } + + } + + if (!empty($logo)) { + $assetData->put('logo', $logo); + } } if ($template->getSupport1DBarcode()) { From 74384f14e46a39c0a96e30dde0e5a007c64ad3f0 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Aug 2023 01:25:13 +0100 Subject: [PATCH 47/82] Use clearer translation (from original PR) Signed-off-by: snipe --- resources/views/settings/labels.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/settings/labels.blade.php b/resources/views/settings/labels.blade.php index 32dda8118f..d23ff8ef2c 100644 --- a/resources/views/settings/labels.blade.php +++ b/resources/views/settings/labels.blade.php @@ -128,7 +128,7 @@

{!! trans('admin/settings/general.label2_asset_logo_help', ['setting_name' => trans('admin/settings/general.brand').' > '.trans('admin/settings/general.label_logo')]) !!} From 92df32dfaaffdd2fafd96f04f65b95e66be1eccc Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Tue, 15 Aug 2023 21:10:48 -0600 Subject: [PATCH 48/82] Move a couple assignation of variables inside an else to only execute once --- .../Controllers/Api/ComponentsController.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php index d41459d2a7..a6e3e379e3 100644 --- a/app/Http/Controllers/Api/ComponentsController.php +++ b/app/Http/Controllers/Api/ComponentsController.php @@ -204,26 +204,28 @@ class ComponentsController extends Controller $this->authorize('view', \App\Models\Asset::class); $component = Component::findOrFail($id); - $assets = $component->assets(); - + $offset = request('offset', 0); $limit = $request->input('limit', 50); - $total = $assets->count(); - $assets = $assets->skip($offset)->take($limit)->get(); - + if ($request->filled('search')) { $assets = $component->assets() - ->where(function ($query) use ($request) { - $search_str = '%' . $request->input('search') . '%'; - $query->where('name', 'like', $search_str) - ->orWhereIn('model_id', function (Builder $query) use ($request) { - $search_str = '%' . $request->input('search') . '%'; - $query->selectRaw('id')->from('models')->where('name', 'like', $search_str); - }) - ->orWhere('asset_tag', 'like', $search_str); + ->where(function ($query) use ($request) { + $search_str = '%' . $request->input('search') . '%'; + $query->where('name', 'like', $search_str) + ->orWhereIn('model_id', function (Builder $query) use ($request) { + $search_str = '%' . $request->input('search') . '%'; + $query->selectRaw('id')->from('models')->where('name', 'like', $search_str); + }) + ->orWhere('asset_tag', 'like', $search_str); }) ->get(); $total = $assets->count(); + } else { + $assets = $component->assets(); + + $total = $assets->count(); + $assets = $assets->skip($offset)->take($limit)->get(); } return (new ComponentsTransformer)->transformCheckedoutComponents($assets, $total); From 852e9ff311b18a1c3d26c914624e1aebc01f3b1e Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Tue, 15 Aug 2023 14:19:36 +0100 Subject: [PATCH 49/82] Accessory checkin via API reported wrong target user --- app/Http/Controllers/Api/AccessoriesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index 263bd2086f..654f3c2e24 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -331,7 +331,7 @@ class AccessoriesController extends Controller $accessory = Accessory::find($accessory_user->accessory_id); $this->authorize('checkin', $accessory); - $logaction = $accessory->logCheckin(User::find($accessory_user->user_id), $request->input('note')); + $logaction = $accessory->logCheckin(User::find($accessory_user->assigned_to), $request->input('note')); // Was the accessory updated? if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) { From b607a59875711aaecbced6732912b66232dac1f1 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Wed, 16 Aug 2023 15:04:17 -0600 Subject: [PATCH 50/82] Add query to search default locations in advanced search --- app/Models/Asset.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 95e1c3a166..6792cf2859 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1433,6 +1433,12 @@ class Asset extends Depreciable }); } + if ($fieldname == 'rtd_location') { + $query->whereHas('defaultLoc', function ($query) use ($search_val) { + $query->where('locations.name', 'LIKE', '%'.$search_val.'%'); + }); + } + if ($fieldname =='assigned_to') { $query->whereHasMorph('assignedTo', [User::class], function ($query) use ($search_val) { $query->where(function ($query) use ($search_val) { From a62876d4bcc704911938c42b364850731d01438b Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 17 Aug 2023 16:14:01 -0700 Subject: [PATCH 51/82] 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 da2f22d5049a79191fb63c0c7fc7fb2c7e8584a8 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 18 Aug 2023 15:31:15 +0100 Subject: [PATCH 52/82] Fixed #13487 - include supplier url in listing Signed-off-by: snipe --- app/Http/Controllers/Api/SuppliersController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/SuppliersController.php b/app/Http/Controllers/Api/SuppliersController.php index a26c33b1f8..ad1227cc83 100644 --- a/app/Http/Controllers/Api/SuppliersController.php +++ b/app/Http/Controllers/Api/SuppliersController.php @@ -41,7 +41,7 @@ class SuppliersController extends Controller ]; $suppliers = Supplier::select( - ['id', 'name', 'address', 'address2', 'city', 'state', 'country', 'fax', 'phone', 'email', 'contact', 'created_at', 'updated_at', 'deleted_at', 'image', 'notes']) + ['id', 'name', 'address', 'address2', 'city', 'state', 'country', 'fax', 'phone', 'email', 'contact', 'created_at', 'updated_at', 'deleted_at', 'image', 'notes', 'url']) ->withCount('assets as assets_count') ->withCount('licenses as licenses_count') ->withCount('accessories as accessories_count') From 0cb76a049a91457da70d29c362baf784d27720d4 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 18 Aug 2023 18:13:16 +0100 Subject: [PATCH 53/82] Make sure the columns and rows can never be 0 Signed-off-by: snipe --- app/Models/Labels/DefaultLabel.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/Models/Labels/DefaultLabel.php b/app/Models/Labels/DefaultLabel.php index 3a7dd5af1c..5043f0b292 100644 --- a/app/Models/Labels/DefaultLabel.php +++ b/app/Models/Labels/DefaultLabel.php @@ -37,7 +37,7 @@ class DefaultLabel extends RectangleSheet private int $columns; private int $rows; - + public function __construct() { $settings = Setting::getSettings(); @@ -62,6 +62,16 @@ class DefaultLabel extends RectangleSheet $this->columns = ($usableWidth + $this->labelSpacingH) / ($this->labelWidth + $this->labelSpacingH); $this->rows = ($usableHeight + $this->labelSpacingV) / ($this->labelHeight + $this->labelSpacingV); + + // Make sure the columns and rows are never zero, since that scenario should never happen + if ($this->columns == 0) { + $this->columns = 1; + } + + if ($this->rows == 0) { + $this->rows = 1; + } + } public function getUnit() { return 'in'; } @@ -85,7 +95,7 @@ class DefaultLabel extends RectangleSheet public function getLabelMarginBottom() { return 0; } public function getLabelMarginLeft() { return 0; } public function getLabelMarginRight() { return 0; } - + public function getLabelColumnSpacing() { return $this->labelSpacingH; } public function getLabelRowSpacing() { return $this->labelSpacingV; } @@ -106,7 +116,7 @@ class DefaultLabel extends RectangleSheet $textY = 0; $textX1 = 0; $textX2 = $this->getLabelWidth(); - + // 1D Barcode if ($record->get('barcode1d')) { static::write1DBarcode( @@ -115,7 +125,7 @@ class DefaultLabel extends RectangleSheet $this->getLabelWidth() - 0.1, self::BARCODE1D_SIZE ); } - + // 2D Barcode if ($record->get('barcode2d')) { static::write2DBarcode( From d56c67141049d6b0d4c99778b920cbf98fe85d78 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 18 Aug 2023 18:39:00 +0100 Subject: [PATCH 54/82] Removed the black label from around the default labels Signed-off-by: snipe --- app/Models/Labels/DefaultLabel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Labels/DefaultLabel.php b/app/Models/Labels/DefaultLabel.php index 5043f0b292..f06c4582f9 100644 --- a/app/Models/Labels/DefaultLabel.php +++ b/app/Models/Labels/DefaultLabel.php @@ -86,7 +86,7 @@ class DefaultLabel extends RectangleSheet public function getColumns() { return $this->columns; } public function getRows() { return $this->rows; } - public function getLabelBorder() { return 0.01; } + public function getLabelBorder() { return 0; } public function getLabelWidth() { return $this->labelWidth; } public function getLabelHeight() { return $this->labelHeight; } From 1dcca14c37f7ed3467dce8523664a4a6292dba38 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 18 Aug 2023 21:21:54 +0100 Subject: [PATCH 55/82] =?UTF-8?q?Values=20are=20not=20sortable,=20so=20don?= =?UTF-8?q?=E2=80=99t=20show=20them=20as=20sortable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Presenters/LabelPresenter.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Presenters/LabelPresenter.php b/app/Presenters/LabelPresenter.php index 5ff95d2c4d..db919e659a 100644 --- a/app/Presenters/LabelPresenter.php +++ b/app/Presenters/LabelPresenter.php @@ -21,7 +21,7 @@ class LabelPresenter extends Presenter ], [ 'field' => 'name', 'searchable' => true, - 'sortable' => true, + 'sortable' => false, 'switchable' => true, 'title' => trans('general.name'), 'visible' => true, @@ -44,14 +44,14 @@ class LabelPresenter extends Presenter ], [ 'field' => 'support_fields', 'searchable' => false, - 'sortable' => true, + 'sortable' => false, 'switchable' => true, 'title' => trans('admin/labels/table.support_fields'), 'visible' => true ], [ 'field' => 'support_asset_tag', 'searchable' => false, - 'sortable' => true, + 'sortable' => false, 'switchable' => true, 'title' => trans('admin/labels/table.support_asset_tag'), 'visible' => true, @@ -59,7 +59,7 @@ class LabelPresenter extends Presenter ], [ 'field' => 'support_1d_barcode', 'searchable' => false, - 'sortable' => true, + 'sortable' => false, 'switchable' => true, 'title' => trans('admin/labels/table.support_1d_barcode'), 'visible' => true, @@ -67,7 +67,7 @@ class LabelPresenter extends Presenter ], [ 'field' => 'support_2d_barcode', 'searchable' => false, - 'sortable' => true, + 'sortable' => false, 'switchable' => true, 'title' => trans('admin/labels/table.support_2d_barcode'), 'visible' => true, @@ -75,7 +75,7 @@ class LabelPresenter extends Presenter ], [ 'field' => 'support_logo', 'searchable' => false, - 'sortable' => true, + 'sortable' => false, 'switchable' => true, 'title' => trans('admin/labels/table.support_logo'), 'visible' => true, @@ -83,7 +83,7 @@ class LabelPresenter extends Presenter ], [ 'field' => 'support_title', 'searchable' => false, - 'sortable' => true, + 'sortable' => false, 'switchable' => true, 'title' => trans('admin/labels/table.support_title'), 'visible' => true, From d12f4564e1f1372a14033ea3dade4eade39cdd81 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 18 Aug 2023 21:44:12 +0100 Subject: [PATCH 56/82] Added Dymo Labelwriter template Signed-off-by: snipe --- app/Models/Labels/Tapes/Dymo/LabelWriter.php | 19 ++++ .../Labels/Tapes/Dymo/LabelWriter_30252.php | 90 +++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 app/Models/Labels/Tapes/Dymo/LabelWriter.php create mode 100644 app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php diff --git a/app/Models/Labels/Tapes/Dymo/LabelWriter.php b/app/Models/Labels/Tapes/Dymo/LabelWriter.php new file mode 100644 index 0000000000..fa427fd213 --- /dev/null +++ b/app/Models/Labels/Tapes/Dymo/LabelWriter.php @@ -0,0 +1,19 @@ +getUnit()); } + public function getMarginTop() { return Helper::convertUnit(self::MARGIN_SIDES, 'in', $this->getUnit()); } + public function getMarginBottom() { return Helper::convertUnit(self::MARGIN_SIDES, 'in', $this->getUnit());} + public function getMarginLeft() { return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit()); } + public function getMarginRight() { return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit()); } +} \ No newline at end of file diff --git a/app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php b/app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php new file mode 100644 index 0000000000..1b34eb113a --- /dev/null +++ b/app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php @@ -0,0 +1,90 @@ +getPrintableArea(); + + $currentX = $pa->x1; + $currentY = $pa->y1; + $usableWidth = $pa->w; + + $barcodeSize = $pa->h - self::TAG_SIZE; + + if ($record->has('barcode2d')) { + static::writeText( + $pdf, $record->get('tag'), + $pa->x1, $pa->y2 - self::TAG_SIZE, + 'freemono', 'b', self::TAG_SIZE, 'C', + $barcodeSize, self::TAG_SIZE, true, 0 + ); + static::write2DBarcode( + $pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type, + $currentX, $currentY, + $barcodeSize, $barcodeSize + ); + $currentX += $barcodeSize + self::BARCODE_MARGIN; + $usableWidth -= $barcodeSize + self::BARCODE_MARGIN; + } else { + static::writeText( + $pdf, $record->get('tag'), + $pa->x1, $pa->y2 - self::TAG_SIZE, + 'freemono', 'b', self::TAG_SIZE, 'R', + $usableWidth, self::TAG_SIZE, true, 0 + ); + } + + if ($record->has('title')) { + static::writeText( + $pdf, $record->get('title'), + $currentX, $currentY, + 'freesans', '', self::TITLE_SIZE, 'L', + $usableWidth, self::TITLE_SIZE, true, 0 + ); + $currentY += self::TITLE_SIZE + self::TITLE_MARGIN; + } + + foreach ($record->get('fields') as $field) { + static::writeText( + $pdf, $field['label'], + $currentX, $currentY, + 'freesans', '', self::LABEL_SIZE, 'L', + $usableWidth, self::LABEL_SIZE, true, 0, 0 + ); + $currentY += self::LABEL_SIZE + self::LABEL_MARGIN; + + static::writeText( + $pdf, $field['value'], + $currentX, $currentY, + 'freemono', 'B', self::FIELD_SIZE, 'L', + $usableWidth, self::FIELD_SIZE, true, 0, 0.3 + ); + $currentY += self::FIELD_SIZE + self::FIELD_MARGIN; + } + } +} \ No newline at end of file From 1e82c2bfadef0a43e01c3211d23f9cc704bca745 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 18 Aug 2023 22:17:54 +0100 Subject: [PATCH 57/82] Changed example asset name Signed-off-by: snipe --- app/Http/Controllers/LabelsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php index 97608cb5e2..3e29323cb5 100755 --- a/app/Http/Controllers/LabelsController.php +++ b/app/Http/Controllers/LabelsController.php @@ -30,7 +30,7 @@ class LabelsController extends Controller $exampleAsset = new Asset(); $exampleAsset->id = 999999; - $exampleAsset->name = 'AST-AB-CD-1234'; + $exampleAsset->name = 'JEN-867-5309'; $exampleAsset->asset_tag = 'TCA-00001'; $exampleAsset->serial = 'SN9876543210'; From ffc7c4e99a9e14e6a2a2ce3dc2d7543f639fd39c Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 18 Aug 2023 22:18:09 +0100 Subject: [PATCH 58/82] use number format to constrain large number displays Signed-off-by: snipe --- app/Http/Transformers/LabelsTransformer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Transformers/LabelsTransformer.php b/app/Http/Transformers/LabelsTransformer.php index 8e0e8ca44e..0ed5a09686 100644 --- a/app/Http/Transformers/LabelsTransformer.php +++ b/app/Http/Transformers/LabelsTransformer.php @@ -26,8 +26,8 @@ class LabelsTransformer 'name' => $label->getName(), 'unit' => $label->getUnit(), - 'width' => $label->getWidth(), - 'height' => $label->getHeight(), + 'width' => number_format($label->getWidth(), 2), + 'height' => number_format($label->getHeight(), 2), 'margin_top' => $label->getMarginTop(), 'margin_bottom' => $label->getMarginBottom(), From 45898deb1a194a59c9ca150b5d77585d97afd567 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 18 Aug 2023 22:18:38 +0100 Subject: [PATCH 59/82] =?UTF-8?q?Don=E2=80=99t=20500=20if=20the=201D=20bar?= =?UTF-8?q?code=20doesn=E2=80=99t=20match=20the=20format=20requested=20-?= =?UTF-8?q?=20log=20an=20error=20instead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Models/Labels/Label.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Models/Labels/Label.php b/app/Models/Labels/Label.php index ff759ac544..9b48a7e730 100644 --- a/app/Models/Labels/Label.php +++ b/app/Models/Labels/Label.php @@ -370,7 +370,11 @@ abstract class Label */ public final function write1DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width, $height) { if (empty($value)) return; - $pdf->write1DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch'=>true]); + try { + $pdf->write1DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch'=>true]); + } catch (\Exception $e) { + \Log::error('The 1D barcode ' . $value . ' is not compliant with the barcode type '. $type); + } } /** From 749002b76862e80ee8f2b32551c78ad8511569bc Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Aug 2023 20:09:48 +0100 Subject: [PATCH 60/82] Added migration to add name order to settings Signed-off-by: snipe --- ...1_064609_add_name_ordering_to_settings.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/2023_08_21_064609_add_name_ordering_to_settings.php diff --git a/database/migrations/2023_08_21_064609_add_name_ordering_to_settings.php b/database/migrations/2023_08_21_064609_add_name_ordering_to_settings.php new file mode 100644 index 0000000000..7a0afc5456 --- /dev/null +++ b/database/migrations/2023_08_21_064609_add_name_ordering_to_settings.php @@ -0,0 +1,32 @@ +string('name_display_format', 10)->after('alert_threshold')->nullable()->default('first_last'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('settings', function (Blueprint $table) { + $table->dropColumn('name_display_format'); + }); + } +} From 474c03e3fcc48889d7616d01d51d5f9b794832d7 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Aug 2023 20:10:03 +0100 Subject: [PATCH 61/82] Added name order to settings save controller method Signed-off-by: snipe --- app/Http/Controllers/SettingsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 497ab7cea6..7a7aa45b6e 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -590,6 +590,7 @@ class SettingsController extends Controller $setting->date_display_format = $request->input('date_display_format'); $setting->time_display_format = $request->input('time_display_format'); $setting->digit_separator = $request->input('digit_separator'); + $setting->name_display_format = $request->input('name_display_format'); if ($setting->save()) { return redirect()->route('settings.index') From f3460b5a4f33713be8b655937bc27975d86840af Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Aug 2023 20:10:48 +0100 Subject: [PATCH 62/82] Switch to getFullNameAttribute() in user transformer Signed-off-by: snipe --- app/Http/Transformers/UsersTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php index 76c0288073..45de50fa7d 100644 --- a/app/Http/Transformers/UsersTransformer.php +++ b/app/Http/Transformers/UsersTransformer.php @@ -24,7 +24,7 @@ class UsersTransformer $array = [ 'id' => (int) $user->id, 'avatar' => e($user->present()->gravatar), - 'name' => e($user->first_name).' '.e($user->last_name), + 'name' => e($user->getFullNameAttribute()), 'first_name' => e($user->first_name), 'last_name' => e($user->last_name), 'username' => e($user->username), From 354550b52e830d5c139ef259c1c9a03838aaa2ef Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Aug 2023 20:11:17 +0100 Subject: [PATCH 63/82] Removed getCompleteNameAttribute(), modified getFullNameAttribute() Signed-off-by: snipe --- app/Models/User.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 98a3ec346b..0d49b977c4 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -247,21 +247,12 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo */ public function getFullNameAttribute() { - return $this->first_name.' '.$this->last_name; - } + $setting = Setting::getSettings(); - /** - * Returns the complete name attribute with username - * - * @todo refactor this so it's less repetitive and dumb - * - * @author A. Gianotto - * @since [v2.0] - * @return string - */ - public function getCompleteNameAttribute() - { - return $this->last_name.', '.$this->first_name.' ('.$this->username.')'; + if ($setting->name_display_format=='last_first') { + return ($this->last_name) ? $this->last_name.' '.$this->first_name : $this->first_name; + } + return $this->last_name ? $this->first_name.' '.$this->last_name : $this->first_name; } From c39579b1701d3907f483bc5336c4f58c362365b6 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Aug 2023 20:11:25 +0100 Subject: [PATCH 64/82] New strings Signed-off-by: snipe --- resources/lang/en/general.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 4831845721..1b60951d29 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -120,6 +120,10 @@ return [ 'firstname_lastname_underscore_format' => 'First Name Last Name (jane_smith@example.com)', 'lastnamefirstinitial_format' => 'Last Name First Initial (smithj@example.com)', 'firstintial_dot_lastname_format' => 'First Initial Last Name (j.smith@example.com)', + 'firstname_lastname_display' => 'First Name Last Name (Jane Smith)', + 'lastname_firstname_display' => 'Last Name First Name (Smith Jane)', + 'name_display_format' => 'Name Display Format', + 'name_display_help' => 'This is generally only used in countries where it is common to write ', 'first' => 'First', 'firstnamelastname' => 'First Name Last Name (janesmith@example.com)', 'lastname_firstinitial' => 'Last Name First Initial (smith_j@example.com)', From 8660d41aa369857db0b6b7b3e91d5d1c18ceb77e Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Aug 2023 20:11:45 +0100 Subject: [PATCH 65/82] Changed width of locale field Signed-off-by: snipe --- resources/macros/macros.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/macros/macros.php b/resources/macros/macros.php index 43dc2cc2e0..92c8ecedac 100644 --- a/resources/macros/macros.php +++ b/resources/macros/macros.php @@ -11,7 +11,7 @@ Form::macro('locales', function ($name = 'locale', $selected = null, $class = nu $idclause = (!is_null($id)) ? $id : ''; - $select = ''; $select .= ''; // Pull the autoglossonym array from the localizations translation file From d73d15b8a2436ef3de45592d93cb42eb50a9bae6 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Aug 2023 20:11:59 +0100 Subject: [PATCH 66/82] Added form macro for name format Signed-off-by: snipe --- resources/macros/macros.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/resources/macros/macros.php b/resources/macros/macros.php index 92c8ecedac..c5c7824edc 100644 --- a/resources/macros/macros.php +++ b/resources/macros/macros.php @@ -109,6 +109,23 @@ Form::macro('digit_separator', function ($name = 'digit_separator', $selected = return $select; }); + +Form::macro('name_display_format', function ($name = 'name_display_format', $selected = null, $class = null) { + $formats = [ + 'first_last' => trans('general.firstname_lastname_display'), + 'last_first' => trans('general.lastname_firstname_display'), + ]; + + $select = ''; + + return $select; +}); + /** * Barcode macro * Generates the dropdown menu of available 1D barcodes From bfd674b622d08b50c59b8a86a7363b4567ef40a2 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Aug 2023 20:12:25 +0100 Subject: [PATCH 67/82] Switched to getFullNameAttribute() from fullName() in User Presenter Signed-off-by: snipe --- app/Presenters/UserPresenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index 080a2d10e9..f70ddf8af6 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -433,7 +433,7 @@ class UserPresenter extends Presenter */ public function nameUrl() { - return (string) link_to_route('users.show', $this->fullName(), $this->id); + return (string) link_to_route('users.show', $this->getFullNameAttribute(), $this->id); } /** From ba0643f6a40e422113d3f9394f4ef02b281dbf9c Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Aug 2023 20:13:28 +0100 Subject: [PATCH 68/82] Added name display format, tweaked some Signed-off-by: snipe --- .../views/settings/localization.blade.php | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/resources/views/settings/localization.blade.php b/resources/views/settings/localization.blade.php index a74387b32d..4f800511f1 100644 --- a/resources/views/settings/localization.blade.php +++ b/resources/views/settings/localization.blade.php @@ -42,26 +42,39 @@

-
+
{{ Form::label('site_name', trans('admin/settings/general.default_language')) }}
-
+
{!! Form::locales('locale', Request::old('locale', $setting->locale), 'select2') !!} {!! $errors->first('locale', '') !!}
+ +
+
+ {{ Form::label('name_display_format', trans('general.name_display_format')) }} +
+
+ {!! Form::name_display_format('name_display_format', Request::old('name_display_format', $setting->name_display_format), 'select2') !!} + + {!! $errors->first('name_display_format', '') !!} +
+
+ +
-
+
{{ Form::label('time_display_format', trans('general.time_and_date_display')) }}
-
+
{!! Form::date_display_format('date_display_format', Request::old('date_display_format', $setting->date_display_format), 'select2') !!}
-
+
{!! Form::time_display_format('time_display_format', Request::old('time_display_format', $setting->time_display_format), 'select2') !!}
@@ -71,10 +84,10 @@
-
+
{{ Form::label('default_currency', trans('admin/settings/general.default_currency')) }}
-
+
{{ Form::text('default_currency', old('default_currency', $setting->default_currency), array('class' => 'form-control select2-container','placeholder' => 'USD', 'maxlength'=>'3', 'style'=>'width: 60px; display: inline-block; ')) }} {!! Form::digit_separator('digit_separator', old('digit_separator', $setting->digit_separator), 'select2') !!} @@ -84,9 +97,6 @@
- - -
From c617bf89b6d5202ff9f0c430d159066cd4158adf Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Aug 2023 20:13:45 +0100 Subject: [PATCH 69/82] Tweak layout Signed-off-by: snipe --- resources/views/account/profile.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/account/profile.blade.php b/resources/views/account/profile.blade.php index 2c3158c88f..a42c91e7a1 100755 --- a/resources/views/account/profile.blade.php +++ b/resources/views/account/profile.blade.php @@ -46,7 +46,7 @@
-
+
@if (!config('app.lock_passwords')) {!! Form::locales('locale', old('locale', $user->locale), 'select2') !!} From 36a343365e7777f4b914e1fa67a6d09e1bd067af Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Aug 2023 20:14:07 +0100 Subject: [PATCH 70/82] Switched from fullName() to getFullNameAttribute() Signed-off-by: snipe --- resources/views/account/view-assets.blade.php | 2 +- resources/views/layouts/default.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index b77bddcf0d..10b09602ab 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') -{{ trans('general.hello_name', array('name' => $user->present()->fullName())) }} +{{ trans('general.hello_name', array('name' => $user->present()->getFullNameAttribute())) }} @parent @stop diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 13a65bf28b..a9f547f4f5 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -328,7 +328,7 @@ @endif -