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 %}
{% block menubar %}
{% include 'part/category_navbar.html' with tab='parts' %}
{% include 'part/category_navbar.html' %}
{% endblock %}
{% block content %}
@ -115,63 +115,81 @@
</div>
{% block category_content %}
{% block page_content %}
<div id='button-toolbar'>
<div class='btn-group'>
<button class='btn btn-default' id='part-export' title='{% trans "Export Part Data" %}'>
<span class='fas fa-file-download'></span> {% trans "Export" %}
</button>
{% 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='panel panel-default panel-inventree panel-hidden' id='panel-parts'>
<div class='panel-heading'>
<h4>{% trans "Parts" %}</h4>
</div>
<div id='part-button-toolbar'>
<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>
<ul class='dropdown-menu'>
{% if roles.part.change %}
<li><a href='#' id='multi-part-category' title='{% trans "Set category" %}'>{% trans "Set Category" %}</a></li>
{% endif %}
<li><a href='#' id='multi-part-order' title='{% trans "Order parts" %}'>{% trans "Order Parts" %}</a></li>
<li><a href='#' id='multi-part-export' title='{% trans "Export" %}'>{% trans "Export Data" %}</a></li>
</ul>
</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 -->
<button class='btn btn-default' id='part-export' title='{% trans "Export Part Data" %}'>
<span class='fas fa-file-download'></span> {% trans "Export" %}
</button>
{% 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'>
<button id='part-options' class='btn btn-primary dropdown-toggle' type='button' data-toggle="dropdown">{% trans "Options" %}<span class='caret'></span></button>
<ul class='dropdown-menu'>
{% if roles.part.change %}
<li><a href='#' id='multi-part-category' title='{% trans "Set category" %}'>{% trans "Set Category" %}</a></li>
{% endif %}
<li><a href='#' id='multi-part-order' title='{% trans "Order parts" %}'>{% trans "Order Parts" %}</a></li>
<li><a href='#' id='multi-part-export' title='{% trans "Export" %}'>{% trans "Export Data" %}</a></li>
</ul>
</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 class='panel-content'>
<table class='table table-striped table-condensed' data-toolbar='#part-button-toolbar' id='part-table'>
</table>
</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'>
<h4>
{% block heading %}
{% trans "Parts" %}
{% endblock %}
</h4>
<h4>{% trans "Part Parameters" %}</h4>
</div>
<div class='panel-content'>
{% block details %}
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='part-table'>
</table>
{% endblock %}
<div class='panel-content'>
<table class='table table-striped table-condensed' data-toolbar='#param-button-toolbar' id='parametric-part-table'>
</table>
</div>
</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>
{% endblock %}
{% block category_tables %}
{% endblock category_tables %}
{% endblock %}
{% block js_load %}
{{ block.super }}
@ -180,6 +198,26 @@
{% block js_ready %}
{{ 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({
label: 'category',
toggleId: '#category-menu-toggle',
@ -328,4 +366,9 @@
$('#view-list').hide();
}
attachNavCallbacks({
name: 'partcategory',
default: 'part-stock'
});
{% endblock %}

View File

@ -11,31 +11,23 @@
</a>
</li>
<li class='list-group-item {% if tab == "subcategories" %}active{% endif %}' title='{% trans "Subcategories" %}'>
{% if category %}
<a href='{% url "category-subcategory" category.id %}'>
{% else %}
<a href='{% url "category-index-subcategory" %}'>
{% endif %}
<li class='list-group-item' title='{% trans "Subcategories" %}'>
<a href='#' id='select-subcategories' class='nav-toggle'>
<span class='fas fa-sitemap sidebar-icon'></span>
{% trans "Subcategories" %}
</a>
</li>
<li class='list-group-item {% if tab == "parts" %}active{% endif %}' title='{% trans "Parts" %}'>
{% if category %}
<a href='{% url "category-detail" category.id %}'>
{% else %}
<a href='{% url "part-index" %}'>
{% endif %}
<li class='list-group-item' title='{% trans "Parts" %}'>
<a href='#' id='select-parts' class='nav-toggle'>
<span class='fas fa-shapes sidebar-icon'></span>
{% trans "Parts" %}
</a>
</li>
{% 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" %}'>
<a href='{% url "part-import" %}'>
<li class='list-group-item' title='{% trans "Import Parts" %}'>
<a href='#' id='select-part-import' class='nav-toggle'>
<span class='fas fa-file-upload sidebar-icon'></span>
{% trans "Import Parts" %}
</a>
@ -43,8 +35,8 @@
{% endif %}
{% if category %}
<li class='list-group-item {% if tab == "parameters" %}active{% endif %}' title='{% trans "Parameters" %}'>
<a href='{% url "category-parametric" category.id %}'>
<li class='list-group-item' title='{% trans "Parameters" %}'>
<a href='#' id='select-parameters' class='nav-toggle'>
<span class='fas fa-tasks sidebar-icon'></span>
{% trans "Parameters" %}
</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 markdownify %}
{% block menubar %}
{% include 'part/navbar.html' %}
{% endblock %}
@ -116,6 +115,10 @@
</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-heading'>
<h4>{% trans "Part Variants" %}</h4>
@ -788,11 +791,6 @@
)
});
attachNavCallbacks({
name: 'part',
default: 'part-stock'
});
$('#supplier-create').click(function () {
launchModalForm(
"{% url 'supplier-part-create' %}",
@ -895,4 +893,9 @@
});
});
attachNavCallbacks({
name: 'part',
default: 'part-stock'
});
{% 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'^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
url(r'^.*$', views.CategoryDetail.as_view(), name='category-detail'),
]))

View File

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