Convert Models and Categories Index to use Datatables
This commit is contained in:
@@ -22,11 +22,8 @@ class CategoriesController extends AdminController
|
||||
|
||||
public function getIndex()
|
||||
{
|
||||
// Grab all the categories
|
||||
$categories = Category::orderBy('created_at', 'DESC')->get();
|
||||
|
||||
// Show the page
|
||||
return View::make('backend/categories/index', compact('categories'));
|
||||
return View::make('backend/categories/index');
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +212,34 @@ class CategoriesController extends AdminController
|
||||
|
||||
}
|
||||
|
||||
public function getDatatable()
|
||||
{
|
||||
// Grab all the categories
|
||||
$categories = Category::orderBy('created_at', 'DESC')->get();
|
||||
|
||||
$actions = new \Chumper\Datatable\Columns\FunctionColumn('actions', function($categories) {
|
||||
return '<a href="'.route('update/category', $categories->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/category', $categories->id).'" data-content="'.Lang::get('admin/categories/message.delete.confirm').'" data-title="'.Lang::get('general.delete').' '.htmlspecialchars($categories->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
|
||||
});
|
||||
|
||||
return Datatable::collection($categories)
|
||||
->showColumns('name')
|
||||
->addColumn('category_type', function($categories) {
|
||||
return ucwords($categories->category_type);
|
||||
})
|
||||
->addColumn('count', function($categories) {
|
||||
return ($categories->category_type=='asset') ? link_to('/admin/settings/categories/'.$categories->id.'/view', $categories->assetscount()) : $categories->accessoriescount();
|
||||
})
|
||||
->addColumn('acceptance', function($categories) {
|
||||
return ($categories->require_acceptance=='1') ? '<i class="fa fa-check" style="margin-right:50%;margin-left:50%;"></i>' : '';
|
||||
})
|
||||
->addColumn('eula', function($categories) {
|
||||
return ($categories->getEula()) ? '<i class="fa fa-check" style="margin-right:50%;margin-left:50%;"></i></a>' : '';
|
||||
})
|
||||
->addColumn($actions)
|
||||
->searchColumns('name','category_type','count','acceptance','eula','actions')
|
||||
->orderColumns('name','category_type','count','acceptance','eula','actions')
|
||||
->make();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -24,16 +24,8 @@ class ModelsController extends AdminController
|
||||
*/
|
||||
public function getIndex()
|
||||
{
|
||||
// Grab all the models
|
||||
$models = Model::orderBy('created_at', 'DESC');
|
||||
if (Input::get('Deleted')) {
|
||||
$models->withTrashed()->Deleted();
|
||||
}
|
||||
|
||||
$models = $models->with('category','assets','depreciation')->get();
|
||||
|
||||
// Show the page
|
||||
return View::make('backend/models/index', compact('models'));
|
||||
return View::make('backend/models/index');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,6 +307,42 @@ class ModelsController extends AdminController
|
||||
return $view;
|
||||
|
||||
}
|
||||
|
||||
public function getDatatable($status = null)
|
||||
{
|
||||
$models = Model::orderBy('created_at', 'DESC')->with('category','assets','depreciation');
|
||||
($status != 'Deleted') ?: $models->withTrashed()->Deleted();;
|
||||
$models = $models->get();
|
||||
|
||||
$actions = new \Chumper\Datatable\Columns\FunctionColumn('actions', function($models) {
|
||||
if($models->deleted_at=='') {
|
||||
return '<a href="'.route('update/model', $models->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/model', $models->id).'" data-content="'.Lang::get('admin/models/message.delete.confirm').'" data-title="'.Lang::get('general.delete').' '.htmlspecialchars($models->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
|
||||
} else {
|
||||
return '<a href="'.route('restore/model', $models->id).'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';
|
||||
}
|
||||
});
|
||||
|
||||
return Datatable::collection($models)
|
||||
->addColumn('name', function ($models) {
|
||||
return link_to('/hardware/models/'.$models->id.'/view', $models->name);
|
||||
})
|
||||
->showColumns('modelno')
|
||||
->addColumn('asset_count', function($models) {
|
||||
return $models->assets->count();
|
||||
})
|
||||
->addColumn('depreciation', function($models) {
|
||||
return (($models->depreciation)&&($models->depreciation->id > 0)) ? $models->depreciation->name.' ('.$models->depreciation->months.')' : Lang::get('general.no_depreciation');
|
||||
})
|
||||
->addColumn('category', function($models) {
|
||||
return ($models->category) ? $models->category->name : '';
|
||||
})
|
||||
->addColumn('eol', function($models) {
|
||||
return ($models->eol) ? $models->eol.' '.Lang::get('general.months') : '';
|
||||
})
|
||||
->addColumn($actions)
|
||||
->searchColumns('name','modelno','asset_count','depreciation','category','eol','actions')
|
||||
->orderColumns('name','modelno','asset_count','depreciation','category','eol','actions')
|
||||
->make();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,16 @@ Route::group(array('prefix' => 'api', 'namespace' => 'Controllers\Admin', 'befor
|
||||
Route::resource('/', 'LicensesController');
|
||||
Route::get('list', array('as'=>'api.licenses.list', 'uses'=>'LicensesController@getDatatable'));
|
||||
});
|
||||
/*---Models API---*/
|
||||
Route::group(array('prefix'=>'models'), function() {
|
||||
Route::resource('/', 'ModelsController');
|
||||
Route::get('list/{status?}', array('as'=>'api.models.list', 'uses'=>'ModelsController@getDatatable'));
|
||||
});
|
||||
/*--- Categories API---*/
|
||||
Route::group(array('prefix'=>'categories'), function() {
|
||||
Route::resource('/', 'CategoriesController');
|
||||
Route::get('list', array('as'=>'api.categories.list', 'uses'=>'CategoriesController@getDatatable'));
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
@@ -17,59 +17,58 @@
|
||||
</div>
|
||||
|
||||
<div class="user-profile">
|
||||
<div class="row profile">
|
||||
<div class="col-md-9 bio">
|
||||
|
||||
<div class="table-responsive">
|
||||
<table id="example">
|
||||
<thead>
|
||||
<tr role="row">
|
||||
<th class="col-md-5" bSortable="true">@lang('admin/categories/table.title')</th>
|
||||
<th class="col-md-2" bSortable="true">@lang('general.type')</th>
|
||||
<th class="col-md-2" bSortable="true">@lang('general.assets')</th>
|
||||
<th class="col-md-3" bSortable="true">@lang('admin/categories/table.require_acceptance')</th>
|
||||
<th class="col-md-2" bSortable="true">@lang('admin/categories/table.eula_text')</th>
|
||||
<th class="col-md-2 actions" bSortable="true">@lang('table.actions')</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($categories as $category)
|
||||
<tr>
|
||||
<td>{{{ $category->name }}}</td>
|
||||
<td>{{{ ucwords($category->category_type) }}}</td>
|
||||
<td>
|
||||
@if ($category->category_type=='asset')
|
||||
<a href="{{ route('view/category',$category->id) }}">{{ $category->assetscount() }}</a>
|
||||
@elseif ($category->category_type=='accessory')
|
||||
{{ $category->accessoriescount() }}
|
||||
@endif
|
||||
</td>
|
||||
<td>{{ ($category->require_acceptance=='1') ? '<i class="fa fa-check"></i>' : ''}}</td>
|
||||
<td>{{ ($category->getEula()) ? '<i class="fa fa-check"></i>' : ''}}</td>
|
||||
<td>
|
||||
<a href="{{ route('update/category', $category->id) }}" class="btn btn-warning btn-sm"><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/category', $category->id) }}" data-content="@lang('admin/categories/message.delete.confirm')"
|
||||
data-title="@lang('general.delete')
|
||||
{{{ htmlspecialchars($category->name) }}}?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="row profile">
|
||||
<div class="col-md-9 bio">
|
||||
{{ Datatable::table()
|
||||
->addColumn('',
|
||||
Lang::get('admin/categories/table.title'),
|
||||
Lang::get('general.type'),
|
||||
Lang::get('general.assets'),
|
||||
Lang::get('admin/categories/table.require_acceptance'),
|
||||
Lang::get('admin/categories/table.eula_text'),
|
||||
Lang::get('table.actions'))
|
||||
->setOptions(
|
||||
array(
|
||||
'ajax'=> route('api.categories.list'),
|
||||
'deferRender'=> true,
|
||||
'stateSave'=> true,
|
||||
'stateDuration'=> -1,
|
||||
'dom' =>'CT<"clear">lfrtip',
|
||||
'tableTools' => array(
|
||||
'sSwfPath'=> Config::get('app.url').'/assets/swf/copy_csv_xls_pdf.swf',
|
||||
'aButtons'=>array(
|
||||
'copy',
|
||||
'print',
|
||||
array(
|
||||
'sExtends'=>'collection',
|
||||
'sButtonText'=>'Export',
|
||||
'aButtons'=>array(
|
||||
'csv',
|
||||
'xls',
|
||||
'pdf'
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
'colVis'=> array('showAll'=>'Show All','restore'=>'Restore','exclude'=>array(0,6),'activate'=>'mouseover'),
|
||||
'columnDefs'=> array(array('visible'=>false,'targets'=>array(0)),array('bSortable'=>false,'targets'=>array(6))),
|
||||
'order'=>array(array(1,'asc')),
|
||||
'bProcessing'=>true,
|
||||
'oLanguage'=>array(
|
||||
'sProcessing'=>'<i class="fa fa-spinner fa-spin"></i> Loading...',
|
||||
),
|
||||
)
|
||||
)
|
||||
->render() }}
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- side address column -->
|
||||
<div class="col-md-3 col-xs-12 address pull-right">
|
||||
<br /><br />
|
||||
<h6>@lang('admin/categories/general.about_asset_categories')</h6>
|
||||
<p>@lang('admin/categories/general.about_categories') </p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- side address column -->
|
||||
<div class="col-md-3 col-xs-12 address pull-right">
|
||||
<br /><br />
|
||||
<h6>@lang('admin/categories/general.about_asset_categories')</h6>
|
||||
<p>@lang('admin/categories/general.about_categories') </p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
||||
|
||||
@@ -12,73 +12,56 @@
|
||||
<div class="row header">
|
||||
<div class="col-md-12">
|
||||
<a href="{{ route('create/model') }}" class="btn btn-success pull-right"><i class="fa fa-plus icon-white"></i> @lang('general.create')</a>
|
||||
@if(Input::get('Deleted'))
|
||||
@if(Input::get('status')=='Deleted')
|
||||
<a href="{{ URL::to('hardware/models') }}" class="btn btn-default pull-right"><i class="fa fa-trash"></i> @lang('admin/models/general.view_models')</a>
|
||||
@else
|
||||
<a href="{{ URL::to('hardware/models?Deleted=true') }}" class="btn btn-default pull-right"><i class="fa fa-trash"></i> @lang('admin/models/general.view_deleted')</a>
|
||||
<a href="{{ URL::to('hardware/models?status=Deleted') }}" class="btn btn-default pull-right"><i class="fa fa-trash"></i> @lang('admin/models/general.view_deleted')</a>
|
||||
@endif
|
||||
<h3>@lang('admin/models/table.title')</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row form-wrapper">
|
||||
<table id="example">
|
||||
<thead>
|
||||
<tr role="row">
|
||||
<th class="col-md-3">@lang('admin/models/table.title')</th>
|
||||
<th class="col-md-2">@lang('admin/models/table.modelnumber')</th>
|
||||
<th class="col-md-1">@lang('admin/models/table.numassets')</th>
|
||||
<th class="col-md-2">@lang('general.depreciation')</th>
|
||||
<th class="col-md-2">@lang('general.category')</th>
|
||||
<th class="col-md-2">@lang('general.eol')</th>
|
||||
<th class="col-md-2 actions">@lang('table.actions')</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($models as $model)
|
||||
<tr>
|
||||
<td><a href="{{ route('view/model', $model->id) }}">{{{ $model->name }}}</a></td>
|
||||
<td>{{{ $model->modelno }}}</td>
|
||||
<td><a href="{{ route('view/model', $model->id) }}">{{ ($model->assets->count()) }}</a></td>
|
||||
<td>
|
||||
|
||||
@if (($model->depreciation) && ($model->depreciation->id > 0)) {{{ $model->depreciation->name }}}
|
||||
({{{ $model->depreciation->months }}}
|
||||
@lang('general.months')
|
||||
)
|
||||
@else
|
||||
@lang('general.no_depreciation')
|
||||
@endif
|
||||
|
||||
</td>
|
||||
<td>
|
||||
@if ($model->category) {{{ $model->category->name }}}
|
||||
@endif
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
@if ($model->eol) {{{ $model->eol }}}
|
||||
@lang('general.months')
|
||||
@else
|
||||
--
|
||||
@endif
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
@if($model->deleted_at=="")
|
||||
<a href="{{ route('update/model', $model->id) }}" class="btn btn-warning btn-sm"><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/model', $model->id) }}" data-content="@lang('admin/models/message.delete.confirm')"
|
||||
data-title="@lang('general.delete')
|
||||
{{ htmlspecialchars($model->name) }}?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>
|
||||
@else
|
||||
<a href="{{ route('restore/model', $model->id) }}" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
{{ Datatable::table()
|
||||
->addColumn(Lang::get('admin/models/table.title'),
|
||||
Lang::get('admin/models/table.modelnumber'),
|
||||
Lang::get('admin/models/table.numassets'),
|
||||
Lang::get('general.depreciation'),
|
||||
Lang::get('general.category'),
|
||||
Lang::get('general.eol'),
|
||||
Lang::get('table.actions'))
|
||||
->setOptions(
|
||||
array(
|
||||
'ajax'=> route('api.models.list', Input::get('status')),
|
||||
'deferRender'=> true,
|
||||
'stateSave'=> true,
|
||||
'stateDuration'=> -1,
|
||||
'dom' =>'CT<"clear">lfrtip',
|
||||
'tableTools' => array(
|
||||
'sSwfPath'=> Config::get('app.url').'/assets/swf/copy_csv_xls_pdf.swf',
|
||||
'aButtons'=>array(
|
||||
'copy',
|
||||
'print',
|
||||
array(
|
||||
'sExtends'=>'collection',
|
||||
'sButtonText'=>'Export',
|
||||
'aButtons'=>array(
|
||||
'csv',
|
||||
'xls',
|
||||
'pdf'
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
'colVis'=> array('showAll'=>'Show All','restore'=>'Restore','exclude'=>array(6),'activate'=>'mouseover'),
|
||||
'columnDefs'=> array(array('bSortable'=>false,'targets'=>array(6))),
|
||||
'order'=>array(array(0,'asc')),
|
||||
'bProcessing'=>true,
|
||||
'oLanguage'=>array(
|
||||
'sProcessing'=>'<i class="fa fa-spinner fa-spin"></i> Loading...',
|
||||
),
|
||||
)
|
||||
)
|
||||
->render() }}
|
||||
|
||||
@stop
|
||||
|
||||
Reference in New Issue
Block a user