mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Unique parameters names from category makes it to bootstrap table
This commit is contained in:
parent
6b48977e7b
commit
d05a5978a0
@ -111,6 +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):
|
||||
""" 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')
|
||||
def before_delete_part_category(sender, instance, using, **kwargs):
|
||||
|
@ -116,10 +116,10 @@
|
||||
</div>
|
||||
|
||||
|
||||
{% block part_list %}
|
||||
{% block category_tables %}
|
||||
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='part-table'>
|
||||
</table>
|
||||
{% endblock part_list %}
|
||||
{% endblock category_tables %}
|
||||
|
||||
{% endblock %}
|
||||
{% 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 %}
|
@ -2,7 +2,7 @@
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block part_list %}
|
||||
{% block category_tables %}
|
||||
|
||||
{% include 'part/category_tabs.html' with tab='parametric-table' %}
|
||||
|
||||
@ -10,3 +10,22 @@
|
||||
</table>
|
||||
|
||||
{% 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 %}
|
@ -2,7 +2,7 @@
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block part_list %}
|
||||
{% block category_tables %}
|
||||
|
||||
{% include 'part/category_tabs.html' with tab='part-list' %}
|
||||
|
||||
|
@ -77,8 +77,8 @@ part_category_urls = [
|
||||
url(r'^edit/?', views.CategoryEdit.as_view(), name='category-edit'),
|
||||
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'^.*$', views.CategoryDetail.as_view(template_name='part/category_partlist.html'), name='category-detail'),
|
||||
url(r'^parametric/?', views.CategoryParametric.as_view(), name='category-parametric'),
|
||||
url(r'^.*$', views.CategoryDetail.as_view(), name='category-detail'),
|
||||
]
|
||||
|
||||
part_bom_urls = [
|
||||
|
@ -1889,6 +1889,21 @@ class CategoryDetail(DetailView):
|
||||
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):
|
||||
""" Update view to edit a PartCategory """
|
||||
model = PartCategory
|
||||
|
@ -171,13 +171,10 @@ function loadParametricPartTable(table, url, options={}) {
|
||||
* - url: Base URL for API query
|
||||
*/
|
||||
|
||||
// Ensure category detail is included
|
||||
options.params['category_detail'] = true;
|
||||
|
||||
var params = options.params || {};
|
||||
console.log(params)
|
||||
|
||||
var filters = {};
|
||||
var filters = loadTableFilters("parts");
|
||||
for (var key in params) {
|
||||
filters[key] = params[key];
|
||||
}
|
||||
@ -187,19 +184,88 @@ function loadParametricPartTable(table, url, options={}) {
|
||||
{
|
||||
field: 'pk',
|
||||
title: 'ID',
|
||||
visible: true,
|
||||
switchable: true,
|
||||
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({
|
||||
field: header,
|
||||
title: header,
|
||||
sortable: true,
|
||||
})
|
||||
}
|
||||
|
||||
$(table).inventreeTable({
|
||||
url: url,
|
||||
sortName: 'pk',
|
||||
method: 'get',
|
||||
queryParams: filters,
|
||||
groupBy: false,
|
||||
name: options.name || 'part',
|
||||
name: options.name || 'parametric',
|
||||
original: params,
|
||||
formatNoMatches: function() { return "{% trans "No parts found" %}"; },
|
||||
columns: columns,
|
||||
|
Loading…
Reference in New Issue
Block a user