Unique parameters names from category makes it to bootstrap table

This commit is contained in:
eeintech 2020-09-29 16:13:08 -05:00
parent 6b48977e7b
commit d05a5978a0
7 changed files with 127 additions and 25 deletions

View File

@ -111,6 +111,20 @@ class PartCategory(InvenTreeTree):
""" True if there are any parts in this category """ """ True if there are any parts in this category """
return self.partcount() > 0 return self.partcount() > 0
def get_unique_parameters(self, cascade=True):
""" Get all parameters for all parts from this category """
parameters = []
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)
return parameters
@receiver(pre_delete, sender=PartCategory, dispatch_uid='partcategory_delete_log') @receiver(pre_delete, sender=PartCategory, dispatch_uid='partcategory_delete_log')
def before_delete_part_category(sender, instance, using, **kwargs): def before_delete_part_category(sender, instance, using, **kwargs):

View File

@ -116,10 +116,10 @@
</div> </div>
{% block part_list %} {% block category_tables %}
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='part-table'> <table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='part-table'>
</table> </table>
{% endblock part_list %} {% endblock category_tables %}
{% endblock %} {% endblock %}
{% block js_load %} {% block js_load %}
@ -245,16 +245,4 @@
}, },
); );
loadParametricPartTable(
"#parametric-part-table",
"{% url 'api-part-list' %}",
{
params: {
{% if category %}category: {{ category.id }},
{% else %}category: "null",
{% endif %}
},
},
);
{% endblock %} {% endblock %}

View File

@ -2,7 +2,7 @@
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
{% block part_list %} {% block category_tables %}
{% include 'part/category_tabs.html' with tab='parametric-table' %} {% include 'part/category_tabs.html' with tab='parametric-table' %}
@ -10,3 +10,22 @@
</table> </table>
{% endblock %} {% endblock %}
{% block js_ready %}
{{ block.super }}
loadParametricPartTable(
"#parametric-part-table",
"{% url 'api-part-list' %}",
{
params: {
{% if category %}category: {{ category.id }},
{% else %}category: "null",
{% endif %}
},
headers: {{ parameters|safe }},
name: 'parametric',
},
);
{% endblock %}

View File

@ -2,7 +2,7 @@
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
{% block part_list %} {% block category_tables %}
{% include 'part/category_tabs.html' with tab='part-list' %} {% include 'part/category_tabs.html' with tab='part-list' %}

View File

@ -77,8 +77,8 @@ part_category_urls = [
url(r'^edit/?', views.CategoryEdit.as_view(), name='category-edit'), url(r'^edit/?', views.CategoryEdit.as_view(), name='category-edit'),
url(r'^delete/?', views.CategoryDelete.as_view(), name='category-delete'), url(r'^delete/?', views.CategoryDelete.as_view(), name='category-delete'),
url(r'^parametric/?', views.CategoryDetail.as_view(template_name='part/category_parametric.html'), name='category-parametric'), url(r'^parametric/?', views.CategoryParametric.as_view(), name='category-parametric'),
url(r'^.*$', views.CategoryDetail.as_view(template_name='part/category_partlist.html'), name='category-detail'), url(r'^.*$', views.CategoryDetail.as_view(), name='category-detail'),
] ]
part_bom_urls = [ part_bom_urls = [

View File

@ -1889,6 +1889,21 @@ class CategoryDetail(DetailView):
return context return context
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['parameters'] = category.get_unique_parameters()
print(context)
return context
class CategoryEdit(AjaxUpdateView): class CategoryEdit(AjaxUpdateView):
""" Update view to edit a PartCategory """ """ Update view to edit a PartCategory """
model = PartCategory model = PartCategory

View File

@ -171,13 +171,10 @@ function loadParametricPartTable(table, url, options={}) {
* - url: Base URL for API query * - url: Base URL for API query
*/ */
// Ensure category detail is included
options.params['category_detail'] = true;
var params = options.params || {}; var params = options.params || {};
console.log(params) console.log(params)
var filters = {}; var filters = loadTableFilters("parts");
for (var key in params) { for (var key in params) {
filters[key] = params[key]; filters[key] = params[key];
} }
@ -187,19 +184,88 @@ function loadParametricPartTable(table, url, options={}) {
{ {
field: 'pk', field: 'pk',
title: 'ID', title: 'ID',
visible: true, visible: false,
switchable: true, switchable: false,
searchable: 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({
field: header,
title: header,
sortable: true,
})
}
$(table).inventreeTable({ $(table).inventreeTable({
url: url, url: url,
sortName: 'pk', sortName: 'pk',
method: 'get', method: 'get',
queryParams: filters, queryParams: filters,
groupBy: false, groupBy: false,
name: options.name || 'part', 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,