Add serializer / table display

This commit is contained in:
Oliver Walters 2020-05-18 19:15:40 +10:00
parent fc6cad475a
commit 2f6d03388d
2 changed files with 34 additions and 6 deletions

View File

@ -62,14 +62,20 @@ class PartTestTemplateSerializer(InvenTreeModelSerializer):
Serializer for the PartTestTemplate class Serializer for the PartTestTemplate class
""" """
key = serializers.CharField(read_only=True)
class Meta: class Meta:
model = PartTestTemplate model = PartTestTemplate
fields = [ fields = [
'pk', 'pk',
'key',
'part', 'part',
'test_name', 'test_name',
'required' 'description',
'required',
'requires_value',
'requires_attachment',
] ]

View File

@ -286,6 +286,14 @@ function loadPartTable(table, url, options={}) {
}); });
} }
function yesNoLabel(value) {
if (value) {
return `<span class='label label-green'>{% trans "YES" %}</span>`;
} else {
return `<span class='label label-yellow'>{% trans "NO" %}</span>`;
}
}
function loadPartTestTemplateTable(table, options) { function loadPartTestTemplateTable(table, options) {
/* /*
@ -332,16 +340,30 @@ function loadPartTestTemplateTable(table, options) {
title: "{% trans "Test Name" %}", title: "{% trans "Test Name" %}",
sortable: true, sortable: true,
}, },
{
field: 'description',
title: "{% trans "Description" %}",
},
{ {
field: 'required', field: 'required',
title: "{% trans 'Required' %}", title: "{% trans 'Required' %}",
sortable: true, sortable: true,
formatter: function(value) { formatter: function(value) {
if (value) { return yesNoLabel(value);
return `<span class='label label-green'>{% trans "YES" %}</span>`; }
} else { },
return `<span class='label label-yellow'>{% trans "NO" %}</span>`; {
} field: 'requires_value',
title: "{% trans "Requires Value" %}",
formatter: function(value) {
return yesNoLabel(value);
}
},
{
field: 'requires_attachment',
title: "{% trans "Requires Attachment" %}",
formatter: function(value) {
return yesNoLabel(value);
} }
}, },
{ {