Add table displaying part test templates

This commit is contained in:
Oliver Walters 2020-05-17 16:07:55 +10:00
parent 66f2c01d5d
commit e9ed50fc4b
4 changed files with 109 additions and 2 deletions

View File

@ -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]

View File

@ -26,4 +26,14 @@
{% block js_ready %}
{{ block.super }}
loadPartTestTemplateTable(
$("#test-template-table"),
{
part: {{ part.pk }},
params: {
part: {{ part.pk }},
}
}
);
{% endblock %}

View File

@ -284,4 +284,85 @@ 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" %}';
}
}
}
]
});
}

View File

@ -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