From 6dd7181d09dd2d794085ffb69d1beb70331c51c8 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 12 Jun 2023 12:10:19 -0700 Subject: [PATCH 1/6] fixed audit log image not appearing --- app/Presenters/AssetAuditPresenter.php | 4 ++-- resources/views/partials/bootstrap-table.blade.php | 8 ++++++-- resources/views/reports/audit.blade.php | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Presenters/AssetAuditPresenter.php b/app/Presenters/AssetAuditPresenter.php index 2c25a6aa06..a332950de1 100644 --- a/app/Presenters/AssetAuditPresenter.php +++ b/app/Presenters/AssetAuditPresenter.php @@ -44,13 +44,13 @@ class AssetAuditPresenter extends Presenter 'visible' => true, 'formatter' => 'hardwareLinkFormatter', ], [ - 'field' => 'image', + 'field' => 'file', 'searchable' => false, 'sortable' => true, 'switchable' => true, 'title' => trans('admin/hardware/table.image'), 'visible' => false, - 'formatter' => 'imageFormatter', + 'formatter' => 'auditImageFormatter', ], [ 'field' => 'asset_tag', 'searchable' => true, diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index 0a4ac1b031..473110fbf5 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -652,11 +652,15 @@ } } + function auditImageFormatter(value){ + if (value){ + return '' + } + } + function imageFormatter(value, row) { - - if (value) { // This is a clunky override to handle unusual API responses where we're presenting a link instead of an array diff --git a/resources/views/reports/audit.blade.php b/resources/views/reports/audit.blade.php index 15ad80964d..3d16b0714b 100644 --- a/resources/views/reports/audit.blade.php +++ b/resources/views/reports/audit.blade.php @@ -34,7 +34,7 @@ - {{ trans('admin/hardware/table.image') }} + {{ trans('admin/hardware/table.image') }} {{ trans('general.audit') }} {{ trans('general.admin') }} {{ trans('general.item') }} From 2d9ddab3f00f7bf848521a78b2b1e025c1e4ea0b Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 21 Jun 2023 09:24:17 +0100 Subject: [PATCH 2/6] Moved logic for tighter constraints when ids are passed Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 119 +++++++++--------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index ced1f013c6..97f2f9eab9 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -136,66 +136,7 @@ class AssetsController extends Controller } } - if ($request->filled('status_id')) { - $assets->where('assets.status_id', '=', $request->input('status_id')); - } - if ($request->filled('asset_tag')) { - $assets->where('assets.asset_tag', '=', $request->input('asset_tag')); - } - - if ($request->filled('serial')) { - $assets->where('assets.serial', '=', $request->input('serial')); - } - - if ($request->input('requestable') == 'true') { - $assets->where('assets.requestable', '=', '1'); - } - - if ($request->filled('model_id')) { - $assets->InModelList([$request->input('model_id')]); - } - - if ($request->filled('category_id')) { - $assets->InCategory($request->input('category_id')); - } - - if ($request->filled('location_id')) { - $assets->where('assets.location_id', '=', $request->input('location_id')); - } - - if ($request->filled('rtd_location_id')) { - $assets->where('assets.rtd_location_id', '=', $request->input('rtd_location_id')); - } - - if ($request->filled('supplier_id')) { - $assets->where('assets.supplier_id', '=', $request->input('supplier_id')); - } - - if ($request->filled('asset_eol_date')) { - $assets->where('assets.asset_eol_date', '=', $request->input('asset_eol_date')); - } - - if (($request->filled('assigned_to')) && ($request->filled('assigned_type'))) { - $assets->where('assets.assigned_to', '=', $request->input('assigned_to')) - ->where('assets.assigned_type', '=', $request->input('assigned_type')); - } - - if ($request->filled('company_id')) { - $assets->where('assets.company_id', '=', $request->input('company_id')); - } - - if ($request->filled('manufacturer_id')) { - $assets->ByManufacturer($request->input('manufacturer_id')); - } - - if ($request->filled('depreciation_id')) { - $assets->ByDepreciationId($request->input('depreciation_id')); - } - - if ($request->filled('byod')) { - $assets->where('assets.byod', '=', $request->input('byod')); - } $request->filled('order_number') ? $assets = $assets->where('assets.order_number', '=', e($request->get('order_number'))) : ''; @@ -300,6 +241,66 @@ class AssetsController extends Controller $assets->TextSearch($request->input('search')); } + if ($request->filled('status_id')) { + $assets->where('assets.status_id', '=', $request->input('status_id')); + } + + if ($request->filled('asset_tag')) { + $assets->where('assets.asset_tag', '=', $request->input('asset_tag')); + } + + if ($request->filled('serial')) { + $assets->where('assets.serial', '=', $request->input('serial')); + } + + if ($request->input('requestable') == 'true') { + $assets->where('assets.requestable', '=', '1'); + } + + if ($request->filled('model_id')) { + $assets->InModelList([$request->input('model_id')]); + } + + if ($request->filled('category_id')) { + $assets->InCategory($request->input('category_id')); + } + + if ($request->filled('location_id')) { + $assets->where('assets.location_id', '=', $request->input('location_id')); + } + + if ($request->filled('rtd_location_id')) { + $assets->where('assets.rtd_location_id', '=', $request->input('rtd_location_id')); + } + + if ($request->filled('supplier_id')) { + $assets->where('assets.supplier_id', '=', $request->input('supplier_id')); + } + + if ($request->filled('asset_eol_date')) { + $assets->where('assets.asset_eol_date', '=', $request->input('asset_eol_date')); + } + + if (($request->filled('assigned_to')) && ($request->filled('assigned_type'))) { + $assets->where('assets.assigned_to', '=', $request->input('assigned_to')) + ->where('assets.assigned_type', '=', $request->input('assigned_type')); + } + + if ($request->filled('company_id')) { + $assets->where('assets.company_id', '=', $request->input('company_id')); + } + + if ($request->filled('manufacturer_id')) { + $assets->ByManufacturer($request->input('manufacturer_id')); + } + + if ($request->filled('depreciation_id')) { + $assets->ByDepreciationId($request->input('depreciation_id')); + } + + if ($request->filled('byod')) { + $assets->where('assets.byod', '=', $request->input('byod')); + } // This is kinda gross, but we need to do this because the Bootstrap Tables // API passes custom field ordering as custom_fields.fieldname, and we have to strip From 5d4e704fac36a0b2c916bb88841a9db46bd4c2bb Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 21 Jun 2023 09:26:54 +0100 Subject: [PATCH 3/6] Added a comment Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 97f2f9eab9..bd64ae8c98 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -241,6 +241,7 @@ class AssetsController extends Controller $assets->TextSearch($request->input('search')); } + // Leave these under the TextSearch scope, else the fuzziness will override the specific ID (status ID, etc) requested if ($request->filled('status_id')) { $assets->where('assets.status_id', '=', $request->input('status_id')); } From 67e47a7d8b44ed4575ae3f10044160c1c8cd775d Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 22 Jun 2023 13:53:58 -0600 Subject: [PATCH 4/6] Add guard clause to obtain the default ID of imported asset's status label --- app/Importer/AssetImporter.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index e8da1e06b4..be19455618 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -12,7 +12,10 @@ class AssetImporter extends ItemImporter public function __construct($filename) { parent::__construct($filename); - $this->defaultStatusLabelId = Statuslabel::first()->id; + + if (!is_null(Statuslabel::first())) { + $this->defaultStatusLabelId = Statuslabel::first()->id; + } } protected function handle($row) From 78d8e32a22422f4b473752160a3f3a6a60c80dd0 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 22 Jun 2023 21:16:24 +0100 Subject: [PATCH 5/6] Fixed weird order number thing Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index bd64ae8c98..16cef00d4d 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -137,9 +137,6 @@ class AssetsController extends Controller } - - $request->filled('order_number') ? $assets = $assets->where('assets.order_number', '=', e($request->get('order_number'))) : ''; - // Make sure the offset and limit are actually integers and do not exceed system limits $offset = ($request->input('offset') > $assets->count()) ? $assets->count() : abs($request->input('offset')); $limit = app('api_limit_value'); @@ -303,6 +300,10 @@ class AssetsController extends Controller $assets->where('assets.byod', '=', $request->input('byod')); } + if ($request->filled('order_number')) { + $assets->where('assets.order_number', '=', $request->get('order_number')); + } + // This is kinda gross, but we need to do this because the Bootstrap Tables // API passes custom field ordering as custom_fields.fieldname, and we have to strip // that out to let the default sorter below order them correctly on the assets table. From 4f7b2836b54817966e56b0f7ca789060c3a0c3fc Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 26 Jun 2023 08:27:17 +0100 Subject: [PATCH 6/6] Set table alias for model number sort scope Signed-off-by: snipe --- app/Models/Asset.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 1d7595e5d9..c716b77d1e 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1566,7 +1566,7 @@ class Asset extends Depreciable */ public function scopeOrderModelNumber($query, $order) { - return $query->join('models', 'assets.model_id', '=', 'models.id')->orderBy('models.model_number', $order); + return $query->leftJoin('models as model_number_sort', 'assets.model_id', '=', 'models.id')->orderBy('models.model_number', $order); }