diff --git a/app/Http/Controllers/Api/AssetModelsController.php b/app/Http/Controllers/Api/AssetModelsController.php index 4003511c9e..24f2451d55 100644 --- a/app/Http/Controllers/Api/AssetModelsController.php +++ b/app/Http/Controllers/Api/AssetModelsController.php @@ -36,14 +36,15 @@ class AssetModelsController extends Controller ->with('category','depreciation', 'manufacturer','fieldset') ->withCount('assets'); - if ($request->has('search')) { - $assetmodels->TextSearch($request->input('search')); - } + if ($request->has('status')) { $assetmodels->onlyTrashed(); } + if ($request->has('search')) { + $assetmodels->TextSearch($request->input('search')); + } $offset = $request->input('offset', 0); $limit = $request->input('limit', 50); @@ -60,6 +61,7 @@ class AssetModelsController extends Controller } + $total = $assetmodels->count(); $assetmodels = $assetmodels->skip($offset)->take($limit)->get(); return (new AssetModelsTransformer)->transformAssetModels($assetmodels, $total); diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 0c5f7c013b..bdde23cc27 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -54,6 +54,7 @@ class AssetsController extends Controller */ public function index(Request $request) { + $this->authorize('index', Asset::class); $allowed_columns = [ @@ -78,30 +79,28 @@ class AssetsController extends Controller ]; $filter = array(); + if ($request->has('filter')) { $filter = json_decode($request->input('filter')); } - $all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load foreach ($all_custom_fields as $field) { $allowed_columns[]=$field->db_column_name(); } - $assets = Company::scopeCompanyables(Asset::select('assets.*'),"company_id","assets")->with( - 'location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo', + $assets = Company::scopeCompanyables(Asset::select('assets.*'),"company_id","assets") + ->with('location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo', 'model.category', 'model.manufacturer', 'model.fieldset','supplier'); - if (count($filter) > 0) { - $assets->ByFilter($filter); - } elseif ($request->has('search')) { - $assets->TextSearch($request->input('search')); - } - // These are used by the API to query against specific ID numbers + + // These are used by the API to query against specific ID numbers. + // They are also used by the individual searches on detail pages like + // locations, etc. if ($request->has('status_id')) { $assets->where('assets.status_id', '=', $request->input('status_id')); } @@ -116,6 +115,7 @@ class AssetsController extends Controller if ($request->has('location_id')) { $assets->where('assets.location_id', '=', $request->input('location_id')); + // dd($assets->toSql()); } if ($request->has('supplier_id')) { @@ -145,7 +145,6 @@ class AssetsController extends Controller $limit = $request->input('limit', 50); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; - // This is used by the sidenav, mostly // We switched from using query scopes here because of a Laravel bug @@ -205,6 +204,12 @@ class AssetsController extends Controller }); } + if (count($filter) > 0) { + $assets->ByFilter($filter); + } elseif ($request->has('search')) { + $assets->TextSearch($request->input('search')); + } + // This is kinda gross, but we need to do this because the Bootstrap Tables // API passes custom field ordering as custom_fields.fieldname, and we have to strip diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 59ef32e617..3d9614caa3 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -25,9 +25,6 @@ class LicensesController extends Controller $this->authorize('view', License::class); $licenses = Company::scopeCompanyables(License::with('company', 'manufacturer', 'freeSeats', 'supplier')->withCount('freeSeats')); - if ($request->has('search')) { - $licenses = $licenses->TextSearch($request->input('search')); - } if ($request->has('company_id')) { $licenses->where('company_id','=',$request->input('company_id')); @@ -73,6 +70,12 @@ class LicensesController extends Controller $licenses->where('supplier_id','=',$request->input('supplier_id')); } + + if ($request->has('search')) { + $licenses = $licenses->TextSearch($request->input('search')); + } + + $offset = request('offset', 0); $limit = request('limit', 50); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; @@ -94,7 +97,8 @@ class LicensesController extends Controller $licenses = $licenses->orderBy($sort, $order); break; } - + + $total = $licenses->count(); diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 27bb31fbf5..4d12c7bd71 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -58,11 +58,6 @@ class UsersController extends Controller $users = Company::scopeCompanyables($users); - if ($request->has('search')) { - $users = $users->TextSearch($request->input('search')); - } - - if (($request->has('deleted')) && ($request->input('deleted')=='true')) { $users = $users->GetDeleted(); } @@ -83,6 +78,10 @@ class UsersController extends Controller $users = $users->where('users.department_id','=',$request->input('department_id')); } + if ($request->has('search')) { + $users = $users->TextSearch($request->input('search')); + } + $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $offset = request('offset', 0); $limit = request('limit', 20); @@ -111,6 +110,8 @@ class UsersController extends Controller $users = $users->orderBy($sort, $order); break; } + + $total = $users->count(); $users = $users->skip($offset)->take($limit)->get(); return (new UsersTransformer)->transformUsers($users, $total);