Refactor PartCategory views

This commit is contained in:
Oliver 2021-07-15 17:26:06 +10:00
parent d5bf108fef
commit 72337dab49
8 changed files with 106 additions and 187 deletions

View File

@ -3,7 +3,7 @@
{% load i18n %} {% load i18n %}
{% block menubar %} {% block menubar %}
{% include 'part/category_navbar.html' with tab='parts' %} {% include 'part/category_navbar.html' %}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
@ -115,63 +115,81 @@
</div> </div>
{% block category_content %} {% block page_content %}
<div id='button-toolbar'> <div class='panel panel-default panel-inventree panel-hidden' id='panel-parts'>
<div class='btn-group'> <div class='panel-heading'>
<button class='btn btn-default' id='part-export' title='{% trans "Export Part Data" %}'> <h4>{% trans "Parts" %}</h4>
<span class='fas fa-file-download'></span> {% trans "Export" %} </div>
</button> <div id='part-button-toolbar'>
{% if roles.part.add %}
<button class='btn btn-success' id='part-create' title='{% trans "Create new part" %}'>
<span class='fas fa-plus-circle'></span> {% trans "New Part" %}
</button>
{% endif %}
<div class='btn-group'> <div class='btn-group'>
<button id='part-options' class='btn btn-primary dropdown-toggle' type='button' data-toggle="dropdown">{% trans "Options" %}<span class='caret'></span></button> <button class='btn btn-default' id='part-export' title='{% trans "Export Part Data" %}'>
<ul class='dropdown-menu'> <span class='fas fa-file-download'></span> {% trans "Export" %}
{% if roles.part.change %} </button>
<li><a href='#' id='multi-part-category' title='{% trans "Set category" %}'>{% trans "Set Category" %}</a></li> {% if roles.part.add %}
{% endif %} <button class='btn btn-success' id='part-create' title='{% trans "Create new part" %}'>
<li><a href='#' id='multi-part-order' title='{% trans "Order parts" %}'>{% trans "Order Parts" %}</a></li> <span class='fas fa-plus-circle'></span> {% trans "New Part" %}
<li><a href='#' id='multi-part-export' title='{% trans "Export" %}'>{% trans "Export Data" %}</a></li> </button>
</ul> {% endif %}
</div> <div class='btn-group'>
<!-- Buttons to toggle between grid and table view --> <button id='part-options' class='btn btn-primary dropdown-toggle' type='button' data-toggle="dropdown">{% trans "Options" %}<span class='caret'></span></button>
<button id='view-list' class='btn btn-default' type='button' title='{% trans "View list display" %}'> <ul class='dropdown-menu'>
<span class='fas fa-th-list'></span> {% if roles.part.change %}
</button> <li><a href='#' id='multi-part-category' title='{% trans "Set category" %}'>{% trans "Set Category" %}</a></li>
<button id='view-grid' class='btn btn-default' type='button' title='{% trans "View grid display" %}'> {% endif %}
<span class='fas fa-th'></span> <li><a href='#' id='multi-part-order' title='{% trans "Order parts" %}'>{% trans "Order Parts" %}</a></li>
</button> <li><a href='#' id='multi-part-export' title='{% trans "Export" %}'>{% trans "Export Data" %}</a></li>
<div class='filter-list' id='filter-list-parts'> </ul>
<!-- Empty div --> </div>
<!-- Buttons to toggle between grid and table view -->
<button id='view-list' class='btn btn-default' type='button' title='{% trans "View list display" %}'>
<span class='fas fa-th-list'></span>
</button>
<button id='view-grid' class='btn btn-default' type='button' title='{% trans "View grid display" %}'>
<span class='fas fa-th'></span>
</button>
<div class='filter-list' id='filter-list-parts'>
<!-- Empty div -->
</div>
</div> </div>
</div> </div>
<div class='panel-content'>
<table class='table table-striped table-condensed' data-toolbar='#part-button-toolbar' id='part-table'>
</table>
</div>
</div> </div>
<div class='panel panel-default panel-inventree'> <div class='panel panel-default panel-inventree panel-hidden' id='panel-parameters'>
<div class='panel-heading'> <div class='panel-heading'>
<h4> <h4>{% trans "Part Parameters" %}</h4>
{% block heading %}
{% trans "Parts" %}
{% endblock %}
</h4>
</div> </div>
<div class='panel-content'> <div class='panel-content'>
{% block details %} <table class='table table-striped table-condensed' data-toolbar='#param-button-toolbar' id='parametric-part-table'>
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='part-table'> </table>
</table> </div>
{% endblock %} </div>
<div class='panel panel-default panel-inventree panel-hidden' id='panel-subcategories'>
<div class='panel-heading'>
<h4>{% trans "Subcategories" %}</h4>
</div>
<div class='panel-content'>
<div id='subcategory-button-toolbar'>
<div class='button-toolbar container-fluid' style='float: right;'>
<div class='filter-list' id='filter-list-category'>
<!-- An empty div in which the filter list will be constructed -->
</div>
</div>
</div>
<table class='table table-striped table-condensed' id='subcategory-table' data-toolbar='#subcategory-button-toolbar'></table>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
{% block category_tables %}
{% endblock category_tables %}
{% endblock %} {% endblock %}
{% block js_load %} {% block js_load %}
{{ block.super }} {{ block.super }}
@ -180,6 +198,26 @@
{% block js_ready %} {% block js_ready %}
{{ block.super }} {{ block.super }}
loadPartCategoryTable($('#subcategory-table'), {
params: {
{% if category %}
parent: {{ category.pk }}
{% else %}
parent: 'null'
{% endif %}
}
});
{% if category %}
loadParametricPartTable(
"#parametric-part-table",
{
headers: {{ headers|safe }},
data: {{ parameters|safe }},
}
);
{% endif %}
enableNavbar({ enableNavbar({
label: 'category', label: 'category',
toggleId: '#category-menu-toggle', toggleId: '#category-menu-toggle',
@ -328,4 +366,9 @@
$('#view-list').hide(); $('#view-list').hide();
} }
attachNavCallbacks({
name: 'partcategory',
default: 'part-stock'
});
{% endblock %} {% endblock %}

View File

@ -11,31 +11,23 @@
</a> </a>
</li> </li>
<li class='list-group-item {% if tab == "subcategories" %}active{% endif %}' title='{% trans "Subcategories" %}'> <li class='list-group-item' title='{% trans "Subcategories" %}'>
{% if category %} <a href='#' id='select-subcategories' class='nav-toggle'>
<a href='{% url "category-subcategory" category.id %}'>
{% else %}
<a href='{% url "category-index-subcategory" %}'>
{% endif %}
<span class='fas fa-sitemap sidebar-icon'></span> <span class='fas fa-sitemap sidebar-icon'></span>
{% trans "Subcategories" %} {% trans "Subcategories" %}
</a> </a>
</li> </li>
<li class='list-group-item {% if tab == "parts" %}active{% endif %}' title='{% trans "Parts" %}'> <li class='list-group-item' title='{% trans "Parts" %}'>
{% if category %} <a href='#' id='select-parts' class='nav-toggle'>
<a href='{% url "category-detail" category.id %}'>
{% else %}
<a href='{% url "part-index" %}'>
{% endif %}
<span class='fas fa-shapes sidebar-icon'></span> <span class='fas fa-shapes sidebar-icon'></span>
{% trans "Parts" %} {% trans "Parts" %}
</a> </a>
</li> </li>
{% if show_import and user.is_staff and roles.part.add %} {% if show_import and user.is_staff and roles.part.add %}
<li class='list-group-item {% if tab == "import" %}active{% endif %}' title='{% trans "Import Parts" %}'> <li class='list-group-item' title='{% trans "Import Parts" %}'>
<a href='{% url "part-import" %}'> <a href='#' id='select-part-import' class='nav-toggle'>
<span class='fas fa-file-upload sidebar-icon'></span> <span class='fas fa-file-upload sidebar-icon'></span>
{% trans "Import Parts" %} {% trans "Import Parts" %}
</a> </a>
@ -43,8 +35,8 @@
{% endif %} {% endif %}
{% if category %} {% if category %}
<li class='list-group-item {% if tab == "parameters" %}active{% endif %}' title='{% trans "Parameters" %}'> <li class='list-group-item' title='{% trans "Parameters" %}'>
<a href='{% url "category-parametric" category.id %}'> <a href='#' id='select-parameters' class='nav-toggle'>
<span class='fas fa-tasks sidebar-icon'></span> <span class='fas fa-tasks sidebar-icon'></span>
{% trans "Parameters" %} {% trans "Parameters" %}
</a> </a>

View File

@ -1,37 +0,0 @@
{% extends "part/category.html" %}
{% load static %}
{% load i18n %}
{% block menubar %}
{% include 'part/category_navbar.html' with tab='parameters' %}
{% endblock %}
{% block heading %}
{% trans "Part Parameters" %}
{% endblock %}
{% block details %}
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='parametric-part-table'>
</table>
{% endblock %}
{% block js_ready %}
{{ block.super }}
/* Hide Button Toolbar */
window.onload = function hideButtonToolbar() {
var toolbar = document.getElementById("button-toolbar");
toolbar.style.display = "none";
};
loadParametricPartTable(
"#parametric-part-table",
{
headers: {{ headers|safe }},
data: {{ parameters|safe }},
}
);
{% endblock %}

View File

@ -1,16 +0,0 @@
{% extends "part/category.html" %}
{% load static %}
{% load i18n %}
{% block menubar %}
{% include 'part/category_navbar.html' with tab='parts' %}
{% endblock %}
{% block heading %}
{% trans "Parts" %}
{% endblock %}
{% block details %}
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='part-table'>
</table>
{% endblock %}

View File

@ -3,7 +3,6 @@
{% load i18n %} {% load i18n %}
{% load markdownify %} {% load markdownify %}
{% block menubar %} {% block menubar %}
{% include 'part/navbar.html' %} {% include 'part/navbar.html' %}
{% endblock %} {% endblock %}
@ -116,6 +115,10 @@
</div> </div>
</div> </div>
<div class='panel panel-default panel-inventree panel-hidden' id='panel-pricing'>
<!-- TODO -->
</div>
<div class='panel panel-default panel-inventree panel-hidden' id='panel-variants'> <div class='panel panel-default panel-inventree panel-hidden' id='panel-variants'>
<div class='panel-heading'> <div class='panel-heading'>
<h4>{% trans "Part Variants" %}</h4> <h4>{% trans "Part Variants" %}</h4>
@ -788,11 +791,6 @@
) )
}); });
attachNavCallbacks({
name: 'part',
default: 'part-stock'
});
$('#supplier-create').click(function () { $('#supplier-create').click(function () {
launchModalForm( launchModalForm(
"{% url 'supplier-part-create' %}", "{% url 'supplier-part-create' %}",
@ -895,4 +893,9 @@
}); });
}); });
attachNavCallbacks({
name: 'part',
default: 'part-stock'
});
{% endblock %} {% endblock %}

