diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py
index afb2dfa64e..707b0b948c 100644
--- a/InvenTree/part/models.py
+++ b/InvenTree/part/models.py
@@ -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):
diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html
index 1f5ee7c48b..0f5ba6de43 100644
--- a/InvenTree/part/templates/part/category.html
+++ b/InvenTree/part/templates/part/category.html
@@ -116,10 +116,10 @@
-{% block part_list %}
+{% block category_tables %}
-{% 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 %}
\ No newline at end of file
diff --git a/InvenTree/part/templates/part/category_parametric.html b/InvenTree/part/templates/part/category_parametric.html
index 7139a539b0..5c99fe391b 100644
--- a/InvenTree/part/templates/part/category_parametric.html
+++ b/InvenTree/part/templates/part/category_parametric.html
@@ -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 @@
{% 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 %}
\ No newline at end of file
diff --git a/InvenTree/part/templates/part/category_partlist.html b/InvenTree/part/templates/part/category_partlist.html
index bf4aef52a8..302fdd3a02 100644
--- a/InvenTree/part/templates/part/category_partlist.html
+++ b/InvenTree/part/templates/part/category_partlist.html
@@ -2,7 +2,7 @@
{% load static %}
{% load i18n %}
-{% block part_list %}
+{% block category_tables %}
{% include 'part/category_tabs.html' with tab='part-list' %}
diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py
index 88d15c1b5b..32cd1b0615 100644
--- a/InvenTree/part/urls.py
+++ b/InvenTree/part/urls.py
@@ -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 = [
diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py
index 3c94afc5a5..80e5beadf8 100644
--- a/InvenTree/part/views.py
+++ b/InvenTree/part/views.py
@@ -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
diff --git a/InvenTree/templates/js/part.html b/InvenTree/templates/js/part.html
index 0b32ef61b9..4d8d09dc9c 100644
--- a/InvenTree/templates/js/part.html
+++ b/InvenTree/templates/js/part.html
@@ -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 = '' + 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) {
+ 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,