mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Save tree state 'per tree'
- Separate save state for Part and Stock tree
This commit is contained in:
		@@ -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):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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%;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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,11 +35,13 @@ 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
 | 
				
			||||||
@@ -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);
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user