mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-23 12:44:12 -08:00
Fixed #4548 - add cateory to model dropdown
This commit is contained in:
parent
a4323a0308
commit
fdaa279930
|
@ -189,18 +189,18 @@ class AssetModelsController extends Controller
|
|||
'models.image',
|
||||
'models.model_number',
|
||||
'models.manufacturer_id',
|
||||
])->with('manufacturer')->OrderManufacturer('ASC');
|
||||
'models.category_id',
|
||||
])->with('manufacturer','category');
|
||||
|
||||
|
||||
if ($request->has('search')) {
|
||||
$assetmodels = $assetmodels->where('models.name', 'LIKE', '%'.$request->get('search').'%')
|
||||
->orWhere('models.model_number', 'LIKE', '%'.$request->get('search').'%');
|
||||
$assetmodels = $assetmodels->SearchByManufacturerOrCat($request->input('search'));
|
||||
}
|
||||
|
||||
$assetmodels = $assetmodels->orderby('models.name', 'asc')->orderby('models.model_number', 'asc')->paginate(50);
|
||||
$assetmodels = $assetmodels->OrderCategory('ASC')->OrderManufacturer('ASC')->orderby('models.name', 'asc')->orderby('models.model_number', 'asc')->paginate(50);
|
||||
|
||||
foreach ($assetmodels as $assetmodel) {
|
||||
$assetmodel->use_text = (($assetmodel->manufacturer) ? e($assetmodel->manufacturer->name) : '').' '.$assetmodel->present()->modelName;
|
||||
$assetmodel->use_text = (($assetmodel->category) ? e($assetmodel->category->name) : '').': '.(($assetmodel->manufacturer) ? e($assetmodel->manufacturer->name) : '').' '.$assetmodel->present()->modelName;
|
||||
$assetmodel->use_image = ($assetmodel->image) ? url('/').'/uploads/models/'.$assetmodel->image : null;
|
||||
}
|
||||
|
||||
|
|
|
@ -169,6 +169,32 @@ class AssetModel extends SnipeModel
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to search on text, including catgeory and manufacturer name
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $search Search term
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeSearchByManufacturerOrCat($query, $search)
|
||||
{
|
||||
|
||||
return $query->where('models.name', 'LIKE', "%$search%")
|
||||
->orWhere('model_number', 'LIKE', "%$search%")
|
||||
->orWhere(function ($query) use ($search) {
|
||||
$query->whereHas('category', function ($query) use ($search) {
|
||||
$query->where('categories.name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
})
|
||||
->orWhere(function ($query) use ($search) {
|
||||
$query->whereHas('manufacturer', function ($query) use ($search) {
|
||||
$query->where('manufacturers.name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on manufacturer
|
||||
*
|
||||
|
@ -182,5 +208,18 @@ class AssetModel extends SnipeModel
|
|||
return $query->leftJoin('manufacturers', 'models.manufacturer_id', '=', 'manufacturers.id')->orderBy('manufacturers.name', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on category name
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeOrderCategory($query, $order)
|
||||
{
|
||||
return $query->leftJoin('categories', 'models.category_id', '=', 'categories.id')->orderBy('categories.name', $order);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Binary file not shown.
BIN
public/js/dist/all.js
vendored
BIN
public/js/dist/all.js
vendored
Binary file not shown.
|
@ -8,7 +8,7 @@
|
|||
"/css/app.css.map": "/css/app.css.map?id=bdbe05e6ecd70ccfac72",
|
||||
"/css/overrides.css.map": "/css/overrides.css.map?id=898c91d4a425b01b589b",
|
||||
"/css/dist/all.css": "/css/dist/all.css?id=51e5995cec7ce583f5dd",
|
||||
"/js/dist/all.js": "/js/dist/all.js?id=7b52ead3a55086ea1f8d",
|
||||
"/js/dist/all.js": "/js/dist/all.js?id=88f08e0103b14f7949b3",
|
||||
"/css/build/all.css": "/css/build/all.css?id=51e5995cec7ce583f5dd",
|
||||
"/js/build/all.js": "/js/build/all.js?id=7b52ead3a55086ea1f8d"
|
||||
"/js/build/all.js": "/js/build/all.js?id=88f08e0103b14f7949b3"
|
||||
}
|
|
@ -241,9 +241,9 @@ $(document).ready(function () {
|
|||
var markup = "<div class='clearfix'>" ;
|
||||
markup +="<div class='pull-left' style='padding-right: 10px;'>";
|
||||
if (datalist.image) {
|
||||
markup += "<img src='" + datalist.image + "' style='max-height: 20px'>";
|
||||
markup += "<div style='width: 30px;'><img src='" + datalist.image + "' style='max-height: 20px; max-width: 30px;'></div>";
|
||||
} else {
|
||||
markup += "<div style='height: 20px; width: 20px;'></div>";
|
||||
markup += "<div style='height: 20px; width: 30px;'></div>";
|
||||
}
|
||||
|
||||
markup += "</div><div>" + datalist.text + "</div>";
|
||||
|
|
Loading…
Reference in a new issue