Implement the search feature from the controller #182

This commit is contained in:
Korina Cordero 2019-03-14 04:44:59 -04:00
parent dc842aab5e
commit bd1009dac9
3 changed files with 59 additions and 1 deletions

View file

@ -1,3 +1,8 @@
general_search:
path: /search
controller: App\Controller\SearchController::index
search_history:
path: /search/history
controller: App\Controller\SearchController::search
methods: [POST]

View file

@ -3,6 +3,10 @@
namespace App\Controller;
use App\Ramcar\BaseController;
use App\Service\GeneralSearch;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Menu\Generator as MenuGenerator;
use App\Access\Generator as ACLGenerator;
@ -25,4 +29,27 @@ class SearchController extends BaseController
// response
return $this->render('search/list.html.twig', $params);
}
public function search(Request $req, GeneralSearch $search)
{
$this->denyAccessUnlessGranted('general.search', null, 'No access.');
$search_term = $req->request->get('data-rows-search');
$results = $search->search($search_term);
// process rows
// this is not how to process the results.
// TODO: fix this asap
$rows = [];
foreach ($obj_rows as $orow) {
// add row data
$row['id'] = $orow[0]->getID();
$rows[] = $row;
}
return $this->json([
'data' => $rows
]);
}
}

View file

@ -23,12 +23,14 @@
<div class="col-xl-8 order-2 order-xl-1">
<div class="form-group m-form__group row align-items-center">
<div class="col-md-4">
<form action= "{{ url('search_history') }}" method="post">
<div class="m-input-icon m-input-icon--left">
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search" >
<span class="m-input-icon__icon m-input-icon__icon--left">
<span><i class="la la-search"></i></span>
</span>
</div>
</form>
</div>
</div>
</div>
@ -46,6 +48,30 @@
{% block scripts %}
<script>
$(function() {
var options = {
data: {
pageSize: 10,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
columns: [
{
field: 'id',
title: 'ID',
width: 30
},
{
field: 'name',
title: 'name'
},
],
};
var table = $("#data-rows").mDatatable(options);
});
</script>
{% endblock %}