Merge pull request #1072 from madd15/bootstrap-table-experiment
Add base for Consumables with bootstrap tables
This commit is contained in:
@@ -348,47 +348,57 @@ class ConsumablesController extends AdminController
|
||||
public function getDatatable()
|
||||
{
|
||||
$consumables = Consumable::select(array('id','name','qty'))
|
||||
->whereNull('deleted_at')
|
||||
->orderBy('created_at', 'DESC');
|
||||
->whereNull('deleted_at');
|
||||
|
||||
$consumables = $consumables->get();
|
||||
if (Input::has('search')) {
|
||||
$consumables = $consumables->TextSearch(Input::get('search'));
|
||||
}
|
||||
|
||||
$actions = new \Chumper\Datatable\Columns\FunctionColumn('actions',function($consumables)
|
||||
{
|
||||
return '<a href="'.route('checkout/consumable', $consumables->id).'" style="margin-right:5px;" class="btn btn-info btn-sm" '.(($consumables->numRemaining() > 0 ) ? '' : ' disabled').'>'.Lang::get('general.checkout').'</a><a href="'.route('update/consumable', $consumables->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/consumable', $consumables->id).'" data-content="'.Lang::get('admin/consumables/message.delete.confirm').'" data-title="'.Lang::get('general.delete').' '.htmlspecialchars($consumables->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
|
||||
});
|
||||
$allowed_columns = ['name'];
|
||||
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
||||
$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
|
||||
|
||||
$consumables->orderBy($sort, $order);
|
||||
|
||||
$consumCount = $consumables->count();
|
||||
$consumables = $consumables->skip(Input::get('offset'))->take(Input::get('limit'))->get();
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach($consumables as $consumable) {
|
||||
$actions = '<a href="'.route('checkout/consumable', $consumable->id).'" style="margin-right:5px;" class="btn btn-info btn-sm" '.(($consumable->numRemaining() > 0 ) ? '' : ' disabled').'>'.Lang::get('general.checkout').'</a><a href="'.route('update/consumable', $consumable->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/consumable', $consumable->id).'" data-content="'.Lang::get('admin/consumables/message.delete.confirm').'" data-title="'.Lang::get('general.delete').' '.htmlspecialchars($consumable->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
|
||||
|
||||
$rows[] = array(
|
||||
'name' => link_to('admin/consumables/'.$consumable->id.'/view', $consumable->name),
|
||||
'qty' => $consumable->qty,
|
||||
'numRemaining' => $consumable->numRemaining(),
|
||||
'actions' => $actions
|
||||
);
|
||||
}
|
||||
|
||||
$data = array('total' => $consumCount, 'rows' => $rows);
|
||||
|
||||
return $data;
|
||||
|
||||
return Datatable::collection($consumables)
|
||||
->addColumn('name',function($consumables)
|
||||
{
|
||||
return link_to('admin/consumables/'.$consumables->id.'/view', $consumables->name);
|
||||
})
|
||||
->addColumn('qty',function($consumables)
|
||||
{
|
||||
return $consumables->qty;
|
||||
})
|
||||
->addColumn('numRemaining',function($consumables)
|
||||
{
|
||||
return $consumables->numRemaining();
|
||||
})
|
||||
->addColumn($actions)
|
||||
->searchColumns('name','qty','numRemaining','actions')
|
||||
->orderColumns('name','qty','numRemaining','actions')
|
||||
->make();
|
||||
}
|
||||
|
||||
public function getDataView($consumableID)
|
||||
{
|
||||
$consumable = Consumable::find($consumableID);
|
||||
$consumable_users = $consumable->users;
|
||||
$count = $consumable_users->count();
|
||||
|
||||
$rows = array();
|
||||
|
||||
return Datatable::collection($consumable_users)
|
||||
->addColumn('name',function($consumable_users)
|
||||
{
|
||||
return link_to('/admin/users/'.$consumable_users->id.'/view', $consumable_users->fullName());
|
||||
})
|
||||
->make();
|
||||
foreach ($consumable_users as $user) {
|
||||
$rows[] = array(
|
||||
'name' => link_to('/admin/users/'.$user->id.'/view', $user->fullName())
|
||||
);
|
||||
}
|
||||
|
||||
$data = array('total' => $count, 'rows' => $rows);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class Accessory extends Elegant
|
||||
return $remaining;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Query builder scope to search on text
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
@@ -78,13 +78,10 @@ class Accessory extends Elegant
|
||||
*/
|
||||
public function scopeTextSearch($query, $search)
|
||||
{
|
||||
$search = explode('+', $search);
|
||||
|
||||
return $query->where(function($query) use ($search)
|
||||
{
|
||||
foreach ($search as $s) {
|
||||
$query->where('name', 'LIKE', '%'.$s.'%');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,22 @@ class Consumable extends Elegant
|
||||
$remaining = $total - $checkedout;
|
||||
return $remaining;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to search on text
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $search Search term
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeTextSearch($query, $search)
|
||||
{
|
||||
|
||||
return $query->where(function($query) use ($search)
|
||||
{
|
||||
$query->where('name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ Route::group(array('prefix' => 'api', 'namespace' => 'Controllers\Admin', 'befor
|
||||
/*---Consumables API---*/
|
||||
Route::group(array('prefix'=>'consumables'), function () {
|
||||
Route::get('list', array('as'=>'api.consumables.list', 'uses'=>'ConsumablesController@getDatatable'));
|
||||
Route::get('{accessoryID}/view', array('as'=>'api.consumables.view', 'uses'=>'ConsumablesController@getDataView'));
|
||||
Route::get('{consumableID}/view', array('as'=>'api.consumables.view', 'uses'=>'ConsumablesController@getDataView'));
|
||||
});
|
||||
|
||||
/*---Users API---*/
|
||||
|
||||
@@ -19,78 +19,15 @@
|
||||
<div class="user-profile">
|
||||
<div class="row profile">
|
||||
<div class="col-md-9 bio">
|
||||
{{ Datatable::table()
|
||||
->addColumn(Lang::get('admin/consumables/table.title'),
|
||||
Lang::get('admin/consumables/general.total'),
|
||||
Lang::get('admin/consumables/general.remaining'),
|
||||
Lang::get('table.actions'))
|
||||
->setOptions(
|
||||
array(
|
||||
'language' => array(
|
||||
'search' => Lang::get('general.search'),
|
||||
'lengthMenu' => Lang::get('general.page_menu'),
|
||||
'loadingRecords' => Lang::get('general.loading'),
|
||||
'zeroRecords' => Lang::get('general.no_results'),
|
||||
'info' => Lang::get('general.pagination_info'),
|
||||
'processing' => '<i class="fa fa-spinner fa-spin"></i> '.Lang::get('general.processing'),
|
||||
'paginate'=> array(
|
||||
'first'=>Lang::get('general.first'),
|
||||
'previous'=>Lang::get('general.previous'),
|
||||
'next'=>Lang::get('general.next'),
|
||||
'last'=>Lang::get('general.last'),
|
||||
),
|
||||
),
|
||||
'sAjaxSource'=>route('api.consumables.list'),
|
||||
'dom' =>'T<"clear">lfrtip',
|
||||
'tableTools' => array(
|
||||
'sSwfPath'=> Config::get('app.url').'/assets/swf/copy_csv_xls_pdf.swf',
|
||||
'aButtons'=>array(
|
||||
array(
|
||||
'sExtends'=>'copy',
|
||||
'sButtonText'=>'Copy',
|
||||
'mColumns'=>array(0,1,2),
|
||||
'bFooter'=>false,
|
||||
),
|
||||
array(
|
||||
'sExtends'=>'print',
|
||||
'sButtonText'=>'Print',
|
||||
'mColumns'=>array(0,1,2),
|
||||
'bShowAll'=>true,
|
||||
'bFooter'=>true,
|
||||
),
|
||||
array(
|
||||
'sExtends'=>'collection',
|
||||
'sButtonText'=>'Export',
|
||||
'aButtons'=>array(
|
||||
array(
|
||||
'sExtends'=>'csv',
|
||||
'sButtonText'=>'csv',
|
||||
'mColumns'=>array(0,1,2),
|
||||
'bFooter'=>false,
|
||||
),
|
||||
array(
|
||||
'sExtends'=>'xls',
|
||||
'sButtonText'=>'XLS',
|
||||
'mColumns'=>array(0,1,2),
|
||||
'bFooter'=>false,
|
||||
),
|
||||
array(
|
||||
'sExtends'=>'pdf',
|
||||
'sButtonText'=>'PDF',
|
||||
'mColumns'=>array(0,1,2),
|
||||
'bFooter'=>false,
|
||||
)
|
||||
)
|
||||
),
|
||||
)
|
||||
),
|
||||
'columnDefs'=> array(
|
||||
array('bSortable'=>false,'targets'=>array(3)),
|
||||
),
|
||||
'order'=>array(array(0,'asc')),
|
||||
)
|
||||
)
|
||||
->render() }}
|
||||
<table name="consumables" id="table" data-url="{{route('api.consumables.list')}}">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-sortable="true" data-field="name">{{Lang::get('admin/consumables/table.title')}}</th>
|
||||
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="qty">{{Lang::get('admin/consumables/general.total')}}</th>
|
||||
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="numRemaining">{{Lang::get('admin/consumables/general.remaining')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -103,4 +40,34 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('#table').bootstrapTable({
|
||||
classes: 'table table-hover table-no-bordered',
|
||||
undefinedText: 'undefined',
|
||||
iconsPrefix: 'fa',
|
||||
showRefresh: true,
|
||||
search: true,
|
||||
pageSize: {{{ Setting::getSettings()->per_page }}},
|
||||
pagination: true,
|
||||
sidePagination: 'server',
|
||||
sortable: true,
|
||||
mobileResponsive: true,
|
||||
showExport: true,
|
||||
showColumns: false,
|
||||
maintainSelected: true,
|
||||
paginationFirstText: "@lang('general.first')",
|
||||
paginationLastText: "@lang('general.last')",
|
||||
paginationPreText: "@lang('general.previous')",
|
||||
paginationNextText: "@lang('general.next')",
|
||||
pageList: ['10','25','50','100','150','200'],
|
||||
icons: {
|
||||
paginationSwitchDown: 'fa-caret-square-o-down',
|
||||
paginationSwitchUp: 'fa-caret-square-o-up',
|
||||
columns: 'fa-columns',
|
||||
refresh: 'fa-refresh'
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
@stop
|
||||
|
||||
@@ -31,52 +31,20 @@
|
||||
|
||||
<!-- checked out consumables table -->
|
||||
@if ($consumable->users->count() > 0)
|
||||
{{ Datatable::table()
|
||||
->addColumn(Lang::get('general.user'))
|
||||
->setOptions(
|
||||
array(
|
||||
'sAjaxSource'=>route('api.consumables.view', $consumable->id),
|
||||
'dom' =>'T<"clear">lfrtip',
|
||||
'tableTools' => array(
|
||||
'sSwfPath'=> Config::get('app.url').'/assets/swf/copy_csv_xls_pdf.swf',
|
||||
'aButtons'=>array(
|
||||
array(
|
||||
'sExtends'=>'copy',
|
||||
),
|
||||
'print',
|
||||
array(
|
||||
'sExtends'=>'collection',
|
||||
'sButtonText'=>'Export',
|
||||
'aButtons'=>array(
|
||||
array(
|
||||
'sExtends'=>'csv',
|
||||
),
|
||||
array(
|
||||
'sExtends'=>'xls',
|
||||
),
|
||||
array(
|
||||
'sExtends'=>'pdf',
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
'columnDefs'=> array(
|
||||
|
||||
array('width'=>'auto','targets'=>array(0)),
|
||||
),
|
||||
'order'=>array(array(0,'asc')),
|
||||
)
|
||||
)
|
||||
->render() }}
|
||||
|
||||
<table name="consumable_users" id="table" data-url="{{route('api.consumables.view', $consumable->id)}}">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="name">{{Lang::get('general.user')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
@else
|
||||
<div class="col-md-9">
|
||||
<div class="alert alert-info alert-block">
|
||||
<i class="fa fa-info-circle"></i>
|
||||
@lang('general.no_results')
|
||||
<div class="col-md-9">
|
||||
<div class="alert alert-info alert-block">
|
||||
<i class="fa fa-info-circle"></i>
|
||||
@lang('general.no_results')
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
@@ -89,4 +57,33 @@
|
||||
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('#table').bootstrapTable({
|
||||
classes: 'table table-hover table-no-bordered',
|
||||
undefinedText: 'undefined',
|
||||
iconsPrefix: 'fa',
|
||||
showRefresh: true,
|
||||
search: false,
|
||||
pageSize: {{{ Setting::getSettings()->per_page }}},
|
||||
pagination: true,
|
||||
sidePagination: 'server',
|
||||
sortable: true,
|
||||
mobileResponsive: true,
|
||||
showExport: true,
|
||||
showColumns: false,
|
||||
maintainSelected: true,
|
||||
paginationFirstText: "@lang('general.first')",
|
||||
paginationLastText: "@lang('general.last')",
|
||||
paginationPreText: "@lang('general.previous')",
|
||||
paginationNextText: "@lang('general.next')",
|
||||
pageList: ['10','25','50','100','150','200'],
|
||||
icons: {
|
||||
paginationSwitchDown: 'fa-caret-square-o-down',
|
||||
paginationSwitchUp: 'fa-caret-square-o-up',
|
||||
columns: 'fa-columns',
|
||||
refresh: 'fa-refresh'
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
@stop
|
||||
|
||||
Reference in New Issue
Block a user