From 206720849cc878b842cca0e3c8073372a3ac01c8 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 9 May 2019 00:12:50 +1000 Subject: [PATCH 1/3] Reduce icon size in sidenav bar --- InvenTree/static/css/inventree.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/InvenTree/static/css/inventree.css b/InvenTree/static/css/inventree.css index 50d10547e1..296ffa82c2 100644 --- a/InvenTree/static/css/inventree.css +++ b/InvenTree/static/css/inventree.css @@ -10,6 +10,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%; From cc7fb31d6d2846e6433d898a1e1748dfe15bd49e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 9 May 2019 00:13:50 +1000 Subject: [PATCH 2/3] Save and recall expansion state of tree - Save choices to sessionStorage --- InvenTree/InvenTree/views.py | 6 ++++- InvenTree/static/script/inventree/sidenav.js | 25 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 6118f00fd0..fb09c80ad9 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -21,7 +21,11 @@ from rest_framework import views class TreeSerializer(views.APIView): - """ JSON View for serializing a Tree object. + """ 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/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() { From 7ac4308c22a21c9811dce10a426f5817709372e6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 9 May 2019 00:40:44 +1000 Subject: [PATCH 3/3] PEP fix --- InvenTree/InvenTree/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index fb09c80ad9..d2d8e48e35 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -21,7 +21,7 @@ from rest_framework import views class TreeSerializer(views.APIView): - """ JSON View for serializing a Tree object. + """ JSON View for serializing a Tree object. Turns a 'tree' model into a JSON object compatible with bootstrap-treview.