Parameter ordering fix (#3704)

* Hard-code URL fforr loadPartParameterTable function

* Improve API efficiency for including parameter data in Part query

* Fix loading of part parameter data into table
This commit is contained in:
Oliver 2022-09-21 23:31:24 +10:00 committed by GitHub
parent 33326f6eaf
commit 829a9d8311
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 7 deletions

View File

@ -1605,6 +1605,20 @@ class PartParameterList(ListCreateAPI):
queryset = PartParameter.objects.all()
serializer_class = part_serializers.PartParameterSerializer
def get_serializer(self, *args, **kwargs):
"""Return the serializer instance for this API endpoint.
If requested, extra detail fields are annotated to the queryset:
- template_detail
"""
try:
kwargs['template_detail'] = str2bool(self.request.GET.get('template_detail', True))
except AttributeError:
pass
return self.serializer_class(*args, **kwargs)
filter_backends = [
DjangoFilterBackend
]

View File

@ -247,6 +247,19 @@ class PartParameterTemplateSerializer(InvenTreeModelSerializer):
class PartParameterSerializer(InvenTreeModelSerializer):
"""JSON serializers for the PartParameter model."""
def __init__(self, *args, **kwargs):
"""Custom initialization method for the serializer.
Allows us to optionally include or exclude particular information
"""
template_detail = kwargs.pop('template_detail', False)
super().__init__(*args, **kwargs)
if not template_detail:
self.fields.pop('template_detail')
template_detail = PartParameterTemplateSerializer(source='template', many=False, read_only=True)
class Meta:

View File

@ -813,7 +813,6 @@
onPanelLoad("part-parameters", function() {
loadPartParameterTable(
'#parameter-table',
'{% url "api-part-parameter-list" %}',
{
params: {
part: {{ part.pk }},

View File

@ -803,7 +803,7 @@ function loadSimplePartTable(table, url, options={}) {
}
function loadPartParameterTable(table, url, options) {
function loadPartParameterTable(table, options) {
var params = options.params || {};
@ -819,7 +819,7 @@ function loadPartParameterTable(table, url, options) {
setupFilterList('part-parameters', $(table), filterTarget);
$(table).inventreeTable({
url: url,
url: '{% url "api-part-parameter-list" %}',
original: params,
queryParams: filters,
name: 'partparameters',
@ -1292,13 +1292,12 @@ function loadParametricPartTable(table, options={}) {
},
columns: columns,
showColumns: true,
// filterControl: true,
sidePagination: 'server',
idField: 'pk',
uniqueId: 'pk',
onLoadSuccess: function() {
onLoadSuccess: function(response) {
var data = $(table).bootstrapTable('getData');
var data = response.results;
for (var idx = 0; idx < data.length; idx++) {
var row = data[idx];
@ -1309,7 +1308,7 @@ function loadParametricPartTable(table, options={}) {
row[`parameter_${parameter.template}`] = parameter.data;
});
$(table).bootstrapTable('updateRow', pk, row);
$(table).bootstrapTable('updateByUniqueId', pk, row);
}
}
});