mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Added a filter to filter for parts which are used in a specific project
Related to issue #516
This commit is contained in:
parent
934acca934
commit
04d1e84596
4 changed files with 35 additions and 0 deletions
|
@ -39,6 +39,7 @@ use App\Entity\Parts\Manufacturer;
|
|||
use App\Entity\Parts\MeasurementUnit;
|
||||
use App\Entity\Parts\StorageLocation;
|
||||
use App\Entity\Parts\Supplier;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Services\Trees\NodesListBuilder;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
@ -90,6 +91,8 @@ class PartFilter implements FilterInterface
|
|||
public readonly ArrayCollection $parameters;
|
||||
public readonly IntConstraint $parametersCount;
|
||||
|
||||
public readonly EntityConstraint $project;
|
||||
|
||||
public function __construct(NodesListBuilder $nodesListBuilder)
|
||||
{
|
||||
$this->name = new TextConstraint('part.name');
|
||||
|
@ -140,6 +143,8 @@ class PartFilter implements FilterInterface
|
|||
|
||||
$this->parameters = new ArrayCollection();
|
||||
$this->parametersCount = new IntConstraint('COUNT(_parameters)');
|
||||
|
||||
$this->project = new EntityConstraint($nodesListBuilder, Project::class, '_projectBomEntries.project');
|
||||
}
|
||||
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
|
|
|
@ -383,6 +383,9 @@ final class PartsDataTable implements DataTableTypeInterface
|
|||
if (str_contains($dql, '_parameters')) {
|
||||
$builder->leftJoin('part.parameters', '_parameters');
|
||||
}
|
||||
if (str_contains($dql, '_projectBomEntries')) {
|
||||
$builder->leftJoin('part.project_bom_entries', '_projectBomEntries');
|
||||
}
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ use App\Entity\Parts\Manufacturer;
|
|||
use App\Entity\Parts\MeasurementUnit;
|
||||
use App\Entity\Parts\StorageLocation;
|
||||
use App\Entity\Parts\Supplier;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Form\Filters\Constraints\BooleanConstraintType;
|
||||
use App\Form\Filters\Constraints\ChoiceConstraintType;
|
||||
use App\Form\Filters\Constraints\DateTimeConstraintType;
|
||||
|
@ -41,6 +42,7 @@ use App\Form\Filters\Constraints\TagsConstraintType;
|
|||
use App\Form\Filters\Constraints\TextConstraintType;
|
||||
use App\Form\Filters\Constraints\UserEntityConstraintType;
|
||||
use Svg\Tag\Text;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
|
@ -53,6 +55,10 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
|
||||
class PartFilterType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly Security $security)
|
||||
{
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
|
@ -271,6 +277,17 @@ class PartFilterType extends AbstractType
|
|||
'min' => 0,
|
||||
]);
|
||||
|
||||
/**************************************************************************
|
||||
* Project tab
|
||||
**************************************************************************/
|
||||
if ($this->security->isGranted('read', Project::class)) {
|
||||
$builder->add('project', StructuralEntityConstraintType::class, [
|
||||
'label' => 'project.label',
|
||||
'entity_class' => Project::class
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$builder->add('submit', SubmitType::class, [
|
||||
'label' => 'filter.submit',
|
||||
]);
|
||||
|
|
|
@ -26,6 +26,11 @@
|
|||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link" id="filter-parameters-tab" data-bs-toggle="tab" data-bs-target="#filter-parameters"><i class="fas fa-atlas fa-fw"></i> {% trans %}part.edit.tab.specifications{% endtrans %}</button>
|
||||
</li>
|
||||
{% if filterForm.project is defined %}
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link" id="filter-projects-tab" data-bs-toggle="tab" data-bs-target="#filter-projects"><i class="fas fa-archive fa-fw"></i> {% trans %}project.labelp{% endtrans %}</button>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
{{ form_start(filterForm, {"attr": {"data-controller": "helpers--form-cleanup", "data-action": "helpers--form-cleanup#submit"}}) }}
|
||||
|
@ -113,6 +118,11 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{% if filterForm.project is defined %}
|
||||
<div class="tab-pane pt-3" id="filter-projects" role="tabpanel" aria-labelledby="filter-projects-tab" tabindex="0">
|
||||
{{ form_row(filterForm.project) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue