Remove nav tree

This commit is contained in:
Oliver 2021-10-29 10:54:15 +11:00
parent 80a41affc1
commit 890fd0f1a0
7 changed files with 53 additions and 209 deletions

View File

@ -20,20 +20,3 @@
{% include 'part/cat_link.html' with category=category %}
{% endif %}
{% endblock %}
{% block js_ready %}
{{ block.super }}
loadTree("{% url 'api-part-tree' %}",
"#part-tree",
{
name: 'part',
}
);
initNavTree({
label: 'part',
treeId: '#sidenav-left',
toggleId: '#toggle-part-tree',
});
{% endblock %}

View File

@ -426,19 +426,6 @@
{% block js_ready %}
{{ block.super }}
loadTree("{% url 'api-stock-tree' %}",
"#stock-tree",
{
name: 'stock',
}
);
initNavTree({
label: 'stock',
treeId: '#sidenav-left',
toggleId: '#toggle-stock-tree',
});
$("#stock-serialize").click(function() {
launchModalForm(
"{% url 'stock-item-serialize' item.id %}",

View File

@ -24,21 +24,3 @@
{% include 'stock/loc_link.html' with location=location %}
{% endif %}
{% endblock %}
{% block js_ready %}
{{ block.super }}
loadTree("{% url 'api-stock-tree' %}",
"#stock-tree",
{
name: 'stock',
}
);
initNavTree({
label: 'stock',
treeId: '#sidenav-left',
toggleId: '#toggle-stock-tree',
});
{% endblock %}

View File

@ -7,6 +7,40 @@
{% inventree_title %} | {% trans "Index" %}
{% endblock %}
{% block sidebar %}
<!-- Part Entries -->
{% include "sidebar_header.html" with text="Parts" icon="fa-shapes" %}
{% include "sidebar_item.html" with label='starred-parts' text="Starred Parts" icon="fa-star" badge=True %}
{% include "sidebar_item.html" with label='latest-parts' text="Latest Parts" icon="fa-newspaper" badge=True %}
{% include "sidebar_item.html" with label='bom-validation' text="BOM Requires Attention" icon="fa-times-circle" badge=True %}
<!-- Stock Entries -->
{% include "sidebar_header.html" with text="Stock" icon="fa-boxes" %}
{% include "sidebar_item.html" with label='recently-updated-stock' text="Recently Updates" icon="fa-clock" badge=True %}
{% include "sidebar_item.html" with label='low-stock' text="Low Stock" icon="fa-shopping-cart" badge=True %}
{% include "sidebar_item.html" with label='depleted-stock' text="Depleted Stock" icon="fa-times badge=True" %}
{% include "sidebar_item.html" with label='stock-to-build' text="Need to Build" icon="fa-bullhorn" badge=True %}
{% include "sidebar_item.html" with label='expired-stock' text="Expired Stock" icon="fa-calendar-times" badge=True %}
{% include "sidebar_item.html" with label='stale-stock' text="Stale Stock" icon="fa-stopwatch" badge=True %}
<!-- Build Orders -->
{% include "sidebar_header.html" with text="Build Orders" icon="fa-tools" %}
{% include "sidebar_item.html" with label='build-pending' text="In Progress" icon="fa-cogs" badge=True %}
{% include "sidebar_item.html" with label='build-overdue' text="Overdue" icon="fa-calendar-times" badge=True %}
<!-- Purchase Orders -->
{% include "sidebar_header.html" with text="Purchase Orders" icon="fa-shopping-cart" %}
{% include "sidebar_item.html" with label='po-outstanding' text="Outstanding" icon="fa-sign-in-alt" badge=True %}
{% include "sidebar_item.html" with label='po-overdue' text="Overdue" icon="fa-calendar-times" badge=True %}
<!-- Sales Orders -->
{% include "sidebar_header.html" with text="Sales Orders" icon="fa-truck" %}
{% include "sidebar_item.html" with label='so-outstanding' text="Outstanding" icon="fa-sign-out-alt" badge=True %}
{% include "sidebar_item.html" with label='so-overdue' text="Overdue" icon="fa-calendar-times" badge=True %}
{% endblock %}
{% block content %}
<h3>{% inventree_title %} </h3>
<hr>
@ -320,4 +354,6 @@ loadSalesOrderTable("#table-so-overdue", {
{% endif %}
enableSidebar('index');
{% endblock %}

View File

@ -3,8 +3,6 @@
/* exported
enableSidebar,
initNavTree,
loadTree,
onPanelLoad,
*/
@ -81,159 +79,6 @@ function onPanelLoad(panel, callback) {
});
}
function loadTree(url, tree, options={}) {
/* Load the side-nav tree view
Args:
url: URL to request tree data
tree: html ref to treeview
options:
data: data object to pass to the AJAX request
selected: ID of currently selected item
name: name of the tree
*/
var data = {};
if (options.data) {
data = options.data;
}
var key = 'inventree-sidenav-items-';
if (options.name) {
key += options.name;
}
$.ajax({
url: url,
type: 'get',
dataType: 'json',
data: data,
success: function(response) {
if (response.tree) {
$(tree).treeview({
data: response.tree,
enableLinks: true,
showTags: true,
});
if (localStorage.getItem(key)) {
var saved_exp = localStorage.getItem(key).split(',');
// Automatically expand the desired notes
for (var q = 0; q < saved_exp.length; q++) {
$(tree).treeview('expandNode', parseInt(saved_exp[q]));
}
}
// Setup a callback whenever a node is toggled
$(tree).on('nodeExpanded nodeCollapsed', function(event, data) {
// Record the entire list of expanded items
var expanded = $(tree).treeview('getExpanded');
var exp = [];
for (var i = 0; i < expanded.length; i++) {
exp.push(expanded[i].nodeId);
}
// Save the expanded nodes
localStorage.setItem(key, exp);
});
}
},
error: function(xhr, ajaxOptions, thrownError) {
// TODO
}
});
}
/**
* Initialize navigation tree display
*/
function initNavTree(options) {
var resize = true;
if ('resize' in options) {
resize = options.resize;
}
var label = options.label || 'nav';
var stateLabel = `${label}-tree-state`;
var widthLabel = `${label}-tree-width`;
var treeId = options.treeId || '#sidenav-left';
var toggleId = options.toggleId;
// Initially hide the tree
$(treeId).animate({
width: '0px',
}, 0, function() {
if (resize) {
$(treeId).resizable({
minWidth: '0px',
maxWidth: '500px',
handles: 'e, se',
grid: [5, 5],
stop: function(event, ui) {
var width = Math.round(ui.element.width());
if (width < 75) {
$(treeId).animate({
width: '0px'
}, 50);
localStorage.setItem(stateLabel, 'closed');
} else {
localStorage.setItem(stateLabel, 'open');
localStorage.setItem(widthLabel, `${width}px`);
}
}
});
}
var state = localStorage.getItem(stateLabel);
var width = localStorage.getItem(widthLabel) || '300px';
if (state && state == 'open') {
$(treeId).animate({
width: width,
}, 50);
}
});
// Register callback for 'toggle' button
if (toggleId) {
$(toggleId).click(function() {
var state = localStorage.getItem(stateLabel) || 'closed';
var width = localStorage.getItem(widthLabel) || '300px';
if (state == 'open') {
$(treeId).animate({
width: '0px'
}, 50);
localStorage.setItem(stateLabel, 'closed');
} else {
$(treeId).animate({
width: width,
}, 50);
localStorage.setItem(stateLabel, 'open');
}
});
}
}
/**
* Enable support for sidebar on this page
@ -297,7 +142,8 @@ function setSidebarState(label, state) {
if (state == "collapsed") {
$('.sidebar-item-text').animate({
opacity: 0.0,
'opacity': 0.0,
'font-size': '0%',
}, 100, function() {
$('.sidebar-item-text').hide();
$('#sidebar-toggle-icon').removeClass('fa-chevron-left').addClass('fa-chevron-right');
@ -306,7 +152,8 @@ function setSidebarState(label, state) {
$('.sidebar-item-text').show();
$('#sidebar-toggle-icon').removeClass('fa-chevron-right').addClass('fa-chevron-left');
$('.sidebar-item-text').animate({
opacity: 1.0,
'opacity': 1.0,
'font-size': '100%',
}, 100);
}

View File

@ -1,6 +1,8 @@
{% load i18n %}
<span title='{% trans text %}' class="list-group-item sidebar-list-group-item border-end-0 d-inline-block text-truncate" data-bs-parent="#sidebar">
<h5>
<i class="bi bi-bootstrap"></i><span class='sidebar-item-icon fas {{ icon }}'></span><span class='sidebar-item-text' style='display: none;'>{% trans text %}</span>
</h5>
<h6>
<i class="bi bi-bootstrap"></i>
{% if icon %}<span class='sidebar-item-icon fas {{ icon }}'></span>{% endif %}
{% if text %}<span class='sidebar-item-text' style='display: none;'>{% trans text %}</span>{% endif %}
</h6>
</span>

View File

@ -1,4 +1,11 @@
{% load i18n %}
<a href="#" id='select-{{ label }}' title='{% trans text %}' class="list-group-item sidebar-list-group-item border-end-0 d-inline-block text-truncate sidebar-selector" data-bs-parent="#sidebar">
<i class="bi bi-bootstrap"></i><span class='sidebar-item-icon fas {{ icon }}'></span><span class='sidebar-item-text' style='display: none;'>{% trans text %}</span>
<i class="bi bi-bootstrap"></i>
<span class='sidebar-item-icon fas {{ icon }}'></span>
<span class='sidebar-item-text' style='display: none;'>{% trans text %}</span>
{% if badge %}
<span id='sidebar-badge-{{ label }}' class='sidebar-item-badge badge rounded-pill badge-right bg-dark'>
<span class='fas fa-spin fa-spinner'></span>
</span>
{% endif %}
</a>