Simplify display of possible conflicting parts

- Round to single digit
- Only show 5 closest matches
This commit is contained in:
Oliver Walters 2020-10-28 23:48:35 +11:00
parent 091a9d9803
commit ed8be5225d
4 changed files with 18 additions and 10 deletions

View File

@ -493,6 +493,9 @@ function openModal(options) {
var modal = options.modal || '#modal-form'; var modal = options.modal || '#modal-form';
// Ensure that the 'warning' div is hidden
$(modal).find('#form-validation-warning').css('display', 'none');
$(modal).on('shown.bs.modal', function() { $(modal).on('shown.bs.modal', function() {
$(modal + ' .modal-form-content').scrollTop(0); $(modal + ' .modal-form-content').scrollTop(0);
if (options.focus) { if (options.focus) {

View File

@ -245,7 +245,7 @@ def match_part_names(match, threshold=80, reverse=True, compare_length=False):
if ratio >= threshold: if ratio >= threshold:
matches.append({ matches.append({
'part': part, 'part': part,
'ratio': ratio 'ratio': round(ratio, 1)
}) })
matches = sorted(matches, key=lambda item: item['ratio'], reverse=reverse) matches = sorted(matches, key=lambda item: item['ratio'], reverse=reverse)

View File

@ -1,19 +1,23 @@
{% extends "modal_form.html" %} {% extends "modal_form.html" %}
{% load inventree_extras %}
{% load i18n %}
{% block pre_form_content %} {% block pre_form_content %}
{{ block.super }} {{ block.super }}
{% if matches %} {% if matches %}
<b>Possible Matching Parts</b> <div class='alert alert-block alert-warning'>
<p>The new part may be a duplicate of these existing parts:</p> <b>{% trans "Possible Matching Parts" %}</b>
<ul class='list-group'> <p>{% trans "The new part may be a duplicate of these existing parts" %}:</p>
{% for match in matches %} <ul class='list-group'>
<li class='list-group-item list-group-item-condensed'> {% for match in matches %}
{{ match.part.full_name }} - <i>{{ match.part.description }}</i> ({{ match.ratio }}%) <li class='list-group-item list-group-item-condensed'>
</li> {{ match.part.full_name }} - <i>{{ match.part.description }}</i> ({% decimal match.ratio %}% {% trans "match" %})
{% endfor %} </li>
{% endfor %}
</ul> </ul>
</div>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -436,7 +436,8 @@ class PartDuplicate(AjaxCreateView):
matches = match_part_names(name) matches = match_part_names(name)
if len(matches) > 0: if len(matches) > 0:
context['matches'] = matches # Display the first five closest matches
context['matches'] = matches[:5]
# Enforce display of the checkbox # Enforce display of the checkbox
form.fields['confirm_creation'].widget = CheckboxInput() form.fields['confirm_creation'].widget = CheckboxInput()