diff --git a/src/Controller/PartListsController.php b/src/Controller/PartListsController.php index 72280736..77a01a48 100644 --- a/src/Controller/PartListsController.php +++ b/src/Controller/PartListsController.php @@ -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 diff --git a/src/Controller/TreeController.php b/src/Controller/TreeController.php index 4f80ba0e..c5605cf5 100644 --- a/src/Controller/TreeController.php +++ b/src/Controller/TreeController.php @@ -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); } diff --git a/src/DataTables/PartsDataTable.php b/src/DataTables/PartsDataTable.php index 45e877c1..11ef84c5 100644 --- a/src/DataTables/PartsDataTable.php +++ b/src/DataTables/PartsDataTable.php @@ -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'] . '%'); } diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index a00a92e9..634a1b18 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -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!'); } diff --git a/templates/Parts/lists/_info_card.html.twig b/templates/Parts/lists/_info_card.html.twig index 90d11b4f..fcf850ce 100644 --- a/templates/Parts/lists/_info_card.html.twig +++ b/templates/Parts/lists/_info_card.html.twig @@ -1,7 +1,7 @@
- {% trans %}category.label{% endtrans %}: {{ entity.fullPath }} + {{ header_label | trans }}: {{ entity.fullPath }}
diff --git a/templates/Parts/lists/_parts_list.html.twig b/templates/Parts/lists/_parts_list.html.twig new file mode 100644 index 00000000..c1de4fc8 --- /dev/null +++ b/templates/Parts/lists/_parts_list.html.twig @@ -0,0 +1,12 @@ + +
+
+
+
+

{% trans %}part_list.loading.caption{% endtrans %}

+
{% trans %}part_list.loading.message{% endtrans %}
+
+
+
+
+ diff --git a/templates/Parts/lists/category_list.html.twig b/templates/Parts/lists/category_list.html.twig index 71df1921..e49700c5 100644 --- a/templates/Parts/lists/category_list.html.twig +++ b/templates/Parts/lists/category_list.html.twig @@ -1,18 +1,13 @@ {% extends "base.html.twig" %} +{% block title %} + {% trans %}parts_list.category.title{% endtrans %} {{ entity.name }} +{% endblock %} + {% block content %} - {% include "Parts/lists/_info_card.html.twig" %} + {% include "Parts/lists/_info_card.html.twig" with {'header_label': 'category.label'} %} -
-
-
-
-

{% trans %}part_list.loading.caption{% endtrans %}

-
{% trans %}part_list.loading.message{% endtrans %}
-
-
-
-
+ {% include "Parts/lists/_parts_list.html.twig" %} {% endblock %} diff --git a/templates/Parts/lists/footprint_list.html.twig b/templates/Parts/lists/footprint_list.html.twig new file mode 100644 index 00000000..b66aafed --- /dev/null +++ b/templates/Parts/lists/footprint_list.html.twig @@ -0,0 +1,13 @@ +{% extends "base.html.twig" %} + +{% block title %} + {% trans %}parts_list.footprint.title{% endtrans %} {{ entity.name }} +{% endblock %} + +{% block content %} + + {% include "Parts/lists/_info_card.html.twig" with {'header_label': 'footprint.label'} %} + + {% include "Parts/lists/_parts_list.html.twig" %} + +{% endblock %} diff --git a/templates/Parts/lists/manufacturer_list.html.twig b/templates/Parts/lists/manufacturer_list.html.twig new file mode 100644 index 00000000..de427199 --- /dev/null +++ b/templates/Parts/lists/manufacturer_list.html.twig @@ -0,0 +1,13 @@ +{% extends "base.html.twig" %} + +{% block title %} +{% trans %}parts_list.manufacturer.title{% endtrans %} {{ entity.name }} +{% endblock %} + +{% block content %} + + {% include "Parts/lists/_info_card.html.twig" with {'header_label': 'manufacturer.label'} %} + + {% include "Parts/lists/_parts_list.html.twig" %} + +{% endblock %} diff --git a/templates/parts_list.html.twig b/templates/parts_list.html.twig deleted file mode 100644 index 4fd977f6..00000000 --- a/templates/parts_list.html.twig +++ /dev/null @@ -1,29 +0,0 @@ -{% extends "base.html.twig" %} - -{% block content %} - - {# -
-
-
Bauteile
-
- -
-
- #} - - {# Set the title for the table here. It will be inserted into the table later.#} - - -
-
-
-
-

{% trans %}part_list.loading.caption{% endtrans %}

-
{% trans %}part_list.loading.message{% endtrans %}
-
-
-
-
- -{% endblock %}