View File

@ -1,51 +0,0 @@
{% extends "part/category.html" %}
{% load i18n %}
{% load inventree_extras %}
{% load static %}
{% block menubar %}
{% include 'part/category_navbar.html' with tab='subcategories' %}
{% endblock %}
{% block category_content %}
<div class='panel panel-default panel-inventree'>
<div class='panel-heading'>
<h4>{% trans "Subcategories" %}</h4>
</div>
<div id='button-toolbar'>
<div class='button-toolbar container-fluid' style='float: right;'>
<div class='filter-list' id='filter-list-category'>
<!-- An empty div in which the filter list will be constructed -->
</div>
</div>
</div>
<table class='table table-striped table-condensed' id='subcategory-table' data-toolbar='#button-toolbar'></table>
</div>
{% endblock %}
{% block js_ready %}
{{ block.super }}
enableNavbar({
label: 'category',
toggleId: '#category-menu-toggle',
});
loadPartCategoryTable($('#subcategory-table'), {
params: {
{% if category %}
parent: {{ category.pk }}
{% else %}
parent: 'null'
{% endif %}
}
});
{% endblock %}

View File

@ -78,9 +78,6 @@ category_urls = [
url(r'^delete/', views.CategoryDelete.as_view(), name='category-delete'), url(r'^delete/', views.CategoryDelete.as_view(), name='category-delete'),
url(r'^parameters/', include(category_parameter_urls)), url(r'^parameters/', include(category_parameter_urls)),
url(r'^subcategory/', views.CategoryDetail.as_view(template_name='part/subcategory.html'), name='category-subcategory'),
url(r'^parametric/', views.CategoryParametric.as_view(), name='category-parametric'),
# Anything else # Anything else
url(r'^.*$', views.CategoryDetail.as_view(), name='category-detail'), url(r'^.*$', views.CategoryDetail.as_view(), name='category-detail'),
])) ]))

View File

@ -1818,7 +1818,7 @@ class CategoryDetail(InvenTreeRoleMixin, DetailView):
model = PartCategory model = PartCategory
context_object_name = 'category' context_object_name = 'category'
queryset = PartCategory.objects.all().prefetch_related('children') queryset = PartCategory.objects.all().prefetch_related('children')
template_name = 'part/category_partlist.html' template_name = 'part/category.html'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -1829,18 +1829,6 @@ class CategoryDetail(InvenTreeRoleMixin, DetailView):
except KeyError: except KeyError:
context['part_count'] = 0 context['part_count'] = 0
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()
# Get current category # Get current category
category = kwargs.get('object', None) category = kwargs.get('object', None)