mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Show when parts from info provider already exist (#810)
* added button to show existing part with same manufacturer and mpn in provider list * added button to edit existing part in provider list * added docstring and comments * replaced unnecessary double quotes * Introduced a new twig variable localPart to split up the result * Highlight a row, if the part is already existing * Made buttons translatable * Improved styling of the buttons and added a badge to show a hint * Extracted database queries for part matching into its own service and optimized the query reducing the required queries by factor 2 * Allow to find existing parts via the stored providerReference This should allow the database to more quickly find entries * Allow to use part name and manufacturer alternative names for mapping * Added a button to update a local part from the info provider and moved some buttons into dropdown menu --------- Co-authored-by: jona <a@b.c> Co-authored-by: Jan Böhmer <mail@jan-boehmer.de>
This commit is contained in:
parent
e9efbff912
commit
92e4976396
4 changed files with 195 additions and 28 deletions
|
@ -56,61 +56,104 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
{% for result in results %}
|
||||
<tr>
|
||||
{% set dto = result["dto"] %}
|
||||
{# @var App\Entity\Parts\Part localPart #}
|
||||
{% set localPart = result["localPart"] %}
|
||||
|
||||
<tr {% if localPart is not null %}class="table-warning"{% endif %}>
|
||||
<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') }}>
|
||||
</td>
|
||||
<td>
|
||||
{% if result.provider_url is not null %}
|
||||
<a href="{{ result.provider_url }}" target="_blank" rel="noopener">{{ result.name }}</a>
|
||||
{% if dto.provider_url is not null %}
|
||||
<a href="{{ dto.provider_url }}" target="_blank" rel="noopener">{{ dto.name }}</a>
|
||||
{% else %}
|
||||
{{ result.name }}
|
||||
{{ dto.name }}
|
||||
{% endif %}
|
||||
|
||||
{% if result.mpn is not null %}
|
||||
{% if dto.mpn is not null %}
|
||||
<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 %}
|
||||
{% if result["localPart"] is not null %}
|
||||
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{{ result.description }}
|
||||
{% if result.category is not null %}
|
||||
{{ dto.description }}
|
||||
{% if dto.category is not null %}
|
||||
<br>
|
||||
<small class="text-muted">{{ result.category }}</small>
|
||||
<small class="text-muted">{{ dto.category }}</small>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{{ result.manufacturer ?? '' }}
|
||||
{% if result.footprint is not null %}
|
||||
{{ dto.manufacturer ?? '' }}
|
||||
{% if dto.footprint is not null %}
|
||||
<br>
|
||||
<small class="text-muted">{{ result.footprint }}</small>
|
||||
<small class="text-muted">{{ dto.footprint }}</small>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ helper.m_status_to_badge(result.manufacturing_status) }}</td>
|
||||
<td>{{ helper.m_status_to_badge(dto.manufacturing_status) }}</td>
|
||||
<td>
|
||||
{% if result.provider_url %}
|
||||
<a href="{{ result.provider_url }}" target="_blank" rel="noopener">
|
||||
{{ info_provider_label(result.provider_key)|default(result.provider_key) }}
|
||||
{% if dto.provider_url %}
|
||||
<a href="{{ dto.provider_url }}" target="_blank" rel="noopener">
|
||||
{{ info_provider_label(dto.provider_key)|default(dto.provider_key) }}
|
||||
</a>
|
||||
{% else %}
|
||||
{{ info_provider_label(result.provider_key)|default(result.provider_key) }}
|
||||
{{ info_provider_label(dto.provider_key)|default(dto.provider_key) }}
|
||||
{% endif %}
|
||||
<br>
|
||||
<small class="text-muted">{{ result.provider_id }}</small>
|
||||
<td>
|
||||
<small class="text-muted">{{ dto.provider_id }}</small>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
|
||||
{% if update_target %} {# We update an existing 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 #}
|
||||
{% set href = path('info_providers_create_part',
|
||||
{'providerKey': result.provider_key, 'providerId': result.provider_id}) %}
|
||||
{'providerKey': dto.provider_key, 'providerId': dto.provider_id}) %}
|
||||
{% endif %}
|
||||
|
||||
<a class="btn btn-primary" href="{{ href }}"
|
||||
target="_blank" title="{% trans %}part.create.btn{% endtrans %}">
|
||||
<i class="fa-solid fa-plus-square"></i>
|
||||
</a>
|
||||
{# If we have no local part, then we can just show the create button #}
|
||||
{% if localPart is null %}
|
||||
<a class="btn btn-primary" href="{{ href }}"
|
||||
target="_blank" title="{% trans %}part.create.btn{% endtrans %}">
|
||||
<i class="fa-solid fa-plus-square"></i>
|
||||
</a>
|
||||
{% else %} {# Otherwise add a button group with all three buttons #}
|
||||
<span class="badge text-bg-warning mb-1 d-block" title="{% trans %}info_providers.search.existing_part_found{% endtrans %}">
|
||||
<i class="fa-solid fa-circle-info fa-fw"></i>
|
||||
{% trans %}info_providers.search.existing_part_found.short{% endtrans %}
|
||||
</span>
|
||||
|
||||
<div class="btn-group" role="group">
|
||||
<a class="btn btn-primary" href="{{ path('app_part_show', {'id': localPart.id}) }}"
|
||||
target="_blank" title="{% trans %}info_providers.search.show_existing_part{% endtrans %}">
|
||||
<i class="fa-solid fa-search"></i>
|
||||
</a>
|
||||
<a class="btn btn-primary" href="{{ path("info_providers_update_part", {'id': localPart.id, 'providerKey': dto.provider_key, 'providerId': dto.provider_id}) }}"
|
||||
target="_blank" title="{% trans %}info_providers.search.update_existing_part{% endtrans %}">
|
||||
<i class="fa-solid fa-arrows-rotate"></i>
|
||||
</a>
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"></button>
|
||||
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" href="{{ path('part_edit', {'id': localPart.id}) }}" target="_blank">
|
||||
<i class="fa-solid fa-pencil fa-fw"></i> {% trans %}info_providers.search.edit_existing_part{% endtrans %}
|
||||
</a></li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ href }}" target="_blank">
|
||||
<i class="fa-solid fa-plus-square fa-fw"></i> {% trans %}part.create.btn{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue