From bff0f30b13d4ec6cdc48d10f13a152c0ba8b5505 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 9 May 2019 21:41:44 +1000 Subject: [PATCH] Save tree state 'per tree' - Separate save state for Part and Stock tree --- InvenTree/part/models.py | 3 +- .../part/templates/part/part_app_base.html | 6 +++- InvenTree/static/css/inventree.css | 8 +++++ InvenTree/static/script/inventree/sidenav.js | 36 +++++++++++++++---- .../stock/templates/stock/stock_app_base.html | 7 +++- 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 35a2e8336d..86d65b23b2 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -57,7 +57,8 @@ class PartCategory(InvenTreeTree): (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 def has_parts(self): diff --git a/InvenTree/part/templates/part/part_app_base.html b/InvenTree/part/templates/part/part_app_base.html index 43b12377f6..cb1fbdef90 100644 --- a/InvenTree/part/templates/part/part_app_base.html +++ b/InvenTree/part/templates/part/part_app_base.html @@ -34,7 +34,11 @@ InvenTree | Part List {% block js_ready %} {{ block.super }} loadTree("{% url 'api-part-tree' %}", - "#part-tree"); + "#part-tree", + { + name: 'part', + } + ); $("#toggle-part-tree").click(function() { toggleSideNav("#sidenav"); diff --git a/InvenTree/static/css/inventree.css b/InvenTree/static/css/inventree.css index a6272dc76f..8b1458ef06 100644 --- a/InvenTree/static/css/inventree.css +++ b/InvenTree/static/css/inventree.css @@ -19,6 +19,14 @@ 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 */ .select-full-width { width: 100%; diff --git a/InvenTree/static/script/inventree/sidenav.js b/InvenTree/static/script/inventree/sidenav.js index 93ee6f05ff..f3f0b25171 100644 --- a/InvenTree/static/script/inventree/sidenav.js +++ b/InvenTree/static/script/inventree/sidenav.js @@ -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({ url: url, @@ -13,11 +35,13 @@ function loadTree(url, tree, data) { 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 - for (var q = 0; q < saved_exp.length; q++) { - $(tree).treeview('expandNode', parseInt(saved_exp[q])); + // 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 @@ -33,7 +57,7 @@ function loadTree(url, tree, data) { } // Save the expanded nodes - sessionStorage.setItem('inventree-sidenav-expanded-items', exp); + sessionStorage.setItem(key, exp); }); } }, diff --git a/InvenTree/stock/templates/stock/stock_app_base.html b/InvenTree/stock/templates/stock/stock_app_base.html index 26393626bb..805147f6ad 100644 --- a/InvenTree/stock/templates/stock/stock_app_base.html +++ b/InvenTree/stock/templates/stock/stock_app_base.html @@ -33,7 +33,12 @@ InvenTree | Stock initSideNav(); {{ block.super }} loadTree("{% url 'api-stock-tree' %}", - "#stock-tree"); + "#stock-tree", + { + name: 'stock', + selected: 'elab', + } + ); $("#toggle-stock-tree").click(function() { toggleSideNav("#sidenav");