mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
More bootstrap tables formatting
This commit is contained in:
parent
8f12486f6c
commit
04bb180a80
|
@ -5,7 +5,7 @@ use App\Models\AssetModel;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Helpers\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Transformers\DatatablesTransformer;
|
||||
use App\Http\Transformers\AssetModelsTransformer;
|
||||
|
||||
/**
|
||||
* This class controls all actions related to asset models for
|
||||
|
@ -28,7 +28,7 @@ class AssetModelsController extends Controller
|
|||
$this->authorize('view', AssetModel::class);
|
||||
$allowed_columns = ['id','image','name','model_number','eol','notes','created_at'];
|
||||
|
||||
$assetmodels = AssetModel::select(['id','image','name','model_number','eol','notes','created_at'])
|
||||
$assetmodels = AssetModel::select(['id','image','name','model_number','eol','notes','created_at','category_id','manufacturer_id','depreciation_id','fieldset_id'])
|
||||
->with('category','depreciation', 'manufacturer','fieldset')
|
||||
->withCount('assets');
|
||||
|
||||
|
@ -44,7 +44,7 @@ class AssetModelsController extends Controller
|
|||
|
||||
$total = $assetmodels->count();
|
||||
$assetmodels = $assetmodels->skip($offset)->take($limit)->get();
|
||||
return (new DatatablesTransformer)->transformDatatables($assetmodels, $total);
|
||||
return (new AssetModelsTransformer)->transformAssetModels($assetmodels, $total);
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,7 +81,7 @@ class AssetModelsController extends Controller
|
|||
{
|
||||
$this->authorize('view', AssetModel::class);
|
||||
$assetmodel = AssetModel::findOrFail($id);
|
||||
return $assetmodel;
|
||||
return (new AssetModelsTransformer)->transformAssetModel($assetmodel);
|
||||
}
|
||||
|
||||
|
||||
|
|
43
app/Http/Transformers/AssetModelsTransformer.php
Normal file
43
app/Http/Transformers/AssetModelsTransformer.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
namespace App\Http\Transformers;
|
||||
|
||||
use App\Models\AssetModel;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class AssetModelsTransformer
|
||||
{
|
||||
|
||||
public function transformAssetModels (Collection $assetmodels, $total)
|
||||
{
|
||||
$array = array();
|
||||
foreach ($assetmodels as $assetmodel) {
|
||||
$array[] = self::transformAssetModel($assetmodel);
|
||||
}
|
||||
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||
}
|
||||
|
||||
public function transformAssetModel (AssetModel $assetmodel)
|
||||
{
|
||||
$transformed = [
|
||||
'id' => $assetmodel->id,
|
||||
'name' => e($assetmodel->name),
|
||||
'manufacturer' => ($assetmodel->manufacturer_id) ? $assetmodel->manufacturer : null,
|
||||
'image' => e($assetmodel->image),
|
||||
'model_number' => e($assetmodel->model_number),
|
||||
'depreciation' => ($assetmodel->depreciation) ? $assetmodel->depreciation : 'No',
|
||||
'assets_count' => $assetmodel->assets_count,
|
||||
'category' => ($assetmodel->category_id) ? $assetmodel->category : null,
|
||||
'fieldset' => ($assetmodel->fieldset) ? $assetmodel->fieldset : null,
|
||||
'eol' => ($assetmodel->eol > 0) ? $assetmodel->eol .' months': 'None',
|
||||
'notes' => e($assetmodel->notes),
|
||||
|
||||
];
|
||||
return $transformed;
|
||||
}
|
||||
|
||||
public function transformAssetModelsDatatable($assetmodels) {
|
||||
return (new DatatablesTransformer)->transformDatatables($assetmodels);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -26,10 +26,10 @@ class AssetsTransformer
|
|||
'serial' => $asset->serial,
|
||||
'model' => ($asset->model) ? $asset->model : '',
|
||||
'model_number' => $asset->model_number,
|
||||
'status_label' => ($asset->assetstatus) ? $asset->assetstatus : '',
|
||||
'status_label' => ($asset->assetstatus) ? $asset->assetstatus : null,
|
||||
'last_checkout' => $asset->last_checkout,
|
||||
'category' => ($asset->model->category) ? $asset->model->category : '',
|
||||
'manufacturer' => $asset->manufacturer,
|
||||
'category' => ($asset->model->category) ? $asset->model->category : null,
|
||||
'manufacturer' => ($asset->model->manufacturer) ? $asset->model->manufacturer : null,
|
||||
'notes' => $asset->notes,
|
||||
'expected_checkin' => $asset->expected_checkin,
|
||||
'order_number' => $asset->order_number,
|
||||
|
|
|
@ -21,6 +21,7 @@ class AssetModel extends SnipeModel
|
|||
use Requestable, Presentable;
|
||||
protected $dates = ['deleted_at'];
|
||||
protected $table = 'models';
|
||||
protected $hidden = ['user_id','deleted_at'];
|
||||
|
||||
// Declare the rules for the model validation
|
||||
protected $rules = array(
|
||||
|
|
|
@ -23,6 +23,7 @@ class Category extends SnipeModel
|
|||
use SoftDeletes;
|
||||
protected $dates = ['deleted_at'];
|
||||
protected $table = 'categories';
|
||||
protected $hidden = ['user_id','deleted_at'];
|
||||
|
||||
/**
|
||||
* Category validation rules
|
||||
|
|
|
@ -19,6 +19,10 @@ class Manufacturer extends SnipeModel
|
|||
'user_id' => 'integer',
|
||||
);
|
||||
|
||||
protected $hidden = ['user_id','deleted_at'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Whether the model should inject it's identifier to the unique
|
||||
* validation rules before attempting validation. If this property
|
||||
|
|
|
@ -16,6 +16,7 @@ class Statuslabel extends SnipeModel
|
|||
protected $injectUniqueIdentifier = true;
|
||||
protected $dates = ['deleted_at'];
|
||||
protected $table = 'status_labels';
|
||||
protected $hidden = ['user_id','deleted_at'];
|
||||
|
||||
|
||||
protected $rules = array(
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<th data-sortable="true" data-formatter="usersLinkObjFormatter" data-field="assigned_to">{{ trans('admin/hardware/form.checkedout_to') }}</th>
|
||||
<th data-sortable="true" data-formatter="locationsLinkObjFormatter" data-field="location" data-searchable="true">{{ trans('admin/hardware/table.location') }}</th>
|
||||
<th data-sortable="true" data-field="category" data-searchable="true" data-formatter="categoriesLinkObjFormatter">{{ trans('general.category') }}</th>
|
||||
<th data-sortable="true" data-field="manufacturer" data-formatter="manufacturersLinkObjFormatter" data-searchable="true" data-visible="false">{{ trans('general.manufacturer') }}</th>
|
||||
<th data-sortable="true" data-field="manufacturer" data-formatter="manufacturerssLinkObjFormatter" data-searchable="true" data-visible="false">{{ trans('general.manufacturer') }}</th>
|
||||
<th data-sortable="true" data-field="purchase_cost" data-searchable="true" data-visible="false">{{ trans('admin/hardware/form.cost') }}</th>
|
||||
<th data-sortable="true" data-field="purchase_date" data-searchable="true" data-visible="false">{{ trans('admin/hardware/form.date') }}</th>
|
||||
<th data-sortable="false" data-field="eol" data-searchable="true">{{ trans('general.eol') }}</th>
|
||||
|
|
|
@ -37,15 +37,16 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
|
||||
<th data-sortable="true" data-field="image" data-visible="false">{{ trans('admin/hardware/table.image') }}</th>
|
||||
<th data-sortable="false" data-field="manufacturer">{{ trans('general.manufacturer') }}</th>
|
||||
<th data-sortable="true" data-field="name" data-formatter="modelsLinkFormatter">{{ trans('admin/models/table.title') }}</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="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>
|
||||
<th data-sortable="false" data-field="assets_count">{{ trans('admin/models/table.numassets') }}</th>
|
||||
<th data-sortable="false" data-field="depreciation">{{ trans('general.depreciation') }}</th>
|
||||
<th data-sortable="false" data-field="category">{{ trans('general.category') }}</th>
|
||||
<th data-sortable="false" data-field="depreciation" data-formatter="depreciationsLinkObjFormatter">{{ trans('general.depreciation') }}</th>
|
||||
<th data-sortable="false" data-field="category" data-formatter="categoriesLinkObjFormatter">{{ trans('general.category') }}</th>
|
||||
<th data-sortable="true" data-field="eol">{{ trans('general.eol') }}</th>
|
||||
<th data-sortable="false" data-field="fieldset">{{ trans('admin/models/general.fieldset') }}</th>
|
||||
<th data-sortable="false" data-field="fieldset" data-formatter="fieldsetsLinkObjFormatter">{{ trans('admin/models/general.fieldset') }}</th>
|
||||
<th data-sortable="true" data-field="notes">{{ trans('general.notes') }}</th>
|
||||
<th data-switchable="false" data-formatter="modelsActionsFormatter" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
|
||||
</tr>
|
||||
|
|
|
@ -55,8 +55,6 @@ $('.snipe-table').bootstrapTable({
|
|||
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Handle whether or not the edit button should be disabled
|
||||
$('.snipe-table').on('check.bs.table', function () {
|
||||
$('#bulkEdit').removeAttr('disabled');
|
||||
|
@ -96,6 +94,7 @@ $('.snipe-table').bootstrapTable({
|
|||
};
|
||||
}
|
||||
|
||||
// Make the edit/delete buttons
|
||||
function genericActionsFormatter(destination) {
|
||||
return function (value,row) {
|
||||
return '<nobr><a href="{{ url('/') }}/' + destination + '/' + row.id + '/edit" class="btn btn-sm btn-warning"><i class="fa fa-pencil"></i></a> '
|
||||
|
@ -106,21 +105,44 @@ $('.snipe-table').bootstrapTable({
|
|||
};
|
||||
}
|
||||
|
||||
// Use this when we're introspecting into a column object with more than one item
|
||||
function genericColumnArrayLinkFormatter(destination) {
|
||||
function genericCheckinCheckoutFormatter(destination) {
|
||||
return function (value,row) {
|
||||
if ((value) && (value.name)) {
|
||||
return '<a href="{{ url('/') }}/' + destination + '/' + value.id + '"> ' + value.name + '</a>';
|
||||
}
|
||||
return '<nobr><a href="{{ url('/') }}/' + destination + '/' + row.id + '/edit" class="btn btn-sm btn-warning"><i class="fa fa-pencil"></i></a> '
|
||||
+ '<a data-html="false" class="btn delete-asset btn-danger btn-sm" ' +
|
||||
+ 'data-toggle="modal" href="" data-content="Are you sure you wish to delete this?" '
|
||||
+ 'data-title="{{ trans('general.delete') }}?" onClick="return false;">'
|
||||
+ '<i class="fa fa-trash"></i></a></nobr>';
|
||||
};
|
||||
}
|
||||
|
||||
var formatters = ['hardware','locations','users','manufacturers','statuslabels','models','licenses','categories','suppliers','companies'];
|
||||
function genericPublicImageFormatter(destination) {
|
||||
return function (value,row) {
|
||||
if (value) {
|
||||
return '<img src="{{ url('/') }}/uploads/' + destination + '/' + value + '" height="50" width="50">';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var formatters = [
|
||||
'hardware',
|
||||
'locations',
|
||||
'users',
|
||||
'manufacturers',
|
||||
'statuslabels',
|
||||
'models',
|
||||
'licenses',
|
||||
'categories',
|
||||
'suppliers',
|
||||
'companies',
|
||||
'depreciations',
|
||||
'fieldsets'
|
||||
];
|
||||
|
||||
for (var i in formatters) {
|
||||
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]);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue