mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Added some simple tables for searching, subcategories and tags.
This commit is contained in:
parent
f402145c51
commit
4c5b5b6df0
4 changed files with 79 additions and 27 deletions
|
@ -30,6 +30,7 @@
|
|||
namespace App\Controller;
|
||||
|
||||
use App\DataTables\PartsDataTable;
|
||||
use App\Entity\Parts\Category;
|
||||
use Omines\DataTablesBundle\DataTableFactory;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
@ -44,19 +45,46 @@ class PartListsController extends AbstractController
|
|||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function showCategory(int $id, Request $request, DataTableFactory $dataTable)
|
||||
public function showCategory(Category $category, Request $request, DataTableFactory $dataTable)
|
||||
{
|
||||
/*$table = $dataTable->create()
|
||||
->add("id", TextColumn::class)
|
||||
->add("name", TextColumn::class)
|
||||
->add("description", TextColumn::class)
|
||||
->add("category", TextColumn::class, ['field' => 'category.name'])
|
||||
->createAdapter(ORMAdapter::class, [
|
||||
'entity' => Part::class
|
||||
])
|
||||
->handleRequest($request); */
|
||||
$table = $dataTable->createFromType(PartsDataTable::class, ['category' => $category])
|
||||
->handleRequest($request);
|
||||
|
||||
$table = $dataTable->createFromType(PartsDataTable::class, ['cid' => $id])
|
||||
if ($table->isCallback()) {
|
||||
return $table->getResponse();
|
||||
}
|
||||
|
||||
return $this->render('parts_list.html.twig', ['datatable' => $table]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/parts/by_tag/{tag}", name="part_list_tags")
|
||||
* @param string $tag
|
||||
* @param Request $request
|
||||
* @param DataTableFactory $dataTable
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function showTag(string $tag, Request $request, DataTableFactory $dataTable)
|
||||
{
|
||||
$table = $dataTable->createFromType(PartsDataTable::class, ['tag' => $tag])
|
||||
->handleRequest($request);
|
||||
|
||||
if ($table->isCallback()) {
|
||||
return $table->getResponse();
|
||||
}
|
||||
|
||||
return $this->render('parts_list.html.twig', ['datatable' => $table]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/parts/search/{keyword}", name="parts_search")
|
||||
*/
|
||||
public function showSearch(Request $request, DataTableFactory $dataTable, string $keyword = "")
|
||||
{
|
||||
$search = $keyword;
|
||||
dump($search);
|
||||
|
||||
$table = $dataTable->createFromType(PartsDataTable::class, ['search' => $search])
|
||||
->handleRequest($request);
|
||||
|
||||
if ($table->isCallback()) {
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
namespace App\DataTables;
|
||||
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
@ -50,6 +51,30 @@ class PartsDataTable implements DataTableTypeInterface
|
|||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
protected function buildCriteria(QueryBuilder $builder, array $options)
|
||||
{
|
||||
if (isset($options['category'])) {
|
||||
$em = $builder->getEntityManager();
|
||||
$category = $options['category'];
|
||||
$repo = $em->getRepository(Category::class);
|
||||
$list = $repo->toNodesList($category);
|
||||
$list[] = $category;
|
||||
|
||||
$builder->andWhere('part.category IN (:cid)')->setParameter('cid', $list);
|
||||
}
|
||||
|
||||
if (isset($options['tag'])) {
|
||||
$builder->andWhere('part.tags LIKE :tag')->setParameter('tag', '%' . $options['tag'] . '%');
|
||||
}
|
||||
|
||||
dump($options['search']);
|
||||
|
||||
if (isset($options['search'])) {
|
||||
$builder->AndWhere('part.name LIKE :search')->orWhere('part.description LIKE :search')->orWhere('part.comment LIKE :search')
|
||||
->setParameter('search', '%' . $options['search'] . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataTable $dataTable
|
||||
* @param array $options
|
||||
|
@ -63,21 +88,18 @@ class PartsDataTable implements DataTableTypeInterface
|
|||
}, ])
|
||||
->add('description', TextColumn::class, ['label' => 'description.label'])
|
||||
->add('category', TextColumn::class, ['field' => 'category.name', 'label' => 'category.label'])
|
||||
->add('instock', TextColumn::class, ['label' => 'instock.label_short'])
|
||||
->add('mininstock', TextColumn::class, ['label' => 'mininstock.label_short'])
|
||||
->add('amountSum', TextColumn::class, ['label' => 'instock.label_short'])
|
||||
->add('minamount', TextColumn::class, ['label' => 'mininstock.label_short'])
|
||||
//->add('storelocation', TextColumn::class, ['field' => 'storelocation.name', 'label' => 'storelocation.label'])
|
||||
->addOrderBy('name')
|
||||
->createAdapter(ORMAdapter::class, [
|
||||
'entity' => Part::class,
|
||||
'criteria' => [
|
||||
function (QueryBuilder $builder) use ($options) {
|
||||
if (isset($options['cid'])) {
|
||||
$builder->andWhere('part.category = :cid')
|
||||
->setParameter('cid', $options['cid']);
|
||||
}
|
||||
$this->buildCriteria($builder, $options);
|
||||
},
|
||||
new SearchCriteriaProvider(),
|
||||
],
|
||||
new SearchCriteriaProvider()
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<div class="collapse navbar-collapse" id="navbarContent">
|
||||
<div class="form-inline my-2 my-lg-0 ml-auto" id="searchbar">
|
||||
<!-- Searchbar -->
|
||||
<form action="{$relative_path}show_search_parts.php" method="get">
|
||||
<form action="" method="get">
|
||||
<div class="dropdown d-inline">
|
||||
<button class="btn btn-light dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
{% trans %}search.options.label{% endtrans %}
|
||||
|
@ -52,8 +52,10 @@
|
|||
<label for="regex" class="form-check-label">{% trans %}search.regexmatching{% endtrans %}</label></div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="search" class="form-control mr-sm-2" placeholder="{% trans %}search.placeholder{% endtrans %}" name="keyword" onkeyup="livesearch(event, this, 2);">
|
||||
<button type="submit" id="search-submit" class="btn btn-outline-secondary my-2">{% trans %}go.exclamation{% endtrans %}</button>
|
||||
|
||||
<input type="search" class="form-control mr-sm-2" placeholder="{% trans %}search.placeholder{% endtrans %}" name="keyword"
|
||||
onkeyup="$('#search-submit').attr('href', $('#search-submit').data('href') + '/' + $(this).val());">
|
||||
<a id="search-submit" href="#" role="button" data-href="{{ url('parts_search', {'keyword': ''}) }}" class="btn btn-outline-secondary my-2">{% trans %}go.exclamation{% endtrans %}</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
|
||||
{% macro string_to_tags(string, class="badge badge-info") %}
|
||||
{% for tag in string|split(',') %}
|
||||
<a href="#" class="{{ class }}" >{{ tag | trim }}</a>
|
||||
<a href="{{ url('part_list_tags', {'tag': tag | trim}) }}" class="{{ class }}" >{{ tag | trim }}</a>
|
||||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue