mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Gross copypasta fix for #1932
This commit is contained in:
parent
23e416fd88
commit
47c70141c7
|
@ -300,33 +300,10 @@ class CategoriesController extends Controller
|
|||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns JSON response that contains the data for the category detail page.
|
||||
*
|
||||
* @todo Refactor this nastiness. Assets do not behave
|
||||
* the same as accessories, etc. Need to figure out if I should
|
||||
* make separate controllers, or what. Too much copypasta if I try to work it in here.
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @see CategoriesController::getView() method that generates the view
|
||||
* @param int $categoryId
|
||||
* @since [v1.8]
|
||||
* @return String JSON
|
||||
*/
|
||||
public function getDataView($categoryId)
|
||||
{
|
||||
public function getDataViewAssets($categoryID) {
|
||||
|
||||
$category = Category::find($categoryId);
|
||||
|
||||
if ($category->category_type =='asset') {
|
||||
$category = Category::with('assets.company')->find($categoryID);
|
||||
$category_assets = $category->assets;
|
||||
} elseif ($category->category_type =='accessory') {
|
||||
$category_assets = $category->accessories;
|
||||
} elseif ($category->category_type =='consumable') {
|
||||
$category_assets = $category->consumables;
|
||||
} elseif ($category->category_type =='component') {
|
||||
$category_assets = $category->components;
|
||||
}
|
||||
|
||||
|
||||
if (Input::has('search')) {
|
||||
$category_assets = $category_assets->TextSearch(e(Input::get('search')));
|
||||
|
@ -354,22 +331,11 @@ class CategoriesController extends Controller
|
|||
|
||||
foreach ($category_assets as $asset) {
|
||||
|
||||
if ($category->category_type=='asset') {
|
||||
$category_type = 'hardware';
|
||||
} else {
|
||||
$category_type = $category->category_type;
|
||||
}
|
||||
|
||||
$actions = '';
|
||||
$inout='';
|
||||
|
||||
if ($asset->deleted_at=='') {
|
||||
$actions = '<div style=" white-space: nowrap;">';
|
||||
if ($category_type != 'component') {
|
||||
$actions .= '<a href="'.route('clone/'.$category_type, $asset->id).'" class="btn btn-info btn-sm" title="Clone '.$category_type.'"><i class="fa fa-files-o"></i></a> ';
|
||||
}
|
||||
$actions .= '<a href="'.route('update/'.$category_type, $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> ';
|
||||
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/'.$category_type, $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->asset_tag).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
|
||||
$actions = '<div style=" white-space: nowrap;"><a href="'.route('clone/hardware', $asset->id).'" class="btn btn-info btn-sm" title="Clone asset"><i class="fa fa-files-o"></i></a> <a href="'.route('update/hardware', $asset->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/hardware', $asset->id).'" data-content="'.Lang::get('admin/hardware/message.delete.confirm').'" data-title="'.Lang::get('general.delete').' '.htmlspecialchars($asset->asset_tag).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
|
||||
} elseif ($asset->deleted_at!='') {
|
||||
$actions = '<a href="'.route('restore/hardware', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';
|
||||
}
|
||||
|
@ -377,20 +343,20 @@ class CategoriesController extends Controller
|
|||
if ($asset->assetstatus) {
|
||||
if ($asset->assetstatus->deployable != 0) {
|
||||
if (($asset->assigned_to !='') && ($asset->assigned_to > 0)) {
|
||||
$inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>';
|
||||
$inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.Lang::get('general.checkin').'</a>';
|
||||
} else {
|
||||
$inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>';
|
||||
$inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.Lang::get('general.checkout').'</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rows[] = array(
|
||||
'id' => $asset->id,
|
||||
'name' => (string)link_to('/hardware/'.$asset->id.'/view', e($asset->name)),
|
||||
//'model' => $asset->model->name,
|
||||
'asset_tag' => e($asset->asset_tag),
|
||||
'serial' => e($asset->serial),
|
||||
'assigned_to' => ($asset->assigneduser) ? (string)link_to(config('app.url').'/admin/users/'.$asset->assigneduser->id.'/view', $asset->assigneduser->fullName()): '',
|
||||
'name' => (string)link_to('/hardware/'.$asset->id.'/view', $asset->showAssetName()),
|
||||
'model' => $asset->model->name,
|
||||
'asset_tag' => $asset->asset_tag,
|
||||
'serial' => $asset->serial,
|
||||
'assigned_to' => ($asset->assigneduser) ? link_to('/admin/users/'.$asset->assigneduser->id.'/view', $asset->assigneduser->fullName()): '',
|
||||
'change' => $inout,
|
||||
'actions' => $actions,
|
||||
'companyName' => Company::getName($asset),
|
||||
|
@ -400,4 +366,166 @@ class CategoriesController extends Controller
|
|||
$data = array('total' => $count, 'rows' => $rows);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getDataViewAccessories($categoryID) {
|
||||
|
||||
$category = Category::with('accessories.company')->find($categoryID);
|
||||
$category_assets = $category->accessories;
|
||||
|
||||
if (Input::has('search')) {
|
||||
$category_assets = $category_assets->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;
|
||||
}
|
||||
|
||||
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
$allowed_columns = ['id','name','serial','asset_tag'];
|
||||
$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
|
||||
$count = $category_assets->count();
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($category_assets as $asset) {
|
||||
|
||||
$actions = '';
|
||||
$inout='';
|
||||
|
||||
if ($asset->deleted_at=='') {
|
||||
$actions = '<div style=" white-space: nowrap;"><a href="'.route('update/accessory', $asset->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/accessory', $asset->id).'" data-content="'.Lang::get('admin/hardware/message.delete.confirm').'" data-title="'.Lang::get('general.delete').' '.htmlspecialchars($asset->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
$rows[] = array(
|
||||
'id' => $asset->id,
|
||||
'name' => (string)link_to_route('view/accessory', $asset->name, [$asset->id]),
|
||||
'actions' => $actions,
|
||||
'companyName' => Company::getName($asset),
|
||||
);
|
||||
}
|
||||
|
||||
$data = array('total' => $count, 'rows' => $rows);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function getDataViewConsumables($categoryID) {
|
||||
|
||||
$category = Category::with('accessories.company')->find($categoryID);
|
||||
$category_assets = $category->consumables;
|
||||
|
||||
if (Input::has('search')) {
|
||||
$category_assets = $category_assets->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;
|
||||
}
|
||||
|
||||
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
$allowed_columns = ['id','name','serial','asset_tag'];
|
||||
$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
|
||||
$count = $category_assets->count();
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($category_assets as $asset) {
|
||||
|
||||
$actions = '';
|
||||
$inout='';
|
||||
|
||||
if ($asset->deleted_at=='') {
|
||||
$actions = '<div style=" white-space: nowrap;"><a href="'.route('update/consumable', $asset->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/consumable', $asset->id).'" data-content="'.Lang::get('admin/hardware/message.delete.confirm').'" data-title="'.Lang::get('general.delete').' '.htmlspecialchars($asset->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
$rows[] = array(
|
||||
'id' => $asset->id,
|
||||
'name' => (string) link_to_route('view/consumable', $asset->name, [$asset->id]),
|
||||
'actions' => $actions,
|
||||
'companyName' => Company::getName($asset),
|
||||
);
|
||||
}
|
||||
|
||||
$data = array('total' => $count, 'rows' => $rows);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getDataViewComponent($categoryID) {
|
||||
|
||||
$category = Category::with('accessories.company')->find($categoryID);
|
||||
$category_assets = $category->components;
|
||||
|
||||
if (Input::has('search')) {
|
||||
$category_assets = $category_assets->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;
|
||||
}
|
||||
|
||||
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
$allowed_columns = ['id','name','serial','asset_tag'];
|
||||
$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
|
||||
$count = $category_assets->count();
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($category_assets as $asset) {
|
||||
|
||||
$actions = '';
|
||||
$inout='';
|
||||
|
||||
if ($asset->deleted_at=='') {
|
||||
$actions = '<div style=" white-space: nowrap;"><a href="'.route('update/component', $asset->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/component', $asset->id).'" data-content="'.Lang::get('admin/hardware/message.delete.confirm').'" data-title="'.Lang::get('general.delete').' '.htmlspecialchars($asset->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
$rows[] = array(
|
||||
'id' => $asset->id,
|
||||
'name' => (string)link_to_route('view/accessory', $asset->name, [$asset->id]),
|
||||
'actions' => $actions,
|
||||
'companyName' => Company::getName($asset),
|
||||
);
|
||||
}
|
||||
|
||||
$data = array('total' => $count, 'rows' => $rows);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -137,10 +137,14 @@ Route::group([ 'prefix' => 'api', 'middleware' => 'auth' ], function () {
|
|||
Route::group([ 'prefix' => 'categories' ], function () {
|
||||
|
||||
Route::get('list', [ 'as' => 'api.categories.list', 'uses' => 'CategoriesController@getDatatable' ]);
|
||||
Route::get(
|
||||
'{categoryID}/view',
|
||||
[ 'as' => 'api.categories.view', 'uses' => 'CategoriesController@getDataView' ]
|
||||
);
|
||||
Route::get( '{categoryID}/asset/view',
|
||||
[ 'as' => 'api.categories.asset.view', 'uses' => 'CategoriesController@getDataViewAssets' ] );
|
||||
Route::get( '{categoryID}/accessory/view',
|
||||
[ 'as' => 'api.categories.accessory.view', 'uses' => 'CategoriesController@getDataViewAccessories' ] );
|
||||
Route::get( '{categoryID}/consumable/view',
|
||||
[ 'as' => 'api.categories.consumable.view', 'uses' => 'CategoriesController@getDataViewConsumables' ] );
|
||||
Route::get( '{categoryID}/component/view',
|
||||
[ 'as' => 'api.categories.component.view', 'uses' => 'CategoriesController@getDataViewComponent' ] );
|
||||
});
|
||||
|
||||
/*-- Suppliers API (mostly for creating new ones in-line while creating an asset) --*/
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<table
|
||||
name="category_assets"
|
||||
id="table"
|
||||
data-url="{{ route('api.categories.view', $category->id) }}"
|
||||
data-url="{{ route('api.categories.'.$category->category_type.'.view', [$category->id, $category->category_type]) }}"
|
||||
data-cookie="true"
|
||||
data-click-to-select="true"
|
||||
data-cookie-id-table="categoryAssetsTable">
|
||||
|
@ -44,11 +44,13 @@
|
|||
</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="name">{{ trans('general.name') }}</th>
|
||||
@if ($category->category_type=='asset')
|
||||
<th data-searchable="false" data-sortable="false" data-field="model">{{ trans('admin/hardware/form.model') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="asset_tag">{{ trans('general.asset_tag') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="serial">{{ trans('admin/hardware/form.serial') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="assigned_to">{{ trans('general.user') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="change" data-switchable="false">{{ trans('admin/hardware/table.change') }}</th>
|
||||
@endif
|
||||
<th data-searchable="false" data-sortable="false" data-field="actions" data-switchable="false">{{ trans('table.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
Loading…
Reference in a new issue