mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-20 17:19:34 +00:00
added button to show existing part with same manufacturer and mpn in provider list
This commit is contained in:
parent
e9efbff912
commit
ab68f4b37f
2 changed files with 69 additions and 21 deletions
|
|
@ -23,10 +23,13 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Parts\Manufacturer;
|
||||||
use App\Entity\Parts\Part;
|
use App\Entity\Parts\Part;
|
||||||
use App\Form\InfoProviderSystem\PartSearchType;
|
use App\Form\InfoProviderSystem\PartSearchType;
|
||||||
use App\Services\InfoProviderSystem\PartInfoRetriever;
|
use App\Services\InfoProviderSystem\PartInfoRetriever;
|
||||||
use App\Services\InfoProviderSystem\ProviderRegistry;
|
use App\Services\InfoProviderSystem\ProviderRegistry;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
|
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
|
@ -42,7 +45,8 @@ class InfoProviderController extends AbstractController
|
||||||
{
|
{
|
||||||
|
|
||||||
public function __construct(private readonly ProviderRegistry $providerRegistry,
|
public function __construct(private readonly ProviderRegistry $providerRegistry,
|
||||||
private readonly PartInfoRetriever $infoRetriever)
|
private readonly PartInfoRetriever $infoRetriever,
|
||||||
|
private readonly EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -58,6 +62,34 @@ class InfoProviderController extends AbstractController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function matchResultsToKnownParts(array $partsList): array
|
||||||
|
{
|
||||||
|
$manufacturerQb = $this->em->getRepository(Manufacturer::class)->createQueryBuilder("manufacturer");
|
||||||
|
$manufacturerQb->where($manufacturerQb->expr()->like("LOWER(manufacturer.name)", "LOWER(:manufacturer_name)"));
|
||||||
|
|
||||||
|
|
||||||
|
$mpnQb = $this->em->getRepository(Part::class)->createQueryBuilder("part");
|
||||||
|
$mpnQb->where($mpnQb->expr()->like("LOWER(part.manufacturer_product_number)", "LOWER(:mpn)"));
|
||||||
|
$mpnQb->andWhere($mpnQb->expr()->eq("part.manufacturer", ":manufacturer"));
|
||||||
|
|
||||||
|
foreach ($partsList as $index => $part) {
|
||||||
|
$manufacturerQb->setParameter("manufacturer_name", $part["dto"]->manufacturer);
|
||||||
|
$manufacturers = $manufacturerQb->getQuery()->getResult();
|
||||||
|
if(!$manufacturers) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mpnQb->setParameter("manufacturer", $manufacturers);
|
||||||
|
$mpnQb->setParameter("mpn", $part["dto"]->mpn);
|
||||||
|
$localParts = $mpnQb->getQuery()->getResult();
|
||||||
|
if(!$localParts) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$partsList[$index]["localPart"] = $localParts[0];
|
||||||
|
}
|
||||||
|
return $partsList;
|
||||||
|
}
|
||||||
|
|
||||||
#[Route('/search', name: 'info_providers_search')]
|
#[Route('/search', name: 'info_providers_search')]
|
||||||
#[Route('/update/{target}', name: 'info_providers_update_part_search')]
|
#[Route('/update/{target}', name: 'info_providers_update_part_search')]
|
||||||
public function search(Request $request, #[MapEntity(id: 'target')] ?Part $update_target, LoggerInterface $exceptionLogger): Response
|
public function search(Request $request, #[MapEntity(id: 'target')] ?Part $update_target, LoggerInterface $exceptionLogger): Response
|
||||||
|
|
@ -87,6 +119,10 @@ class InfoProviderController extends AbstractController
|
||||||
//Log the exception
|
//Log the exception
|
||||||
$exceptionLogger->error('Error during info provider search: ' . $e->getMessage(), ['exception' => $e]);
|
$exceptionLogger->error('Error during info provider search: ' . $e->getMessage(), ['exception' => $e]);
|
||||||
}
|
}
|
||||||
|
$results = array_map(function ($result) {return ["dto" => $result,"localPart" => null];}, $results);
|
||||||
|
if(!$update_target) {
|
||||||
|
$results = $this->matchResultsToKnownParts($results);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('info_providers/search/part_search.html.twig', [
|
return $this->render('info_providers/search/part_search.html.twig', [
|
||||||
|
|
|
||||||
|
|
@ -52,59 +52,71 @@
|
||||||
<th>{% trans %}part.table.manufacturingStatus{% endtrans %}</th>
|
<th>{% trans %}part.table.manufacturingStatus{% endtrans %}</th>
|
||||||
<th>{% trans %}info_providers.table.provider.label{% endtrans %}</th>
|
<th>{% trans %}info_providers.table.provider.label{% endtrans %}</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for result in results %}
|
{% for result in results %}
|
||||||
|
{% set dto = result["dto"] %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<img src="{{ result.preview_image_url }}" data-thumbnail="{{ result.preview_image_url }}"
|
<img src="{{ dto.preview_image_url }}" data-thumbnail="{{ dto.preview_image_url }}"
|
||||||
class="hoverpic" style="max-width: 45px;" {{ stimulus_controller('elements/hoverpic') }}>
|
class="hoverpic" style="max-width: 45px;" {{ stimulus_controller('elements/hoverpic') }}>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if result.provider_url is not null %}
|
{% if dto.provider_url is not null %}
|
||||||
<a href="{{ result.provider_url }}" target="_blank" rel="noopener">{{ result.name }}</a>
|
<a href="{{ dto.provider_url }}" target="_blank" rel="noopener">{{ dto.name }}</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ result.name }}
|
{{ dto.name }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if result.mpn is not null %}
|
{% if dto.mpn is not null %}
|
||||||
<br>
|
<br>
|
||||||
<small class="text-muted" title="{% trans %}part.table.mpn{% endtrans %}">{{ result.mpn }}</small>
|
<small class="text-muted" title="{% trans %}part.table.mpn{% endtrans %}">{{ dto.mpn }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ result.description }}
|
{{ dto.description }}
|
||||||
{% if result.category is not null %}
|
{% if dto.category is not null %}
|
||||||
<br>
|
<br>
|
||||||
<small class="text-muted">{{ result.category }}</small>
|
<small class="text-muted">{{ dto.category }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ result.manufacturer ?? '' }}
|
{{ dto.manufacturer ?? '' }}
|
||||||
{% if result.footprint is not null %}
|
{% if dto.footprint is not null %}
|
||||||
<br>
|
<br>
|
||||||
<small class="text-muted">{{ result.footprint }}</small>
|
<small class="text-muted">{{ dto.footprint }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ helper.m_status_to_badge(result.manufacturing_status) }}</td>
|
<td>{{ helper.m_status_to_badge(dto.manufacturing_status) }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% if result.provider_url %}
|
{% if dto.provider_url %}
|
||||||
<a href="{{ result.provider_url }}" target="_blank" rel="noopener">
|
<a href="{{ dto.provider_url }}" target="_blank" rel="noopener">
|
||||||
{{ info_provider_label(result.provider_key)|default(result.provider_key) }}
|
{{ info_provider_label(dto.provider_key)|default(dto.provider_key) }}
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ info_provider_label(result.provider_key)|default(result.provider_key) }}
|
{{ info_provider_label(dto.provider_key)|default(dto.provider_key) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br>
|
<br>
|
||||||
<small class="text-muted">{{ result.provider_id }}</small>
|
<small class="text-muted">{{ dto.provider_id }}</small>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
{% if result["localPart"] is not null %}
|
||||||
|
<a class="btn btn-primary" href="{{ path('part_edit', {'id': result['localPart'].id}) }}"
|
||||||
|
target="_blank" title="Edit Existing Part"> {# TODO: Needs translation #}
|
||||||
|
<i class="fa-solid fa-pencil"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
{% if update_target %} {# We update an existing part #}
|
{% if update_target %} {# We update an existing part #}
|
||||||
{% set href = path('info_providers_update_part',
|
{% set href = path('info_providers_update_part',
|
||||||
{'providerKey': result.provider_key, 'providerId': result.provider_id, 'id': update_target.iD}) %}
|
{'providerKey': dto.provider_key, 'providerId': dto.provider_id, 'id': update_target.iD}) %}
|
||||||
{% else %} {# Create a fresh part #}
|
{% else %} {# Create a fresh part #}
|
||||||
{% set href = path('info_providers_create_part',
|
{% set href = path('info_providers_create_part',
|
||||||
{'providerKey': result.provider_key, 'providerId': result.provider_id}) %}
|
{'providerKey': dto.provider_key, 'providerId': dto.provider_id}) %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<a class="btn btn-primary" href="{{ href }}"
|
<a class="btn btn-primary" href="{{ href }}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue