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\DataTables\PartsDataTable;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
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;
@ -39,7 +41,7 @@ use Symfony\Component\Routing\Annotation\Route;
class PartListsController extends AbstractController class PartListsController extends AbstractController
{ {
/** /**
* @Route("/category/{id}/parts") * @Route("/category/{id}/parts", name="part_list_category")
* *
* @param $id int The id of the 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") * @Route("/parts/by_tag/{tag}", name="part_list_tags")
* @param string $tag * @param string $tag

View file

@ -83,7 +83,7 @@ class TreeController extends AbstractController
if ($footprint !== null) { if ($footprint !== null) {
$tree[] = $builder->elementToTreeNode($footprint); $tree[] = $builder->elementToTreeNode($footprint);
} else { } else {
$tree = $builder->typeToTree(Footprint::class, null); $tree = $builder->typeToTree(Footprint::class);
} }
@ -115,7 +115,7 @@ class TreeController extends AbstractController
if ($manufacturer !== null) { if ($manufacturer !== null) {
$tree[] = $builder->elementToTreeNode($manufacturer); $tree[] = $builder->elementToTreeNode($manufacturer);
} else { } 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\EntityColumn;
use App\DataTables\Column\LocaleDateTimeColumn; use App\DataTables\Column\LocaleDateTimeColumn;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
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;
@ -75,8 +77,9 @@ class PartsDataTable implements DataTableTypeInterface
protected function buildCriteria(QueryBuilder $builder, array $options) protected function buildCriteria(QueryBuilder $builder, array $options)
{ {
if (isset($options['category'])) {
$em = $builder->getEntityManager(); $em = $builder->getEntityManager();
if (isset($options['category'])) {
$category = $options['category']; $category = $options['category'];
$repo = $em->getRepository(Category::class); $repo = $em->getRepository(Category::class);
$list = $repo->toNodesList($category); $list = $repo->toNodesList($category);
@ -85,6 +88,24 @@ class PartsDataTable implements DataTableTypeInterface
$builder->andWhere('part.category IN (:cid)')->setParameter('cid', $list); $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'])) { if (isset($options['tag'])) {
$builder->andWhere('part.tags LIKE :tag')->setParameter('tag', '%' . $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 public function listPartsURL($entity) : string
{ {
if ($entity instanceof Category) { 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!'); throw new EntityNotSupported('The given entity is not supported yet!');
} }

View file

@ -1,7 +1,7 @@
<div class="card mb-3"> <div class="card mb-3">
<div class="card-header"> <div class="card-header">
<a class="card-link" data-toggle="collapse" href="#entityInfo"> <a class="card-link" data-toggle="collapse" href="#entityInfo">
{% trans %}category.label{% endtrans %}: <b>{{ entity.fullPath }}</b> {{ header_label | trans }}: <b>{{ entity.fullPath }}</b>
</a> </a>
</div> </div>
<div id="entityInfo" class="collapse"> <div id="entityInfo" class="collapse">

View file

@ -0,0 +1,12 @@
<div id="part_list" class="table-responsive" data-datatable data-settings='{{ datatable_settings(datatable) }}'>
<div class="card-body">
<div class="card">
<div class="card-body">
<h4>{% trans %}part_list.loading.caption{% endtrans %}</h4>
<h6>{% trans %}part_list.loading.message{% endtrans %}</h6>
</div>
</div>
</div>
</div>

View file

@ -1,18 +1,13 @@
{% extends "base.html.twig" %} {% extends "base.html.twig" %}
{% block title %}
{% trans %}parts_list.category.title{% endtrans %} {{ entity.name }}
{% endblock %}
{% block content %} {% block content %}
{% include "Parts/lists/_info_card.html.twig" %} {% include "Parts/lists/_info_card.html.twig" with {'header_label': 'category.label'} %}
<div id="part_list" class="table-responsive" data-datatable data-settings='{{ datatable_settings(datatable) }}'> {% include "Parts/lists/_parts_list.html.twig" %}
<div class="card-body">
<div class="card">
<div class="card-body">
<h4>{% trans %}part_list.loading.caption{% endtrans %}</h4>
<h6>{% trans %}part_list.loading.message{% endtrans %}</h6>
</div>
</div>
</div>
</div>
{% endblock %} {% endblock %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -1,29 +0,0 @@
{% extends "base.html.twig" %}
{% block content %}
{#
<div class="card border-primary">
<div class="card-header bg-primary text-white">
<h6>Bauteile</h6>
</div>
</div>
</div>
#}
{# Set the title for the table here. It will be inserted into the table later.#}
<div style="display:none;" id="part-card-header-src">Test</div>
<div id="part_list" class="table-responsive" data-datatable data-settings='{{ datatable_settings(datatable) }}'>
<div class="card-body">
<div class="card">
<div class="card-body">
<h4>{% trans %}part_list.loading.caption{% endtrans %}</h4>
<h6>{% trans %}part_list.loading.message{% endtrans %}</h6>
</div>
</div>
</div>
</div>
{% endblock %}