mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-29 13:10:06 +02:00
Use filter system for category parts list.
This commit is contained in:
parent
7c14ebaa28
commit
37a5c52907
2 changed files with 39 additions and 4 deletions
|
@ -55,6 +55,7 @@ use App\Services\Trees\NodesListBuilder;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Omines\DataTablesBundle\DataTableFactory;
|
use Omines\DataTablesBundle\DataTableFactory;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
@ -63,10 +64,12 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||||
class PartListsController extends AbstractController
|
class PartListsController extends AbstractController
|
||||||
{
|
{
|
||||||
private $entityManager;
|
private $entityManager;
|
||||||
|
private $nodesListBuilder;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $entityManager)
|
public function __construct(EntityManagerInterface $entityManager, NodesListBuilder $nodesListBuilder)
|
||||||
{
|
{
|
||||||
$this->entityManager = $entityManager;
|
$this->entityManager = $entityManager;
|
||||||
|
$this->nodesListBuilder = $nodesListBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,6 +103,25 @@ class PartListsController extends AbstractController
|
||||||
return $this->redirect($redirect);
|
return $this->redirect($redirect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable the given form interface after creation of the form by removing and reattaching the form.
|
||||||
|
* @param FormInterface $form
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function disableFormFieldAfterCreation(FormInterface $form, bool $disabled = true): void
|
||||||
|
{
|
||||||
|
$attrs = $form->getConfig()->getOptions();
|
||||||
|
$attrs['disabled'] = $disabled;
|
||||||
|
|
||||||
|
$parent = $form->getParent();
|
||||||
|
if ($parent === null) {
|
||||||
|
throw new \RuntimeException('This function can only be used on form fields that are children of another form!');
|
||||||
|
}
|
||||||
|
|
||||||
|
$parent->remove($form->getName());
|
||||||
|
$parent->add($form->getName(), get_class($form->getConfig()->getType()->getInnerType()), $attrs);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/category/{id}/parts", name="part_list_category")
|
* @Route("/category/{id}/parts", name="part_list_category")
|
||||||
*
|
*
|
||||||
|
@ -107,7 +129,17 @@ class PartListsController extends AbstractController
|
||||||
*/
|
*/
|
||||||
public function showCategory(Category $category, Request $request, DataTableFactory $dataTable)
|
public function showCategory(Category $category, Request $request, DataTableFactory $dataTable)
|
||||||
{
|
{
|
||||||
$table = $dataTable->createFromType(PartsDataTable::class, ['category' => $category])
|
$formRequest = clone $request;
|
||||||
|
$formRequest->setMethod('GET');
|
||||||
|
$filter = new PartFilter($this->nodesListBuilder);
|
||||||
|
|
||||||
|
//Set the category as default filter and disable to change that constraint value
|
||||||
|
$filter->getCategory()->setOperator('INCLUDING_CHILDREN')->setValue($category);
|
||||||
|
$filterForm = $this->createForm(PartFilterType::class, $filter, ['method' => 'GET']);
|
||||||
|
$this->disableFormFieldAfterCreation($filterForm->get('category')->get('value'));
|
||||||
|
$filterForm->handleRequest($formRequest);
|
||||||
|
|
||||||
|
$table = $dataTable->createFromType(PartsDataTable::class, ['filter' => $filter])
|
||||||
->handleRequest($request);
|
->handleRequest($request);
|
||||||
|
|
||||||
if ($table->isCallback()) {
|
if ($table->isCallback()) {
|
||||||
|
@ -118,6 +150,7 @@ class PartListsController extends AbstractController
|
||||||
'datatable' => $table,
|
'datatable' => $table,
|
||||||
'entity' => $category,
|
'entity' => $category,
|
||||||
'repo' => $this->entityManager->getRepository(Category::class),
|
'repo' => $this->entityManager->getRepository(Category::class),
|
||||||
|
'filterForm' => $filterForm->createView(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,12 +302,12 @@ class PartListsController extends AbstractController
|
||||||
*
|
*
|
||||||
* @return JsonResponse|Response
|
* @return JsonResponse|Response
|
||||||
*/
|
*/
|
||||||
public function showAll(Request $request, DataTableFactory $dataTable, NodesListBuilder $nodesListBuilder)
|
public function showAll(Request $request, DataTableFactory $dataTable)
|
||||||
{
|
{
|
||||||
|
|
||||||
$formRequest = clone $request;
|
$formRequest = clone $request;
|
||||||
$formRequest->setMethod('GET');
|
$formRequest->setMethod('GET');
|
||||||
$filter = new PartFilter($nodesListBuilder);
|
$filter = new PartFilter($this->nodesListBuilder);
|
||||||
$filterForm = $this->createForm(PartFilterType::class, $filter, ['method' => 'GET']);
|
$filterForm = $this->createForm(PartFilterType::class, $filter, ['method' => 'GET']);
|
||||||
$filterForm->handleRequest($formRequest);
|
$filterForm->handleRequest($formRequest);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
{% include "Parts/lists/_info_card.html.twig" with {'header_label': 'category.label'} %}
|
{% include "Parts/lists/_info_card.html.twig" with {'header_label': 'category.label'} %}
|
||||||
|
|
||||||
|
{% include "Parts/lists/_filter.html.twig" %}
|
||||||
|
|
||||||
{% include "Parts/lists/_action_bar.html.twig" with {'url_options': {'category': entity.iD}} %}
|
{% include "Parts/lists/_action_bar.html.twig" with {'url_options': {'category': entity.iD}} %}
|
||||||
|
|
||||||
{% include "Parts/lists/_parts_list.html.twig" %}
|
{% include "Parts/lists/_parts_list.html.twig" %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue