diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 707b0b948c..41fcf0bfce 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -112,18 +112,38 @@ class PartCategory(InvenTreeTree): return self.partcount() > 0 def get_unique_parameters(self, cascade=True): - """ Get all parameters for all parts from this category """ - parameters = [] + """ 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') for part in parts: for parameter in part.parameters.all(): - template_name = parameter.template.name - if template_name not in parameters: - parameters.append(template_name) + parameter_name = parameter.template.name + if parameter_name not in unique_parameters_names: + unique_parameters_names.append(parameter_name) - return parameters + return unique_parameters_names + + def get_parts_parameters(self, cascade=True): + """ 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') + + for part in parts: + part_parameters = { + 'IPN': part.IPN, + 'Name': part.name, + } + for parameter in part.parameters.all(): + parameter_name = parameter.template.name + parameter_value = parameter.data + part_parameters[parameter_name] = parameter_value + + category_parameters.append(part_parameters) + + return category_parameters @receiver(pre_delete, sender=PartCategory, dispatch_uid='partcategory_delete_log') diff --git a/InvenTree/part/templates/part/category_parametric.html b/InvenTree/part/templates/part/category_parametric.html index 5c99fe391b..4643dfee8a 100644 --- a/InvenTree/part/templates/part/category_parametric.html +++ b/InvenTree/part/templates/part/category_parametric.html @@ -16,16 +16,10 @@ loadParametricPartTable( "#parametric-part-table", - "{% url 'api-part-list' %}", - { - params: { - {% if category %}category: {{ category.id }}, - {% else %}category: "null", - {% endif %} - }, - headers: {{ parameters|safe }}, - name: 'parametric', - }, + { + headers: {{ headers|safe }}, + data: {{ parameters|safe }}, + } ); {% endblock %} \ No newline at end of file diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 80e5beadf8..0f0f21b9fc 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -1898,8 +1898,10 @@ class CategoryParametric(CategoryDetail): context = super(CategoryParametric, self).get_context_data(**kwargs).copy() category = kwargs['object'] - context['parameters'] = category.get_unique_parameters() - print(context) + context['headers'] = category.get_unique_parameters() + context['headers'].append('IPN') + context['headers'].append('Name') + context['parameters'] = category.get_parts_parameters() return context diff --git a/InvenTree/templates/js/part.html b/InvenTree/templates/js/part.html index 4d8d09dc9c..5ba46b4f31 100644 --- a/InvenTree/templates/js/part.html +++ b/InvenTree/templates/js/part.html @@ -163,95 +163,22 @@ function loadSimplePartTable(table, url, options={}) { } -function loadParametricPartTable(table, url, options={}) { +function loadParametricPartTable(table, options={}) { /* Load parametric part data into specified table. * * Args: * - table: HTML reference to the table - * - url: Base URL for API query + * - data: Parameters data */ - var params = options.params || {}; - console.log(params) + var table_headers = options.headers + var table_data = options.data +/* console.log(table_headers) + console.log(table_data)*/ - var filters = loadTableFilters("parts"); - for (var key in params) { - filters[key] = params[key]; - } - console.log(filters) + var columns = []; - var columns = [ - { - field: 'pk', - title: 'ID', - visible: false, - switchable: false, - searchable: false, - } - ]; - - columns.push({ - field: 'IPN', - title: 'IPN', - sortable: true, - }), - - columns.push({ - field: 'name', - title: '{% trans 'Part' %}', - sortable: true, - formatter: function(value, row, index, field) { - - var name = ''; - - if (row.IPN) { - name += row.IPN; - name += ' | '; - } - - name += value; - - if (row.revision) { - name += ' | '; - name += row.revision; - } - - if (row.is_template) { - name = '' + name + ''; - } - - var display = imageHoverIcon(row.thumbnail) + renderLink(name, '/part/' + row.pk + '/'); - - if (row.is_template) { - display += ``; - } - - if (row.assembly) { - display += ``; - } - - if (row.starred) { - display += ``; - } - - if (row.salable) { - display += ``; - } - - /* - if (row.component) { - display = display + ``; - } - */ - - if (!row.active) { - display += `{% trans "Inactive" %}`; - } - return display; - } - }); - - for (header of options.headers) { + for (header of table_headers) { columns.push({ field: header, title: header, @@ -260,16 +187,17 @@ function loadParametricPartTable(table, url, options={}) { } $(table).inventreeTable({ - url: url, - sortName: 'pk', +/* url: url,*/ + sortName: 'name', method: 'get', - queryParams: filters, + queryParams: table_headers, groupBy: false, name: options.name || 'parametric', - original: params, +/* original: params,*/ formatNoMatches: function() { return "{% trans "No parts found" %}"; }, columns: columns, showColumns: true, + data: table_data, }); }