mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Now loading data! Still need to be bonified
This commit is contained in:
parent
d05a5978a0
commit
40d8a07acc
@ -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')
|
||||
|
@ -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 %}
|
@ -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
|
||||
|
||||
|
@ -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 = '<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) {
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user