Added 'Parametric Table' tab to category detail view, added part_count to 'Parts' tab

This commit is contained in:
eeintech 2020-09-29 15:16:12 -05:00
parent 9e4a599c44
commit 6b48977e7b
7 changed files with 109 additions and 2 deletions

View File

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

View File

@ -0,0 +1,12 @@
{% extends "part/category.html" %}
{% load static %}
{% load i18n %}
{% block part_list %}
{% include 'part/category_tabs.html' with tab='parametric-table' %}
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='parametric-part-table'>
</table>
{% endblock %}

View File

@ -0,0 +1,12 @@
{% extends "part/category.html" %}
{% load static %}
{% load i18n %}
{% block part_list %}
{% include 'part/category_tabs.html' with tab='part-list' %}
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='part-table'>
</table>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% load i18n %}
{% load inventree_extras %}
<ul class="nav nav-tabs">
<li{% ifequal tab 'part-list' %} class="active"{% endifequal %}>
<a href="{% url 'category-detail' category.id %}">{% trans "Parts" %} <span class="badge">{% decimal part_count %}</span></a>
</li>
<li{% ifequal tab 'parametric-table' %} class='active'{% endifequal %}>
<a href="{% url 'category-parametric' category.id %}">{% trans "Parametric Table" %}</a>
</li>
</ul>

View File

@ -77,7 +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('^.*$', views.CategoryDetail.as_view(), name='category-detail'),
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'),
]
part_bom_urls = [

View File

@ -1875,7 +1875,18 @@ class CategoryDetail(DetailView):
model = PartCategory
context_object_name = 'category'
queryset = PartCategory.objects.all().prefetch_related('children')
template_name = 'part/category.html'
template_name = 'part/category_partlist.html'
def get_context_data(self, **kwargs):
context = super(CategoryDetail, self).get_context_data(**kwargs).copy()
try:
context['part_count'] = kwargs['object'].partcount()
except KeyError:
context['part_count'] = 0
return context
class CategoryEdit(AjaxUpdateView):

View File

@ -163,6 +163,51 @@ function loadSimplePartTable(table, url, options={}) {
}
function loadParametricPartTable(table, url, options={}) {
/* Load parametric part data into specified table.
*
* Args:
* - table: HTML reference to the table
* - 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 = {};
for (var key in params) {
filters[key] = params[key];
}
console.log(filters)
var columns = [
{
field: 'pk',
title: 'ID',
visible: true,
switchable: true,
searchable: false,
}
];
$(table).inventreeTable({
url: url,
sortName: 'pk',
method: 'get',
queryParams: filters,
groupBy: false,
name: options.name || 'part',
original: params,
formatNoMatches: function() { return "{% trans "No parts found" %}"; },
columns: columns,
showColumns: true,
});
}
function loadPartTable(table, url, options={}) {
/* Load part listing data into specified table.
*