mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add table displaying part test templates
This commit is contained in:
parent
66f2c01d5d
commit
e9ed50fc4b
@ -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]
|
||||
|
@ -26,4 +26,14 @@
|
||||
{% block js_ready %}
|
||||
{{ block.super }}
|
||||
|
||||
loadPartTestTemplateTable(
|
||||
$("#test-template-table"),
|
||||
{
|
||||
part: {{ part.pk }},
|
||||
params: {
|
||||
part: {{ part.pk }},
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
{% endblock %}
|
@ -285,3 +285,84 @@ function loadPartTable(table, url, options={}) {
|
||||
location.href = '/part/export/?parts=' + parts;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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 `<span class='label label-green'>{% trans "YES" %}</span>`;
|
||||
} else {
|
||||
return `<span class='label label-yellow'>{% trans "NO" %}</span>`;
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'buttons',
|
||||
formatter: function(value, row) {
|
||||
var pk = row.pk;
|
||||
|
||||
if (row.part == part) {
|
||||
var html = `<div class='btn-group float-right' role='group'>`;
|
||||
|
||||
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 += `</div>`;
|
||||
|
||||
return html;
|
||||
} else {
|
||||
return '{% trans "This test is defined for a parent part" %}';
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user