mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Added manufacturers and categories select lists
This commit is contained in:
parent
c6d191bcba
commit
00d910ddbc
|
@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
|
|||
use App\Helpers\Helper;
|
||||
use App\Models\Category;
|
||||
use App\Http\Transformers\CategoriesTransformer;
|
||||
use App\Http\Transformers\SelectlistTransformer;
|
||||
|
||||
class CategoriesController extends Controller
|
||||
{
|
||||
|
@ -128,4 +129,42 @@ class CategoriesController extends Controller
|
|||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/categories/message.delete.success')));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a paginated collection for the select2 menus
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0.16]
|
||||
* @see \App\Http\Transformers\SelectlistTransformer
|
||||
*
|
||||
*/
|
||||
public function selectlist(Request $request)
|
||||
{
|
||||
$this->authorize('view', Categories::class);
|
||||
|
||||
$categories = Category::select([
|
||||
'id',
|
||||
'name',
|
||||
'image',
|
||||
]);
|
||||
|
||||
if ($request->has('search')) {
|
||||
$categories = $categories->where('name', 'LIKE', '%'.$request->get('search').'%');
|
||||
}
|
||||
|
||||
$categories = $categories->orderBy('name', 'ASC')->paginate(50);
|
||||
|
||||
// Loop through and set some custom properties for the transformer to use.
|
||||
// This lets us have more flexibility in special cases like assets, where
|
||||
// they may not have a ->name value but we want to display something anyway
|
||||
foreach ($categories as $category) {
|
||||
$category->use_text = $category->name;
|
||||
$category->use_image = ($category->image) ? url('/').'/uploads/categories/'.$category->image : null;
|
||||
}
|
||||
|
||||
return (new SelectlistTransformer)->transformSelectlist($categories);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use App\Helpers\Helper;
|
|||
use App\Models\Manufacturer;
|
||||
use App\Http\Transformers\DatatablesTransformer;
|
||||
use App\Http\Transformers\ManufacturersTransformer;
|
||||
use App\Http\Transformers\SelectlistTransformer;
|
||||
|
||||
class ManufacturersController extends Controller
|
||||
{
|
||||
|
@ -120,4 +121,40 @@ class ManufacturersController extends Controller
|
|||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/manufacturers/message.delete.success')));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a paginated collection for the select2 menus
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0.16]
|
||||
* @see \App\Http\Transformers\SelectlistTransformer
|
||||
*
|
||||
*/
|
||||
public function selectlist(Request $request)
|
||||
{
|
||||
$this->authorize('view', Manufacturers::class);
|
||||
|
||||
$manufacturers = Manufacturer::select([
|
||||
'id',
|
||||
'name',
|
||||
'image',
|
||||
]);
|
||||
|
||||
if ($request->has('search')) {
|
||||
$manufacturers = $manufacturers->where('name', 'LIKE', '%'.$request->get('search').'%');
|
||||
}
|
||||
|
||||
$manufacturers = $manufacturers->orderBy('name', 'ASC')->paginate(50);
|
||||
|
||||
// Loop through and set some custom properties for the transformer to use.
|
||||
// This lets us have more flexibility in special cases like assets, where
|
||||
// they may not have a ->name value but we want to display something anyway
|
||||
foreach ($manufacturers as $manufacturer) {
|
||||
$manufacturer->use_text = $manufacturer->name;
|
||||
$manufacturer->use_image = ($manufacturer->image) ? url('/').'/uploads/manufacturers/'.$manufacturer->image : null;
|
||||
}
|
||||
|
||||
return (new SelectlistTransformer)->transformSelectlist($manufacturers);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
@section('inputFields')
|
||||
|
||||
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/models/table.name')])
|
||||
@include ('partials.forms.edit.manufacturer')
|
||||
@include ('partials.forms.edit.category')
|
||||
@include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id'])
|
||||
@include ('partials.forms.edit.category-select', ['translated_name' => trans('admin/categories/general.category_name'), 'fieldname' => 'category_id'])
|
||||
@include ('partials.forms.edit.model_number')
|
||||
@include ('partials.forms.edit.depreciation')
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<!-- Asset Model -->
|
||||
<div id="{{ $fieldname }}" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}">
|
||||
|
||||
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
|
||||
|
||||
<div class="col-md-7 required">
|
||||
<select class="js-data-ajax" data-endpoint="categories" name="{{ $fieldname }}" style="width: 100%" id="category_select_id">
|
||||
@if ($category_id = Input::old($fieldname, $item->{$fieldname}))
|
||||
<option value="{{ $category_id }}" selected="selected">
|
||||
{{ \App\Models\Category::find($category_id)->name }}
|
||||
</option>
|
||||
@else
|
||||
<option value="">{{ trans('general.select_category') }}</option>
|
||||
@endif
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
{!! $errors->first($fieldname, '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!}
|
||||
</div>
|
|
@ -0,0 +1,21 @@
|
|||
<!-- Asset Model -->
|
||||
<div id="{{ $fieldname }}" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}">
|
||||
|
||||
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
|
||||
|
||||
<div class="col-md-7 required">
|
||||
<select class="js-data-ajax" data-endpoint="manufacturers" name="{{ $fieldname }}" style="width: 100%" id="category_select_id">
|
||||
@if ($manufacturer_id = Input::old($fieldname, $item->{$fieldname}))
|
||||
<option value="{{ $manufacturer_id }}" selected="selected">
|
||||
{{ \App\Models\Manufacturer::find($manufacturer_id)->name }}
|
||||
</option>
|
||||
@else
|
||||
<option value="">{{ trans('general.select_manufacturer') }}</option>
|
||||
@endif
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
{!! $errors->first($fieldname, '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!}
|
||||
</div>
|
|
@ -45,6 +45,17 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|||
|
||||
/*--- Categories API ---*/
|
||||
|
||||
Route::group(['prefix' => 'categories'], function () {
|
||||
|
||||
Route::get('selectlist',
|
||||
[
|
||||
'as' => 'api.categories.selectlist',
|
||||
'uses' => 'CategoriesController@selectlist'
|
||||
]
|
||||
);
|
||||
}); // Categories group
|
||||
|
||||
|
||||
Route::resource('categories', 'CategoriesController',
|
||||
[
|
||||
'names' =>
|
||||
|
@ -395,6 +406,15 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|||
|
||||
/*--- Manufacturers API ---*/
|
||||
|
||||
Route::group(['prefix' => 'manufacturers'], function () {
|
||||
|
||||
Route::get( 'selectlist', [
|
||||
'as' => 'manufacturers.selectlist',
|
||||
'uses' => 'ManufacturersController@selectlist'
|
||||
]);
|
||||
}); // Locations group
|
||||
|
||||
|
||||
Route::resource('manufacturers', 'ManufacturersController',
|
||||
[
|
||||
'names' =>
|
||||
|
|
Loading…
Reference in a new issue