Merge branch 'develop'

This commit is contained in:
snipe 2018-02-21 05:34:02 -08:00
commit 4e398950a0
8 changed files with 72 additions and 17 deletions

View file

@ -22,17 +22,17 @@ class DepartmentsController extends Controller
public function index(Request $request) public function index(Request $request)
{ {
$this->authorize('view', Department::class); $this->authorize('view', Department::class);
$allowed_columns = ['id','name','image']; $allowed_columns = ['id','name','image','users_count'];
$departments = Department::select([ $departments = Department::select([
'id', 'departments.id',
'name', 'departments.name',
'location_id', 'departments.location_id',
'company_id', 'departments.company_id',
'manager_id', 'departments.manager_id',
'created_at', 'departments.created_at',
'updated_at', 'departments.updated_at',
'image' 'departments.image'
])->with('users')->with('location')->with('manager')->with('company')->withCount('users'); ])->with('users')->with('location')->with('manager')->with('company')->withCount('users');
if ($request->has('search')) { if ($request->has('search')) {
@ -43,7 +43,18 @@ class DepartmentsController extends Controller
$limit = $request->input('limit', 50); $limit = $request->input('limit', 50);
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
$departments->orderBy($sort, $order);
switch ($request->input('sort')) {
case 'location':
$departments->OrderLocation($order);
break;
case 'manager':
$departments->OrderManager($order);
break;
default:
$departments->orderBy($sort, $order);
break;
}
$total = $departments->count(); $total = $departments->count();
$departments = $departments->skip($offset)->take($limit)->get(); $departments = $departments->skip($offset)->take($limit)->get();

View file

@ -60,6 +60,9 @@ class LocationsController extends Controller
case 'parent': case 'parent':
$locations->OrderParent($order); $locations->OrderParent($order);
break; break;
case 'manager':
$locations->OrderManager($order);
break;
default: default:
$locations->orderBy($sort, $order); $locations->orderBy($sort, $order);
break; break;

View file

@ -22,7 +22,7 @@ class StatuslabelsController extends Controller
public function index(Request $request) public function index(Request $request)
{ {
$this->authorize('view', Statuslabel::class); $this->authorize('view', Statuslabel::class);
$allowed_columns = ['id','name','created_at', 'assets_count']; $allowed_columns = ['id','name','created_at', 'assets_count','color'];
$statuslabels = Statuslabel::withCount('assets'); $statuslabels = Statuslabel::withCount('assets');

View file

@ -93,5 +93,31 @@ class Department extends SnipeModel
} }
/**
* Query builder scope to order on location name
*
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderLocation($query, $order)
{
return $query->leftJoin('locations as department_location', 'departments.location_id', '=', 'department_location.id')->orderBy('department_location.name', $order);
}
/**
* Query builder scope to order on manager name
*
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderManager($query, $order)
{
return $query->leftJoin('users as department_user', 'departments.manager_id', '=', 'department_user.id')->orderBy('department_user.first_name', $order)->orderBy('department_user.last_name', $order);
}
} }

View file

@ -205,4 +205,17 @@ class Location extends SnipeModel
// Left join here, or it will only return results with parents // Left join here, or it will only return results with parents
return $query->leftJoin('locations as parent_loc', 'locations.parent_id', '=', 'parent_loc.id')->orderBy('parent_loc.name', $order); return $query->leftJoin('locations as parent_loc', 'locations.parent_id', '=', 'parent_loc.id')->orderBy('parent_loc.name', $order);
} }
/**
* Query builder scope to order on manager name
*
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderManager($query, $order)
{
return $query->leftJoin('users as location_user', 'locations.manager_id', '=', 'location_user.id')->orderBy('location_user.first_name', $order)->orderBy('location_user.last_name', $order);
}
} }

View file

@ -128,7 +128,7 @@ class LocationPresenter extends Presenter
],[ ],[
"field" => "manager", "field" => "manager",
"searchable" => false, "searchable" => false,
"sortable" => false, "sortable" => true,
"switchable" => true, "switchable" => true,
"title" => trans('admin/users/table.manager'), "title" => trans('admin/users/table.manager'),
"visible" => false, "visible" => false,

View file

@ -41,9 +41,9 @@
<th data-sortable="true" data-field="company" data-visible="false" data-formatter="companiesLinkObjFormatter">{{ trans('general.company') }}</th> <th data-sortable="true" data-field="company" data-visible="false" data-formatter="companiesLinkObjFormatter">{{ trans('general.company') }}</th>
<th data-sortable="true" data-formatter="departmentsLinkFormatter" data-field="name" data-searchable="false">{{ trans('admin/departments/table.name') }}</th> <th data-sortable="true" data-formatter="departmentsLinkFormatter" data-field="name" data-searchable="false">{{ trans('admin/departments/table.name') }}</th>
<th data-sortable="true" data-field="image" data-visible="false" data-formatter="imageFormatter">{{ trans('general.image') }}</th> <th data-sortable="true" data-field="image" data-visible="false" data-formatter="imageFormatter">{{ trans('general.image') }}</th>
<th data-sortable="false" data-formatter="usersLinkObjFormatter" data-field="manager" data-searchable="false">{{ trans('admin/departments/table.manager') }}</th> <th data-sortable="true" data-formatter="usersLinkObjFormatter" data-field="manager" data-searchable="false">{{ trans('admin/departments/table.manager') }}</th>
<th data-sortable="false" data-field="users_count" data-searchable="false">{{ trans('general.users') }}</th> <th data-sortable="true" data-field="users_count" data-searchable="false">{{ trans('general.users') }}</th>
<th data-sortable="false" data-formatter="locationsLinkObjFormatter" data-field="location" data-searchable="false">{{ trans('admin/departments/table.location') }}</th> <th data-sortable="true" data-formatter="locationsLinkObjFormatter" data-field="location" data-searchable="false">{{ trans('admin/departments/table.location') }}</th>
<th data-sortable="false" data-formatter="departmentsActionsFormatter" data-field="actions" data-searchable="false">{{ trans('table.actions') }}</th> <th data-sortable="false" data-formatter="departmentsActionsFormatter" data-field="actions" data-searchable="false">{{ trans('table.actions') }}</th>
</tr> </tr>

View file

@ -26,11 +26,13 @@
data-pagination="true" data-pagination="true"
data-id-table="statuslabelsTable" data-id-table="statuslabelsTable"
data-search="true" data-search="true"
data-show-footer="false"
data-side-pagination="server" data-side-pagination="server"
data-show-columns="true" data-show-columns="true"
data-show-export="true" data-show-export="true"
data-show-refresh="true" data-show-refresh="true"
data-sort-order="asc" data-sort-order="asc"
data-sort-name="name"
id="statuslabelsTable" id="statuslabelsTable"
class="table table-striped snipe-table" class="table table-striped snipe-table"
data-url="{{ route('api.statuslabels.index') }}" data-url="{{ route('api.statuslabels.index') }}"
@ -44,9 +46,9 @@
<th data-sortable="true" data-field="name" data-formatter="statuslabelsAssetLinkFormatter">{{ trans('admin/statuslabels/table.name') }}</th> <th data-sortable="true" data-field="name" data-formatter="statuslabelsAssetLinkFormatter">{{ trans('admin/statuslabels/table.name') }}</th>
<th data-sortable="false" data-field="type" data-formatter="statusLabelTypeFormatter">{{ trans('admin/statuslabels/table.status_type') }}</th> <th data-sortable="false" data-field="type" data-formatter="statusLabelTypeFormatter">{{ trans('admin/statuslabels/table.status_type') }}</th>
<th data-sortable="true" data-field="assets_count">{{ trans('general.assets') }}</th> <th data-sortable="true" data-field="assets_count">{{ trans('general.assets') }}</th>
<th data-sortable="false" data-field="color" data-formatter="colorSqFormatter">{{ trans('admin/statuslabels/table.color') }}</th> <th data-sortable="true" data-field="color" data-formatter="colorSqFormatter">{{ trans('admin/statuslabels/table.color') }}</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 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-formatter="statuslabelsActionsFormatter" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
</tr> </tr>
</thead> </thead>
</table> </table>