From 75d35273c968af94584dc4420bb95ceb3644a3a9 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Jan 2017 22:46:07 -0800 Subject: [PATCH] Pull image formatter out of dynamic loop, pass full url to formatter --- app/Http/Transformers/AssetModelsTransformer.php | 2 +- app/Http/Transformers/AssetsTransformer.php | 4 ++-- app/Models/Asset.php | 11 +++++++++++ resources/views/hardware/index.blade.php | 2 +- resources/views/models/index.blade.php | 2 +- .../views/partials/bootstrap-table.blade.php | 16 ++++++++-------- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/Http/Transformers/AssetModelsTransformer.php b/app/Http/Transformers/AssetModelsTransformer.php index 57fc05e928..e23f5ecbc7 100644 --- a/app/Http/Transformers/AssetModelsTransformer.php +++ b/app/Http/Transformers/AssetModelsTransformer.php @@ -22,7 +22,7 @@ class AssetModelsTransformer 'id' => $assetmodel->id, 'name' => e($assetmodel->name), 'manufacturer' => ($assetmodel->manufacturer_id) ? $assetmodel->manufacturer : null, - 'image' => e($assetmodel->image), + 'image' => ($assetmodel->image!='') ? url('/').'/uploads/models/'.e($assetmodel->image) : '', 'model_number' => e($assetmodel->model_number), 'depreciation' => ($assetmodel->depreciation) ? $assetmodel->depreciation : 'No', 'assets_count' => $assetmodel->assets_count, diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index 8338e79d68..acc21185b1 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -34,8 +34,8 @@ class AssetsTransformer 'expected_checkin' => $asset->expected_checkin, 'order_number' => $asset->order_number, 'companyName' => $asset->companyName, - 'location' => ($asset->assetLoc) ? $asset->assetLoc : '', - 'image' => $asset->image, + 'location' => ($asset->assetLoc) ? $asset->assetLoc : null, + 'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null, 'assigned_to' => ($asset->assigneduser) ? (new UsersTransformer)->transformUser($asset->assigneduser) : null, 'created_at' => $asset->created_at, 'purchase_date' => $asset->purchase_date, diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 1e78890cb5..ad0bc1c50d 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -271,6 +271,17 @@ class Asset extends Depreciable return $this->belongsTo('\App\Models\Location', 'rtd_location_id'); } + + public function getImageUrl() { + if ($this->image && !empty($this->image)) { + return url('/').'/uploads/assets/'.$this->image; + } elseif ($this->model && !empty($this->model->image)) { + return url('/').'/uploads/models/'.$this->model->image; + } + return false; + } + + /** * Get action logs for this asset */ diff --git a/resources/views/hardware/index.blade.php b/resources/views/hardware/index.blade.php index 896655e9c7..7427351194 100755 --- a/resources/views/hardware/index.blade.php +++ b/resources/views/hardware/index.blade.php @@ -75,7 +75,7 @@ @endif {{ trans('general.id') }} {{ trans('general.company') }} - {{ trans('admin/hardware/table.image') }} + {{ trans('admin/hardware/table.image') }} {{ trans('admin/hardware/form.name') }} {{ trans('admin/hardware/table.asset_tag') }} {{ trans('admin/hardware/table.serial') }} diff --git a/resources/views/models/index.blade.php b/resources/views/models/index.blade.php index f3085ed9de..ae6bdf69bd 100755 --- a/resources/views/models/index.blade.php +++ b/resources/views/models/index.blade.php @@ -38,7 +38,7 @@ {{ trans('general.id') }} {{ trans('general.name') }} - {{ trans('admin/hardware/table.image') }} + {{ trans('admin/hardware/table.image') }} {{ trans('general.manufacturer') }} {{ trans('admin/models/table.modelnumber') }} diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index 851b2eb055..d98699831d 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -115,13 +115,7 @@ $('.snipe-table').bootstrapTable({ }; } - function genericPublicImageFormatter(destination) { - return function (value,row) { - if (value) { - return ''; - } - } - } + var formatters = [ 'hardware', @@ -142,7 +136,6 @@ $('.snipe-table').bootstrapTable({ window[formatters[i] + 'LinkFormatter'] = genericRowLinkFormatter(formatters[i]); window[formatters[i] + 'LinkObjFormatter'] = genericColumnObjLinkFormatter(formatters[i]); window[formatters[i] + 'ActionsFormatter'] = genericActionsFormatter(formatters[i]); - window[formatters[i] + 'ImageFormatter'] = genericPublicImageFormatter(formatters[i]); } @@ -168,6 +161,13 @@ $('.snipe-table').bootstrapTable({ } } + function imageFormatter(value, row) { + console.log(value); + if (value) { + return ''; + } + } + $(function () { $('#bulkEdit').click(function () { var selectedIds = $('.snipe-table').bootstrapTable('getSelections');