Allow to show parts for manufacturers and footprints.

This commit is contained in:
Jan Böhmer 2019-09-08 13:59:35 +02:00
parent 8dc9c7b9ae
commit c3fd325645
10 changed files with 126 additions and 46 deletions

View file

@ -31,6 +31,8 @@ namespace App\Controller;
use App\DataTables\PartsDataTable;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use Omines\DataTablesBundle\DataTableFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@ -39,7 +41,7 @@ use Symfony\Component\Routing\Annotation\Route;
class PartListsController extends AbstractController
{
/**
* @Route("/category/{id}/parts")
* @Route("/category/{id}/parts", name="part_list_category")
*
* @param $id int The id of the category
*
@ -60,6 +62,50 @@ class PartListsController extends AbstractController
]);
}
/**
* @Route("/footprint/{id}/parts", name="part_list_footprint")
*
* @param $id int The id of the category
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/
public function showFootprint(Footprint $footprint, Request $request, DataTableFactory $dataTable)
{
$table = $dataTable->createFromType(PartsDataTable::class, ['footprint' => $footprint])
->handleRequest($request);
if ($table->isCallback()) {
return $table->getResponse();
}
return $this->render('Parts/lists/footprint_list.html.twig', [
'datatable' => $table,
'entity' => $footprint
]);
}
/**
* @Route("/manufacturer/{id}/parts", name="part_list_manufacturer")
*
* @param $id int The id of the category
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/
public function showManufacturer(Manufacturer $manufacturer, Request $request, DataTableFactory $dataTable)
{
$table = $dataTable->createFromType(PartsDataTable::class, ['manufacturer' => $manufacturer])
->handleRequest($request);
if ($table->isCallback()) {
return $table->getResponse();
}
return $this->render('Parts/lists/manufacturer_list.html.twig', [
'datatable' => $table,
'entity' => $manufacturer
]);
}
/**
* @Route("/parts/by_tag/{tag}", name="part_list_tags")
* @param string $tag

View file

@ -83,7 +83,7 @@ class TreeController extends AbstractController
if ($footprint !== null) {
$tree[] = $builder->elementToTreeNode($footprint);
} else {
$tree = $builder->typeToTree(Footprint::class, null);
$tree = $builder->typeToTree(Footprint::class);
}
@ -115,7 +115,7 @@ class TreeController extends AbstractController
if ($manufacturer !== null) {
$tree[] = $builder->elementToTreeNode($manufacturer);
} else {
$tree = $builder->typeToTree(Manufacturer::class, null);
$tree = $builder->typeToTree(Manufacturer::class);
}

View file

@ -32,6 +32,8 @@ namespace App\DataTables;
use App\DataTables\Column\EntityColumn;
use App\DataTables\Column\LocaleDateTimeColumn;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Services\EntityURLGenerator;
use Doctrine\ORM\QueryBuilder;
@ -75,8 +77,9 @@ class PartsDataTable implements DataTableTypeInterface
protected function buildCriteria(QueryBuilder $builder, array $options)
{
$em = $builder->getEntityManager();
if (isset($options['category'])) {
$em = $builder->getEntityManager();
$category = $options['category'];
$repo = $em->getRepository(Category::class);
$list = $repo->toNodesList($category);
@ -85,6 +88,24 @@ class PartsDataTable implements DataTableTypeInterface
$builder->andWhere('part.category IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['footprint'])) {
$category = $options['footprint'];
$repo = $em->getRepository(Footprint::class);
$list = $repo->toNodesList($category);
$list[] = $category;
$builder->andWhere('part.footprint IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['manufacturer'])) {
$category = $options['manufacturer'];
$repo = $em->getRepository(Manufacturer::class);
$list = $repo->toNodesList($category);
$list[] = $category;
$builder->andWhere('part.manufacturer IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['tag'])) {
$builder->andWhere('part.tags LIKE :tag')->setParameter('tag', '%' . $options['tag'] . '%');
}

View file

@ -277,8 +277,17 @@ class EntityURLGenerator
public function listPartsURL($entity) : string
{
if ($entity instanceof Category) {
return $this->urlGenerator->generate('app_partlists_showcategory', ['id' => $entity->getID()]);
return $this->urlGenerator->generate('part_list_category', ['id' => $entity->getID()]);
}
if ($entity instanceof Footprint) {
return $this->urlGenerator->generate('part_list_footprint', ['id' => $entity->getID()]);
}
if ($entity instanceof Manufacturer) {
return $this->urlGenerator->generate('part_list_manufacturer', ['id' => $entity->getID()]);
}
throw new EntityNotSupported('The given entity is not supported yet!');
}