Locations in bootstrap tables for #1266
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
return array (
|
||||
'app_version' => 'v2.0-262',
|
||||
'hash_version' => 'v2.0-262-gcab5dba',
|
||||
'app_version' => 'v2.0-264',
|
||||
'hash_version' => 'v2.0-264-g36a3d65',
|
||||
);
|
||||
@@ -254,6 +254,79 @@ class LocationsController extends AdminController
|
||||
|
||||
}
|
||||
|
||||
public function getDatatable()
|
||||
{
|
||||
$locations = Location::select(array('id','name','address','address2','city','state','zip','country'))
|
||||
->whereNull('deleted_at');
|
||||
|
||||
if (Input::has('search')) {
|
||||
$locations = $locations->TextSearch(e(Input::get('search')));
|
||||
}
|
||||
|
||||
if (Input::has('offset')) {
|
||||
$offset = e(Input::get('offset'));
|
||||
} else {
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
if (Input::has('limit')) {
|
||||
$limit = e(Input::get('limit'));
|
||||
} else {
|
||||
$limit = 50;
|
||||
}
|
||||
|
||||
|
||||
$allowed_columns = ['name','address','city','state','country'];
|
||||
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
||||
$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
|
||||
|
||||
$locations->orderBy($sort, $order);
|
||||
|
||||
$locationsCount = $locations->count();
|
||||
$locations = $locations->skip($offset)->take($limit)->get();
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach($locations as $location) {
|
||||
$actions = '<a href="'.route('update/location', $location->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/location', $location->id).'" data-content="'.Lang::get('admin/locations/message.delete.confirm').'" data-title="'.Lang::get('general.delete').' '.htmlspecialchars($location->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
|
||||
|
||||
$rows[] = array(
|
||||
'name' => link_to('admin/locations/'.$location->id.'/view', $location->name),
|
||||
'parent' => ($location->parent) ? $location->parent->name : '',
|
||||
'assets' => ($location->assets->count() + $location->assignedassets->count()),
|
||||
'address' => ($location->address) ? $location->address: '',
|
||||
'city' => $location->city,
|
||||
'state' => $location->state,
|
||||
'country' => $location->country,
|
||||
'actions' => $actions
|
||||
);
|
||||
}
|
||||
|
||||
$data = array('total' => $locationsCount, 'rows' => $rows);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
public function getDataView($locationId)
|
||||
{
|
||||
$consumable = Consumable::find($consumableID);
|
||||
$consumable_users = $consumable->users;
|
||||
$count = $consumable_users->count();
|
||||
|
||||
$rows = array();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+27
-1
@@ -29,7 +29,7 @@ class Location extends Elegant
|
||||
}
|
||||
|
||||
public function parent() {
|
||||
return $this->belongsTo('Location', 'parent_id');
|
||||
return $this->hasOne('Location', 'parent_id');
|
||||
}
|
||||
|
||||
public function childLocations() {
|
||||
@@ -88,5 +88,31 @@ class Location extends Elegant
|
||||
return $location_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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('name', 'LIKE', "%$search%")
|
||||
->orWhere('address', 'LIKE', "%$search%")
|
||||
->orWhere('city', 'LIKE', "%$search%")
|
||||
->orWhere('state', 'LIKE', "%$search%")
|
||||
->orWhere('zip', 'LIKE', "%$search%")
|
||||
->orWhere(function($query) use ($search) {
|
||||
$query->whereHas('parent', function($query) use ($search) {
|
||||
$query->where(function($query) use ($search) {
|
||||
$query->where('name','LIKE','%'.$search.'%');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+11
-5
@@ -39,11 +39,17 @@
|
||||
[ 'as' => 'api.accessories.view', 'uses' => 'AccessoriesController@getDataView' ] );
|
||||
} );
|
||||
|
||||
/*---Consumables API---*/
|
||||
Route::group(array('prefix'=>'consumables'), function () {
|
||||
Route::get('list', array('as'=>'api.consumables.list', 'uses'=>'ConsumablesController@getDatatable'));
|
||||
Route::get('{consumableID}/view', array('as'=>'api.consumables.view', 'uses'=>'ConsumablesController@getDataView'));
|
||||
});
|
||||
/*---Consumables API---*/
|
||||
Route::group(array('prefix'=>'consumables'), function () {
|
||||
Route::get('list', array('as'=>'api.consumables.list', 'uses'=>'ConsumablesController@getDatatable'));
|
||||
Route::get('{consumableID}/view', array('as'=>'api.consumables.view', 'uses'=>'ConsumablesController@getDataView'));
|
||||
});
|
||||
|
||||
/*---Locations API---*/
|
||||
Route::group(array('prefix'=>'locations'), function () {
|
||||
Route::get('list', array('as'=>'api.locations.list', 'uses'=>'LocationsController@getDatatable'));
|
||||
Route::get('{$locationID}/view', array('as'=>'api.locations.view', 'uses'=>'LocationsController@getDataView'));
|
||||
});
|
||||
|
||||
/*---Users API---*/
|
||||
Route::group( [ 'prefix' => 'users' ], function () {
|
||||
|
||||
@@ -18,47 +18,71 @@ Locations ::
|
||||
|
||||
<div class="row form-wrapper">
|
||||
|
||||
<table id="example">
|
||||
<thead>
|
||||
<tr role="row">
|
||||
<th class="col-md-2">@lang('admin/locations/table.name')</th>
|
||||
<th class="col-md-2">@lang('admin/locations/table.parent')</th>
|
||||
<th class="col-md-1">@lang('general.assets')</th>
|
||||
<th class="col-md-3">@lang('admin/locations/table.address')</th>
|
||||
<th class="col-md-2">@lang('admin/locations/table.city'),
|
||||
@lang('admin/locations/table.state')
|
||||
@lang('admin/locations/table.country')</th>
|
||||
<th class="col-md-1 actions">@lang('table.actions')</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($locations as $location)
|
||||
<tr>
|
||||
<td>{{{ $location->name }}}</td>
|
||||
<td>
|
||||
@if ($location->parent)
|
||||
{{{ $location->parent->name }}}
|
||||
@endif
|
||||
</td>
|
||||
<td>{{{ ($location->assets->count() + $location->assignedassets->count()) }}}</td>
|
||||
<td>{{{ $location->address }}}
|
||||
@if($location->address2 != '')
|
||||
, {{{ $location->address2 }}}
|
||||
@endif
|
||||
</td>
|
||||
<td>{{{ $location->city }}}, {{{ strtoupper($location->state) }}} {{{ strtoupper($location->country) }}} </td>
|
||||
<td>
|
||||
<a href="{{ route('update/location', $location->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/location', $location->id) }}" data-content="@lang('admin/locations/message.delete.confirm')"
|
||||
data-title="@lang('general.delete')
|
||||
{{ htmlspecialchars($location->name) }}?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<table
|
||||
name="categories"
|
||||
id="table"
|
||||
data-url="{{ route('api.locations.list') }}"
|
||||
data-cookie="true"
|
||||
data-click-to-select="true"
|
||||
data-cookie-id-table="locationsTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-sortable="true" data-field="name">@lang('admin/locations/table.name')</th>
|
||||
<th data-sortable="false" data-field="parent">@lang('admin/locations/table.parent')</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="assets">@lang('general.assets')</th>
|
||||
<th data-searchable="true" data-sortable="true" data-field="address">@lang('admin/locations/table.address')</th>
|
||||
<th data-searchable="true" data-sortable="true" data-field="city">@lang('admin/locations/table.city')
|
||||
</th>
|
||||
<th data-searchable="true" data-sortable="true" data-field="state">
|
||||
@lang('admin/locations/table.state')
|
||||
</th>
|
||||
<th data-searchable="true" data-sortable="true" data-field="country">
|
||||
@lang('admin/locations/table.country')</th>
|
||||
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions">{{ Lang::get('table.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@section('moar_scripts')
|
||||
<script src="{{ asset('assets/js/bootstrap-table.js') }}"></script>
|
||||
<script src="{{ asset('assets/js/extensions/cookie/bootstrap-table-cookie.js') }}"></script>
|
||||
<script src="{{ asset('assets/js/extensions/mobile/bootstrap-table-mobile.js') }}"></script>
|
||||
<script src="{{ asset('assets/js/extensions/export/bootstrap-table-export.js') }}"></script>
|
||||
<script src="//rawgit.com/kayalshri/tableExport.jquery.plugin/master/tableExport.js"></script>
|
||||
<script src="//rawgit.com/kayalshri/tableExport.jquery.plugin/master/jquery.base64.js"></script>
|
||||
<script type="text/javascript">
|
||||
$('#table').bootstrapTable({
|
||||
classes: 'table table-responsive table-no-bordered',
|
||||
undefinedText: '',
|
||||
iconsPrefix: 'fa',
|
||||
showRefresh: true,
|
||||
search: true,
|
||||
pageSize: {{{ Setting::getSettings()->per_page }}},
|
||||
pagination: true,
|
||||
sidePagination: 'server',
|
||||
sortable: true,
|
||||
cookie: true,
|
||||
mobileResponsive: true,
|
||||
showExport: true,
|
||||
showColumns: true,
|
||||
exportDataType: 'all',
|
||||
exportTypes: ['csv', 'txt','json', 'xml'],
|
||||
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
|
||||
|
||||
@stop
|
||||
|
||||
Reference in New Issue
Block a user