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;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\DataTables\PartsDataTable;
|
use App\DataTables\PartsDataTable;
|
||||||
|
use App\Entity\Parts\Category;
|
||||||
use Omines\DataTablesBundle\DataTableFactory;
|
use Omines\DataTablesBundle\DataTableFactory;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
@ -44,19 +45,9 @@ class PartListsController extends AbstractController
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
* @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()
|
$table = $dataTable->createFromType(PartsDataTable::class, ['category' => $category])
|
||||||
->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, ['cid' => $id])
|
|
||||||
->handleRequest($request);
|
->handleRequest($request);
|
||||||
|
|
||||||
if ($table->isCallback()) {
|
if ($table->isCallback()) {
|
||||||
|
@ -66,6 +57,43 @@ class PartListsController extends AbstractController
|
||||||
return $this->render('parts_list.html.twig', ['datatable' => $table]);
|
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()) {
|
||||||
|
return $table->getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('parts_list.html.twig', ['datatable' => $table]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/parts", name="parts_show_all")
|
* @Route("/parts", name="parts_show_all")
|
||||||
*
|
*
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
namespace App\DataTables;
|
namespace App\DataTables;
|
||||||
|
|
||||||
|
use App\Entity\Parts\Category;
|
||||||
use App\Entity\Parts\Part;
|
use App\Entity\Parts\Part;
|
||||||
use App\Services\EntityURLGenerator;
|
use App\Services\EntityURLGenerator;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
@ -50,6 +51,30 @@ class PartsDataTable implements DataTableTypeInterface
|
||||||
$this->urlGenerator = $urlGenerator;
|
$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 DataTable $dataTable
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
@ -57,27 +82,24 @@ class PartsDataTable implements DataTableTypeInterface
|
||||||
public function configure(DataTable $dataTable, array $options)
|
public function configure(DataTable $dataTable, array $options)
|
||||||
{
|
{
|
||||||
$dataTable//->add("id", TextColumn::class)
|
$dataTable//->add("id", TextColumn::class)
|
||||||
->add('name', TextColumn::class, ['label' => 'name.label',
|
->add('name', TextColumn::class, ['label' => 'name.label',
|
||||||
'render' => function ($value, Part $context) {
|
'render' => function ($value, Part $context) {
|
||||||
return $this->urlGenerator->infoHTML($context);
|
return $this->urlGenerator->infoHTML($context);
|
||||||
}, ])
|
}, ])
|
||||||
->add('description', TextColumn::class, ['label' => 'description.label'])
|
->add('description', TextColumn::class, ['label' => 'description.label'])
|
||||||
->add('category', TextColumn::class, ['field' => 'category.name', 'label' => 'category.label'])
|
->add('category', TextColumn::class, ['field' => 'category.name', 'label' => 'category.label'])
|
||||||
->add('instock', TextColumn::class, ['label' => 'instock.label_short'])
|
->add('amountSum', TextColumn::class, ['label' => 'instock.label_short'])
|
||||||
->add('mininstock', TextColumn::class, ['label' => 'mininstock.label_short'])
|
->add('minamount', TextColumn::class, ['label' => 'mininstock.label_short'])
|
||||||
//->add('storelocation', TextColumn::class, ['field' => 'storelocation.name', 'label' => 'storelocation.label'])
|
//->add('storelocation', TextColumn::class, ['field' => 'storelocation.name', 'label' => 'storelocation.label'])
|
||||||
->addOrderBy('name')
|
->addOrderBy('name')
|
||||||
->createAdapter(ORMAdapter::class, [
|
->createAdapter(ORMAdapter::class, [
|
||||||
'entity' => Part::class,
|
'entity' => Part::class,
|
||||||
'criteria' => [
|
'criteria' => [
|
||||||
function (QueryBuilder $builder) use ($options) {
|
function (QueryBuilder $builder) use ($options) {
|
||||||
if (isset($options['cid'])) {
|
$this->buildCriteria($builder, $options);
|
||||||
$builder->andWhere('part.category = :cid')
|
},
|
||||||
->setParameter('cid', $options['cid']);
|
new SearchCriteriaProvider()
|
||||||
}
|
]
|
||||||
},
|
|
||||||
new SearchCriteriaProvider(),
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<div class="collapse navbar-collapse" id="navbarContent">
|
<div class="collapse navbar-collapse" id="navbarContent">
|
||||||
<div class="form-inline my-2 my-lg-0 ml-auto" id="searchbar">
|
<div class="form-inline my-2 my-lg-0 ml-auto" id="searchbar">
|
||||||
<!-- Searchbar -->
|
<!-- Searchbar -->
|
||||||
<form action="{$relative_path}show_search_parts.php" method="get">
|
<form action="" method="get">
|
||||||
<div class="dropdown d-inline">
|
<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">
|
<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 %}
|
{% trans %}search.options.label{% endtrans %}
|
||||||
|
@ -52,8 +52,10 @@
|
||||||
<label for="regex" class="form-check-label">{% trans %}search.regexmatching{% endtrans %}</label></div>
|
<label for="regex" class="form-check-label">{% trans %}search.regexmatching{% endtrans %}</label></div>
|
||||||
</div>
|
</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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
|
|
||||||
{% macro string_to_tags(string, class="badge badge-info") %}
|
{% macro string_to_tags(string, class="badge badge-info") %}
|
||||||
{% for tag in string|split(',') %}
|
{% 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 %}
|
{% endfor %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue