2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-19 21:45:39 +00:00

Merge branch 'inventree:master' into matmair/issue2279

This commit is contained in:
Matthias Mair
2021-12-11 00:09:32 +01:00
committed by GitHub
40 changed files with 25517 additions and 17226 deletions

View File

@ -239,6 +239,23 @@ class CategoryParameterList(generics.ListAPIView):
return queryset
class CategoryTree(generics.ListAPIView):
"""
API endpoint for accessing a list of PartCategory objects ready for rendering a tree.
"""
queryset = PartCategory.objects.all()
serializer_class = part_serializers.CategoryTree
filter_backends = [
DjangoFilterBackend,
filters.OrderingFilter,
]
# Order by tree level (top levels first) and then name
ordering = ['level', 'name']
class PartSalePriceList(generics.ListCreateAPIView):
"""
API endpoint for list view of PartSalePriceBreak model
@ -1515,6 +1532,7 @@ part_api_urls = [
# Base URL for PartCategory API endpoints
url(r'^category/', include([
url(r'^tree/', CategoryTree.as_view(), name='api-part-category-tree'),
url(r'^parameters/', CategoryParameterList.as_view(), name='api-part-category-parameter-list'),
url(r'^(?P<pk>\d+)/?', CategoryDetail.as_view(), name='api-part-category-detail'),

View File

@ -70,6 +70,20 @@ class CategorySerializer(InvenTreeModelSerializer):
]
class CategoryTree(InvenTreeModelSerializer):
"""
Serializer for PartCategory tree
"""
class Meta:
model = PartCategory
fields = [
'pk',
'name',
'parent',
]
class PartAttachmentSerializer(InvenTreeAttachmentSerializer):
"""
Serializer for the PartAttachment class

View File

@ -6,6 +6,10 @@
{% include 'part/category_sidebar.html' %}
{% endblock %}
{% block breadcrumb_tree %}
<div id="breadcrumb-tree"></div>
{% endblock breadcrumb_tree %}
{% block heading %}
{% if category %}
{% trans "Part Category" %}: {{ category.name }}
@ -239,8 +243,24 @@
{% endif %}
// Enable left-hand navigation sidebar
enableSidebar('category');
// Enable breadcrumb tree view
enableBreadcrumbTree({
label: 'category',
url: '{% url "api-part-category-tree" %}',
{% if category %}
selected: {{ category.pk }},
{% endif %}
processNode: function(node) {
node.text = node.name;
node.href = `/part/category/${node.pk}/`;
return node;
}
});
loadPartCategoryTable(
$('#subcategory-table'), {
params: {

View File

@ -9,6 +9,10 @@
{% include 'part/part_sidebar.html' %}
{% endblock %}
{% block breadcrumb_tree %}
<div id="breadcrumb-tree"></div>
{% endblock breadcrumb_tree %}
{% block page_content %}
<div class='panel panel-hidden' id='panel-part-stock'>
@ -132,10 +136,6 @@
</div>
</div>
<div class='panel panel-hidden' id='panel-pricing'>
<!-- TODO -->
</div>
<div class='panel panel-hidden' id='panel-variants'>
<div class='panel-heading'>
<div class='d-flex flex-wrap'>
@ -1066,4 +1066,18 @@
enableSidebar('part');
enableBreadcrumbTree({
label: 'part',
url: '{% url "api-part-category-tree" %}',
{% if part.category %}
selected: {{ part.category.pk }},
{% endif %}
processNode: function(node) {
node.text = node.name;
node.href = `/part/category/${node.pk}/`;
return node;
}
});
{% endblock %}

View File

@ -14,9 +14,10 @@
{% endblock %}
{% block breadcrumbs %}
<a href='#' id='breadcrumb-tree-toggle' class="breadcrumb-item"><i class="fas fa-bars"></i></a>
{% if part %}
{% include "part/cat_link.html" with category=part.category part=part %}
{% else %}
{% include 'part/cat_link.html' with category=category %}
{% endif %}
{% endblock %}
{% endblock breadcrumbs %}