Now loading data! Still need to be bonified

This commit is contained in:
eeintech 2020-09-29 16:49:53 -05:00
parent d05a5978a0
commit 40d8a07acc
4 changed files with 47 additions and 103 deletions

View File

@ -112,18 +112,38 @@ class PartCategory(InvenTreeTree):
return self.partcount() > 0 return self.partcount() > 0
def get_unique_parameters(self, cascade=True): def get_unique_parameters(self, cascade=True):
""" Get all parameters for all parts from this category """ """ Get all unique parameter names for all parts from this category """
parameters = [] unique_parameters_names = []
parts = self.get_parts(cascade=cascade).prefetch_related('parameters', 'parameters__template') parts = self.get_parts(cascade=cascade).prefetch_related('parameters', 'parameters__template')
for part in parts: for part in parts:
for parameter in part.parameters.all(): for parameter in part.parameters.all():
template_name = parameter.template.name parameter_name = parameter.template.name
if template_name not in parameters: if parameter_name not in unique_parameters_names:
parameters.append(template_name) 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') @receiver(pre_delete, sender=PartCategory, dispatch_uid='partcategory_delete_log')

View File

@ -16,16 +16,10 @@
loadParametricPartTable( loadParametricPartTable(
"#parametric-part-table", "#parametric-part-table",
"{% url 'api-part-list' %}", {
{ headers: {{ headers|safe }},
params: { data: {{ parameters|safe }},
{% if category %}category: {{ category.id }}, }
{% else %}category: "null",
{% endif %}
},
headers: {{ parameters|safe }},
name: 'parametric',
},
); );
{% endblock %} {% endblock %}

View File

@ -1898,8 +1898,10 @@ class CategoryParametric(CategoryDetail):
context = super(CategoryParametric, self).get_context_data(**kwargs).copy() context = super(CategoryParametric, self).get_context_data(**kwargs).copy()
category = kwargs['object'] category = kwargs['object']
context['parameters'] = category.get_unique_parameters() context['headers'] = category.get_unique_parameters()
print(context) context['headers'].append('IPN')
context['headers'].append('Name')
context['parameters'] = category.get_parts_parameters()
return context return context

View File

@ -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. /* Load parametric part data into specified table.
* *
* Args: * Args:
* - table: HTML reference to the table * - table: HTML reference to the table
* - url: Base URL for API query * - data: Parameters data
*/ */
var params = options.params || {}; var table_headers = options.headers
console.log(params) var table_data = options.data
/* console.log(table_headers)
console.log(table_data)*/
var filters = loadTableFilters("parts"); var columns = [];
for (var key in params) {
filters[key] = params[key];
}
console.log(filters)
var columns = [ for (header of table_headers) {
{
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 = '<i>' + name + '</i>';
}
var display = imageHoverIcon(row.thumbnail) + renderLink(name, '/part/' + row.pk + '/');
if (row.is_template) {
display += `<span class='fas fa-clone label-right' title='{% trans "Template part" %}'></span>`;
}
if (row.assembly) {
display += `<span class='fas fa-tools label-right' title='{% trans "Assembled part" %}'></span>`;
}
if (row.starred) {
display += `<span class='fas fa-star label-right' title='{% trans "Starred part" %}'></span>`;
}
if (row.salable) {
display += `<span class='fas fa-dollar-sign label-right' title='{% trans "Salable part" %}'></span>`;
}
/*
if (row.component) {
display = display + `<span class='fas fa-cogs label-right' title='Component part'></span>`;
}
*/
if (!row.active) {
display += `<span class='label label-warning label-right'>{% trans "Inactive" %}</span>`;
}
return display;
}
});
for (header of options.headers) {
columns.push({ columns.push({
field: header, field: header,
title: header, title: header,
@ -260,16 +187,17 @@ function loadParametricPartTable(table, url, options={}) {
} }
$(table).inventreeTable({ $(table).inventreeTable({
url: url, /* url: url,*/
sortName: 'pk', sortName: 'name',
method: 'get', method: 'get',
queryParams: filters, queryParams: table_headers,
groupBy: false, groupBy: false,
name: options.name || 'parametric', name: options.name || 'parametric',
original: params, /* original: params,*/
formatNoMatches: function() { return "{% trans "No parts found" %}"; }, formatNoMatches: function() { return "{% trans "No parts found" %}"; },
columns: columns, columns: columns,
showColumns: true, showColumns: true,
data: table_data,
}); });
} }