Add an option to configure number of parts displayed in search preview box

This commit is contained in:
Oliver 2021-07-21 15:05:14 +10:00
parent 15b3055e53
commit 2ffae368f1
5 changed files with 25 additions and 3 deletions

View File

@ -111,6 +111,7 @@ dynamic_javascript_urls = [
url(r'^company.js', DynamicJsView.as_view(template_name='js/company.js'), name='company.js'),
url(r'^filters.js', DynamicJsView.as_view(template_name='js/filters.js'), name='filters.js'),
url(r'^forms.js', DynamicJsView.as_view(template_name='js/forms.js'), name='forms.js'),
url(r'^inventree.js', DynamicJsView.as_view(template_name='js/inventree.js'), name='inventree.js'),
url(r'^label.js', DynamicJsView.as_view(template_name='js/label.js'), name='label.js'),
url(r'^model_renderers.js', DynamicJsView.as_view(template_name='js/model_renderers.js'), name='model_renderers.js'),
url(r'^modals.js', DynamicJsView.as_view(template_name='js/modals.js'), name='modals.js'),

View File

@ -277,6 +277,13 @@ class InvenTreeSetting(models.Model):
'validator': bool,
},
'SEARCH_PREVIEW_RESULTS': {
'name': _('Search Preview Results'),
'description': _('Number of results to show in search preview window'),
'default': 10,
'validator': [int, MinValueValidator(1)]
},
'STOCK_ENABLE_EXPIRY': {
'name': _('Stock Expiry'),
'description': _('Enable stock expiry functionality'),

View File

@ -31,4 +31,11 @@
</tbody>
</table>
<h4>{% trans "Search Settings" %}</h4>
<table class='table table-striped table-condensed'>
<tbody>
{% include "InvenTree/settings/setting.html" with key="SEARCH_PREVIEW_RESULTS" icon="fa-search" %}
</tbody>
</table>
{% endblock %}

View File

@ -142,11 +142,11 @@
<script type='text/javascript' src="{% static 'script/randomColor.min.js' %}"></script>
<!-- general InvenTree -->
<script type='text/javascript' src="{% static 'script/inventree/inventree.js' %}"></script>
<script type='text/javascript' src="{% static 'script/inventree/notification.js' %}"></script>
<script type='text/javascript' src="{% static 'script/inventree/sidenav.js' %}"></script>
<!-- translated -->
<script type='text/javascript' src="{% i18n_static 'inventree.js' %}"></script>
<script type='text/javascript' src="{% i18n_static 'api.js' %}"></script>
<script type='text/javascript' src="{% i18n_static 'attachment.js' %}"></script>
<script type='text/javascript' src="{% i18n_static 'barcode.js' %}"></script>

View File

@ -1,3 +1,5 @@
{% load inventree_extras %}
function attachClipboard(selector, containerselector, textElement) {
// set container
if (containerselector){
@ -13,7 +15,8 @@ function attachClipboard(selector, containerselector, textElement) {
}
} else {
text = function(trigger) {
var content = trigger.parentElement.parentElement.textContent;return content.trim();
var content = trigger.parentElement.parentElement.textContent;
return content.trim();
}
}
@ -86,7 +89,11 @@ function inventreeDocReady() {
source: function (request, response) {
$.ajax({
url: '/api/part/',
data: { search: request.term, limit: 4, offset: 0 },
data: {
search: request.term,
limit: {% settings_value 'SEARCH_PREVIEW_RESULTS' %},
offset: 0
},
success: function (data) {
var transformed = $.map(data.results, function (el) {
return {