Tweaks to status labelas listing display

This commit is contained in:
snipe 2017-02-01 17:48:28 -08:00
parent 7642d17fb8
commit 7086ac8a8b
5 changed files with 27 additions and 16 deletions

View file

@ -7,7 +7,7 @@ use App\Http\Controllers\Controller;
use App\Helpers\Helper; use App\Helpers\Helper;
use App\Models\Statuslabel; use App\Models\Statuslabel;
use App\Models\Asset; use App\Models\Asset;
use App\Http\Transformers\DatatablesTransformer; use App\Http\Transformers\StatuslabelsTransformer;
use App\Http\Transformers\AssetsTransformer; use App\Http\Transformers\AssetsTransformer;
use PhpParser\Node\Expr\Cast\Bool_; use PhpParser\Node\Expr\Cast\Bool_;
@ -25,8 +25,7 @@ class StatuslabelsController extends Controller
$this->authorize('view', Statuslabel::class); $this->authorize('view', Statuslabel::class);
$allowed_columns = ['id','name','created_at']; $allowed_columns = ['id','name','created_at'];
$statuslabels = Statuslabel::select(['id','name','deployable','pending','archived','color','show_in_nav','created_at']) $statuslabels = Statuslabel::withCount('assets');
->withCount('assets');
if ($request->has('search')) { if ($request->has('search')) {
$statuslabels = $statuslabels->TextSearch($request->input('search')); $statuslabels = $statuslabels->TextSearch($request->input('search'));
@ -40,7 +39,7 @@ class StatuslabelsController extends Controller
$total = $statuslabels->count(); $total = $statuslabels->count();
$statuslabels = $statuslabels->skip($offset)->take($limit)->get(); $statuslabels = $statuslabels->skip($offset)->take($limit)->get();
return (new DatatablesTransformer)->transformDatatables($statuslabels, $total); return (new StatuslabelsTransformer)->transformStatuslabels($statuslabels, $total);
} }

View file

@ -22,8 +22,9 @@ class StatuslabelsTransformer
'id' => e($statuslabel->id), 'id' => e($statuslabel->id),
'name' => e($statuslabel->name), 'name' => e($statuslabel->name),
'type' => $statuslabel->getStatuslabelType(), 'type' => $statuslabel->getStatuslabelType(),
'color' => e($statuslabel->color), 'color' => ($statuslabel->color) ? e($statuslabel->color) : null,
'show_in_nav' => ($statuslabel->show_in_nav=='1') ? true : false, 'show_in_nav' => ($statuslabel->show_in_nav=='1') ? true : false,
'notes' => e($statuslabel->notes),
'created_at' => $statuslabel->created_at, 'created_at' => $statuslabel->created_at,
'updated_at' => $statuslabel->updated_at, 'updated_at' => $statuslabel->updated_at,
]; ];
@ -31,10 +32,6 @@ class StatuslabelsTransformer
return $array; return $array;
} }
public function transformStatuslabelsDatatable($users) {
return (new DatatablesTransformer)->transformDatatables($users);
}
} }

View file

@ -27,8 +27,7 @@
data-url="{{route('api.categories.index') }}" data-url="{{route('api.categories.index') }}"
data-cookie="true" data-cookie="true"
data-click-to-select="true" data-click-to-select="true"
data-cookie-id-table="categoriesTable-{{ config('version.hash_version') }}" data-cookie-id-table="categoriesTable-{{ config('version.hash_version') }}">
>
<thead> <thead>
<tr> <tr>
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th> <th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>

View file

@ -152,9 +152,9 @@ $('.snipe-table').bootstrapTable({
function trueFalseFormatter(value, row) { function trueFalseFormatter(value, row) {
if ((value) && ((value == 'true') || (value == '1'))) { if ((value) && ((value == 'true') || (value == '1'))) {
return '<i class="fa fa-check"></i>'; return '<i class="fa fa-check text-success"></i>';
} else { } else {
return '<i class="fa fa-times"></i>'; return '<i class="fa fa-times text-danger"></i>';
} }
} }

View file

@ -31,9 +31,9 @@
<tr> <tr>
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th> <th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
<th data-sortable="true" data-field="name">{{ trans('admin/statuslabels/table.name') }}</th> <th data-sortable="true" data-field="name">{{ trans('admin/statuslabels/table.name') }}</th>
<th data-sortable="false" data-field="type">{{ trans('admin/statuslabels/table.status_type') }}</th> <th data-sortable="false" data-field="type" data-formatter="undeployableFormatter">{{ trans('admin/statuslabels/table.status_type') }}</th>
<th data-sortable="false" data-field="color">{{ trans('admin/statuslabels/table.color') }}</th> <th data-sortable="false" data-field="color" data-formatter="colorSqFormatter">{{ trans('admin/statuslabels/table.color') }}</th>
<th data-sortable="true" data-field="show_in_nav">{{ trans('admin/statuslabels/table.show_in_nav') }}</th> <th class="text-center" data-sortable="true" data-field="show_in_nav" data-formatter="trueFalseFormatter">{{ trans('admin/statuslabels/table.show_in_nav') }}</th>
<th data-switchable="false" data-formatter="statuslabelsActionsFormatter" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th> <th data-switchable="false" data-formatter="statuslabelsActionsFormatter" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
</tr> </tr>
</thead> </thead>
@ -53,4 +53,20 @@
@section('moar_scripts') @section('moar_scripts')
@include ('partials.bootstrap-table', ['exportFile' => 'statuslabels-export', 'search' => true]) @include ('partials.bootstrap-table', ['exportFile' => 'statuslabels-export', 'search' => true])
<script>
function colorSqFormatter(value, row) {
if (value) {
return '<span class="label" style="background-color: ' + value + ';">&nbsp;</span> ' + value;
}
}
function undeployableFormatter(value, row) {
if ((value) && (value!='deployable')) {
return '<span class="text-danger">' + value + '</span> ';
} else {
return '<span class="text-success">' + value + '</span> ';
}
}
</script>
@stop @stop