Save tree state 'per tree'

- Separate save state for Part and Stock tree
This commit is contained in:
Oliver Walters 2019-05-09 21:41:44 +10:00
parent 45223fb607
commit bff0f30b13
5 changed files with 51 additions and 9 deletions

View File

@ -57,7 +57,8 @@ class PartCategory(InvenTreeTree):
(including children of child categories) (including children of child categories)
""" """
return len(Part.objects.filter(category__in=self.getUniqueChildren())) return len(Part.objects.filter(category__in=self.getUniqueChildren(),
active=True))
@property @property
def has_parts(self): def has_parts(self):

View File

@ -34,7 +34,11 @@ InvenTree | Part List
{% block js_ready %} {% block js_ready %}
{{ block.super }} {{ block.super }}
loadTree("{% url 'api-part-tree' %}", loadTree("{% url 'api-part-tree' %}",
"#part-tree"); "#part-tree",
{
name: 'part',
}
);
$("#toggle-part-tree").click(function() { $("#toggle-part-tree").click(function() {
toggleSideNav("#sidenav"); toggleSideNav("#sidenav");

View File

@ -19,6 +19,14 @@
font-size: 11px; font-size: 11px;
} }
.treeview .badge {
font-size: 10px;
}
.treeview .list-group-item {
padding: 6px 12px;
}
/* Force select2 elements in modal forms to be full width */ /* Force select2 elements in modal forms to be full width */
.select-full-width { .select-full-width {
width: 100%; width: 100%;

View File

@ -1,4 +1,26 @@
function loadTree(url, tree, data) { 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({ $.ajax({
url: url, url: url,
@ -13,12 +35,14 @@ function loadTree(url, tree, data) {
showTags: true, showTags: true,
}); });
var saved_exp = sessionStorage.getItem('inventree-sidenav-expanded-items').split(","); if (sessionStorage.getItem(key)) {
var saved_exp = sessionStorage.getItem(key).split(",");
// Automatically expand the desired notes // Automatically expand the desired notes
for (var q = 0; q < saved_exp.length; q++) { for (var q = 0; q < saved_exp.length; q++) {
$(tree).treeview('expandNode', parseInt(saved_exp[q])); $(tree).treeview('expandNode', parseInt(saved_exp[q]));
} }
}
// Setup a callback whenever a node is toggled // Setup a callback whenever a node is toggled
$(tree).on('nodeExpanded nodeCollapsed', function(event, data) { $(tree).on('nodeExpanded nodeCollapsed', function(event, data) {
@ -33,7 +57,7 @@ function loadTree(url, tree, data) {
} }
// Save the expanded nodes // Save the expanded nodes
sessionStorage.setItem('inventree-sidenav-expanded-items', exp); sessionStorage.setItem(key, exp);
}); });
} }
}, },

View File

@ -33,7 +33,12 @@ InvenTree | Stock
initSideNav(); initSideNav();
{{ block.super }} {{ block.super }}
loadTree("{% url 'api-stock-tree' %}", loadTree("{% url 'api-stock-tree' %}",
"#stock-tree"); "#stock-tree",
{
name: 'stock',
selected: 'elab',
}
);
$("#toggle-stock-tree").click(function() { $("#toggle-stock-tree").click(function() {
toggleSideNav("#sidenav"); toggleSideNav("#sidenav");