Skip to content

Commit

Permalink
Search by asset tag
Browse files Browse the repository at this point in the history
Compatible with barcode scanners
  • Loading branch information
snipe committed May 21, 2016
1 parent b796e72 commit fb35e40
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
16 changes: 15 additions & 1 deletion app/Http/Controllers/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function __construct()
parent::__construct();
}


/**
* Returns a view that invokes the ajax tables which actually contains
* the content for the assets listing, which is generated in getDatatable.
Expand All @@ -74,6 +73,21 @@ public function getIndex()
return View::make('hardware/index');
}

/**
* Searches the assets table by asset tag, and redirects if it finds one
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.0]
* @return Redirect
*/
public function getAssetByTag() {
if ($asset = Asset::where('asset_tag','=',Input::get('assetTag'))->first()) {
return redirect()->route('view/hardware', $asset->id);
}
return redirect()->to('hardware')->with('error',trans('admin/hardware/message.does_not_exist'));

}

/**
* Returns a view that presents a form to create a new asset.
*
Expand Down
4 changes: 4 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ function () {
'as' => 'update/hardware',
'uses' => 'AssetsController@getEdit'
]);
Route::get('/bytag', [
'as' => 'findbytag/hardware',
'uses' => 'AssetsController@getAssetByTag'
]);

Route::get('{assetId}/clone', [ 'as' => 'clone/hardware', 'uses' => 'AssetsController@getClone' ]);
Route::post('{assetId}/clone', 'AssetsController@postCreate');
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
'location' => 'Location',
'locations' => 'Locations',
'logout' => 'Logout',
'lookup_by_tag' => 'Lookup by Asset Tag',
'manufacturer' => 'Manufacturer',
'manufacturers' => 'Manufacturers',
'markdown' => 'This field allows <a href="https://help.github.com/articles/github-flavored-markdown/">Github flavored markdown</a>.',
Expand Down
12 changes: 11 additions & 1 deletion resources/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@
<ul class="nav navbar-nav">

@if (Auth::user()->hasAccess('admin'))
<form class="navbar-form navbar-left" role="search" action="{{ route('findbytag/hardware') }}" method="get">
<div class="form-group">
<input type="text" class="form-control" id="tagSearch" name="assetTag" placeholder="{{ trans('general.lookup_by_tag') }}">
<input type="hidden" name="topsearch" value="true">
</div>
<button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
</form>

<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
@lang('general.create')
Expand Down Expand Up @@ -540,7 +548,9 @@
@section('moar_scripts')
@show


<script>
// $("#tagSearch").focus();
</script>

</body>
</html>

0 comments on commit fb35e40

Please sign in to comment.