diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index c66e4c2696..1b672d4c68 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -149,6 +149,12 @@ class PartTestTemplateList(generics.ListCreateAPIView): except (ValueError, Part.DoesNotExist): pass + # Filter by 'required' status + required = params.get('required', None) + + if required is not None: + queryset = queryset.filter(required=required) + return queryset permission_classes = [permissions.IsAuthenticated] diff --git a/InvenTree/part/templates/part/part_tests.html b/InvenTree/part/templates/part/part_tests.html index bb0dbb7683..0d6fb56668 100644 --- a/InvenTree/part/templates/part/part_tests.html +++ b/InvenTree/part/templates/part/part_tests.html @@ -26,4 +26,14 @@ {% block js_ready %} {{ block.super }} +loadPartTestTemplateTable( + $("#test-template-table"), + { + part: {{ part.pk }}, + params: { + part: {{ part.pk }}, + } + } +); + {% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/js/part.html b/InvenTree/templates/js/part.html index 57e7fa5798..528fc9aa93 100644 --- a/InvenTree/templates/js/part.html +++ b/InvenTree/templates/js/part.html @@ -284,4 +284,85 @@ function loadPartTable(table, url, options={}) { location.href = '/part/export/?parts=' + parts; }); -} \ No newline at end of file +} + + +function loadPartTestTemplateTable(table, options) { + /* + * Load PartTestTemplate table. + */ + + var params = options.params || {}; + + var part = options.part || null; + + var filterListElement = options.filterList || '#filter-list-parttests'; + + var filters = loadTableFilters("parttests"); + + var original = {}; + + for (var key in params) { + original[key] = params[key]; + } + + setupFilterList("parttests", table, filterListElement); + + // Override the default values, or add new ones + for (var key in params) { + filters[key] = params[key]; + } + + table.inventreeTable({ + method: 'get', + formatNoMatches: function() { + return '{% trans "No test templates matching query" %}'; + }, + url: "{% url 'api-part-test-template-list' %}", + queryParams: filters, + original: original, + columns: [ + { + field: 'pk', + title: 'ID', + visible: false, + }, + { + field: 'test_name', + title: "{% trans "Test Name" %}", + sortable: true, + }, + { + field: 'required', + title: "{% trans 'Required' %}", + sortable: true, + formatter: function(value) { + if (value) { + return `{% trans "YES" %}`; + } else { + return `{% trans "NO" %}`; + } + } + }, + { + field: 'buttons', + formatter: function(value, row) { + var pk = row.pk; + + if (row.part == part) { + var html = `
`; + + html += makeIconButton('fa-edit icon-blue', 'button-test-edit', pk, '{% trans "Edit test result" %}'); + html += makeIconButton('fa-trash-alt icon-red', 'button-test-delete', pk, '{% trans "Delete test result" %}'); + + html += `
`; + + return html; + } else { + return '{% trans "This test is defined for a parent part" %}'; + } + } + } + ] + }); +} diff --git a/InvenTree/templates/js/table_filters.html b/InvenTree/templates/js/table_filters.html index 955703a7c9..84b517e8e7 100644 --- a/InvenTree/templates/js/table_filters.html +++ b/InvenTree/templates/js/table_filters.html @@ -44,7 +44,17 @@ function getAvailableTableFilters(tableKey) { type: 'bool', title: "{% trans 'Test result' %}", }, - } + }; + } + + // Filters for the 'part test template' table + if (tableKey == 'parttests') { + return { + required: { + type: 'bool', + title: "{% trans "Required" %}", + } + }; } // Filters for the "Build" table