mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Hide part toolbar, nicer part representation, improved parameters prefetching
This commit is contained in:
parent
a71b5ef0a0
commit
b7d25a75c4
@ -111,11 +111,20 @@ class PartCategory(InvenTreeTree):
|
||||
""" True if there are any parts in this category """
|
||||
return self.partcount() > 0
|
||||
|
||||
def get_unique_parameters(self, cascade=True):
|
||||
def prefetch_parts_parameters(self, cascade=True):
|
||||
""" Prefectch parts parameters """
|
||||
|
||||
return self.get_parts(cascade=cascade).prefetch_related('parameters', 'parameters__template')
|
||||
|
||||
def get_unique_parameters(self, cascade=True, prefetch=None):
|
||||
""" Get all unique parameter names for all parts from this category """
|
||||
|
||||
unique_parameters_names = []
|
||||
|
||||
parts = self.get_parts(cascade=cascade).prefetch_related('parameters', 'parameters__template')
|
||||
if prefetch:
|
||||
parts = prefetch
|
||||
else:
|
||||
parts = self.prefetch_parts_parameters(cascade=cascade)
|
||||
|
||||
for part in parts:
|
||||
for parameter in part.parameters.all():
|
||||
@ -123,19 +132,28 @@ class PartCategory(InvenTreeTree):
|
||||
if parameter_name not in unique_parameters_names:
|
||||
unique_parameters_names.append(parameter_name)
|
||||
|
||||
return unique_parameters_names
|
||||
return sorted(unique_parameters_names)
|
||||
|
||||
def get_parts_parameters(self, cascade=True):
|
||||
def get_parts_parameters(self, cascade=True, prefetch=None):
|
||||
""" Get all parameter names and values for all parts from this category """
|
||||
|
||||
category_parameters = []
|
||||
|
||||
parts = self.get_parts(cascade=cascade).prefetch_related('parameters', 'parameters__template')
|
||||
if prefetch:
|
||||
parts = prefetch
|
||||
else:
|
||||
parts = self.prefetch_parts_parameters(cascade=cascade)
|
||||
|
||||
for part in parts:
|
||||
part_parameters = {
|
||||
'IPN': part.IPN,
|
||||
'Name': part.name,
|
||||
'pk': part.pk,
|
||||
'name': part.name,
|
||||
'description': part.description,
|
||||
}
|
||||
# Add IPN only if it exists
|
||||
if part.IPN:
|
||||
part_parameters['IPN'] = part.IPN
|
||||
|
||||
for parameter in part.parameters.all():
|
||||
parameter_name = parameter.template.name
|
||||
parameter_value = parameter.data
|
||||
|
@ -13,6 +13,12 @@
|
||||
|
||||
{% block js_ready %}
|
||||
{{ block.super }}
|
||||
|
||||
/* Hide Button Toolbar */
|
||||
window.onload = function hideButtonToolbar() {
|
||||
var toolbar = document.getElementById("button-toolbar");
|
||||
toolbar.style.display = "none";
|
||||
};
|
||||
|
||||
loadParametricPartTable(
|
||||
"#parametric-part-table",
|
||||
|
@ -1872,6 +1872,7 @@ class PartParameterDelete(AjaxDeleteView):
|
||||
|
||||
class CategoryDetail(DetailView):
|
||||
""" Detail view for PartCategory """
|
||||
|
||||
model = PartCategory
|
||||
context_object_name = 'category'
|
||||
queryset = PartCategory.objects.all().prefetch_related('children')
|
||||
@ -1891,17 +1892,29 @@ class CategoryDetail(DetailView):
|
||||
|
||||
class CategoryParametric(CategoryDetail):
|
||||
""" Parametric view for PartCategory """
|
||||
|
||||
template_name = 'part/category_parametric.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
||||
context = super(CategoryParametric, self).get_context_data(**kwargs).copy()
|
||||
|
||||
category = kwargs['object']
|
||||
context['headers'] = category.get_unique_parameters()
|
||||
context['headers'].append('IPN')
|
||||
context['headers'].append('Name')
|
||||
context['parameters'] = category.get_parts_parameters()
|
||||
# Get current category
|
||||
category = kwargs.get('object', None)
|
||||
|
||||
if category:
|
||||
cascade = kwargs.get('cascade', True)
|
||||
# Prefetch parts parameters
|
||||
parts_parameters = category.prefetch_parts_parameters(cascade=cascade)
|
||||
# Get table headers (unique parameters names)
|
||||
context['headers'] = category.get_unique_parameters(cascade=cascade,
|
||||
prefetch=parts_parameters)
|
||||
# Insert part information
|
||||
context['headers'].insert(0, 'description')
|
||||
context['headers'].insert(0, 'part')
|
||||
# Get parameters data
|
||||
context['parameters'] = category.get_parts_parameters(cascade=cascade,
|
||||
prefetch=parts_parameters)
|
||||
|
||||
return context
|
||||
|
||||
|
@ -179,17 +179,43 @@ function loadParametricPartTable(table, options={}) {
|
||||
var columns = [];
|
||||
|
||||
for (header of table_headers) {
|
||||
columns.push({
|
||||
field: header,
|
||||
title: header,
|
||||
sortable: true,
|
||||
})
|
||||
if (header === 'part') {
|
||||
columns.push({
|
||||
field: 'part',
|
||||
title: '{% trans 'Part' %}',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
|
||||
var name = '';
|
||||
|
||||
if (row.IPN) {
|
||||
name += row.IPN + ' | ' + row.name;
|
||||
} else {
|
||||
name += row.name;
|
||||
}
|
||||
|
||||
return renderLink(name, '/part/' + row.pk + '/');
|
||||
}
|
||||
});
|
||||
} else if (header === 'description') {
|
||||
columns.push({
|
||||
field: header,
|
||||
title: '{% trans 'Description' %}',
|
||||
sortable: true,
|
||||
});
|
||||
} else {
|
||||
columns.push({
|
||||
field: header,
|
||||
title: header,
|
||||
sortable: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(table).inventreeTable({
|
||||
/* url: url,*/
|
||||
sortName: 'name',
|
||||
method: 'get',
|
||||
sortName: 'part',
|
||||
/* method: 'get',*/
|
||||
queryParams: table_headers,
|
||||
groupBy: false,
|
||||
name: options.name || 'parametric',
|
||||
|
Loading…
Reference in New Issue
Block a user