mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Allow to show parts for manufacturers and footprints.
This commit is contained in:
parent
8dc9c7b9ae
commit
c3fd325645
10 changed files with 126 additions and 46 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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'] . '%');
|
||||
}
|
||||
|
|
|
@ -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!');
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<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>
|
||||
</div>
|
||||
<div id="entityInfo" class="collapse">
|
||||
|
|
12
templates/Parts/lists/_parts_list.html.twig
Normal file
12
templates/Parts/lists/_parts_list.html.twig
Normal 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>
|
||||
|
|
@ -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'} %}
|
||||
|
||||
<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>
|
||||
{% include "Parts/lists/_parts_list.html.twig" %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
13
templates/Parts/lists/footprint_list.html.twig
Normal file
13
templates/Parts/lists/footprint_list.html.twig
Normal 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 %}
|
13
templates/Parts/lists/manufacturer_list.html.twig
Normal file
13
templates/Parts/lists/manufacturer_list.html.twig
Normal 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 %}
|
|
@ -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 %}
|
Loading…
Add table
Add a link
Reference in a new issue