diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 6118f00fd0..d2d8e48e35 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -22,6 +22,10 @@ from rest_framework import views class TreeSerializer(views.APIView): """ JSON View for serializing a Tree object. + + Turns a 'tree' model into a JSON object compatible with bootstrap-treview. + + Ref: https://github.com/jonmiles/bootstrap-treeview """ def itemToJson(self, item): diff --git a/InvenTree/static/css/inventree.css b/InvenTree/static/css/inventree.css index 752885145d..f11760ae5b 100644 --- a/InvenTree/static/css/inventree.css +++ b/InvenTree/static/css/inventree.css @@ -14,6 +14,11 @@ color: #ffcc00; } +/* CSS overrides for treeview */ +.expand-icon { + font-size: 11px; +} + /* Force select2 elements in modal forms to be full width */ .select-full-width { width: 100%; diff --git a/InvenTree/static/script/inventree/sidenav.js b/InvenTree/static/script/inventree/sidenav.js index 382a126148..1beefd0ee1 100644 --- a/InvenTree/static/script/inventree/sidenav.js +++ b/InvenTree/static/script/inventree/sidenav.js @@ -11,6 +11,29 @@ function loadTree(url, tree, data) { data: response.tree, enableLinks: true }); + + var saved_exp = sessionStorage.getItem('inventree-sidenav-expanded-items').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 + sessionStorage.setItem('inventree-sidenav-expanded-items', exp); + }); } }, error: function (xhr, ajaxOptions, thrownError) { @@ -24,6 +47,8 @@ function openSideNav() { document.getElementById("inventree-content").style.marginLeft = "270px"; sessionStorage.setItem('inventree-sidenav-state', 'open'); + + } function closeSideNav() {