Pull image formatter out of dynamic loop, pass full url to formatter

This commit is contained in:
snipe 2017-01-24 22:46:07 -08:00
parent 04bb180a80
commit 75d35273c9
6 changed files with 24 additions and 13 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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
*/

View file

@ -75,7 +75,7 @@
@endif
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
<th data-field="companyName" data-formatter="companiesLinkObjFormatter" data-searchable="true" data-sortable="true" data-switchable="true" data-visible="false">{{ trans('general.company') }}</th>
<th data-sortable="true" data-field="image" data-visible="false">{{ trans('admin/hardware/table.image') }}</th>
<th data-sortable="true" data-field="image" data-formatter="imageFormatter" data-visible="false">{{ trans('admin/hardware/table.image') }}</th>
<th data-sortable="true" data-field="name" data-visible="false" data-formatter="hardwareLinkFormatter">{{ trans('admin/hardware/form.name') }}</th>
<th data-sortable="true" data-field="asset_tag" data-formatter="hardwareLinkFormatter">{{ trans('admin/hardware/table.asset_tag') }}</th>
<th data-sortable="true" data-field="serial" data-formatter="hardwareLinkFormatter">{{ trans('admin/hardware/table.serial') }}</th>

View file

@ -38,7 +38,7 @@
<tr>
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
<th data-sortable="true" data-field="name" data-formatter="modelsLinkFormatter">{{ trans('general.name') }}</th>
<th data-sortable="true" data-field="image" data-formatter="modelsImageFormatter" data-visible="false">{{ trans('admin/hardware/table.image') }}</th>
<th data-sortable="true" data-field="image" data-formatter="imageFormatter" data-visible="false">{{ trans('admin/hardware/table.image') }}</th>
<th data-sortable="false" data-field="manufacturer" data-formatter="manufacturersLinkObjFormatter">{{ trans('general.manufacturer') }}</th>
<th data-sortable="true" data-field="model_number">{{ trans('admin/models/table.modelnumber') }}</th>

View file

@ -115,13 +115,7 @@ $('.snipe-table').bootstrapTable({
};
}
function genericPublicImageFormatter(destination) {
return function (value,row) {
if (value) {
return '<img src="{{ url('/') }}/uploads/' + destination + '/' + value + '" height="50" width="50">';
}
}
}
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 '<img src="' + value + '" height="50" width="50">';
}
}
$(function () {
$('#bulkEdit').click(function () {
var selectedIds = $('.snipe-table').bootstrapTable('getSelections');