From 5aa43a5a18e9d5a384e767e2eed79581812a28d6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 10 Apr 2020 12:54:54 +1000 Subject: [PATCH] Load / save stock table filters in session storage --- .../static/script/inventree/stock.js | 56 +++++++++++++++++-- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/InvenTree/InvenTree/static/script/inventree/stock.js b/InvenTree/InvenTree/static/script/inventree/stock.js index 996f566fb6..27d720c410 100644 --- a/InvenTree/InvenTree/static/script/inventree/stock.js +++ b/InvenTree/InvenTree/static/script/inventree/stock.js @@ -14,6 +14,48 @@ function getStockLocations(filters={}, options={}) { return inventreeGet('/api/stock/location/', filters, options) } +function loadStockFilters() { + // Load the stock table filters from session-storage + var filterstring = inventreeLoad("stockfilters", "cascade=true&loc=1"); + + var split = filterstring.split("&"); + + var filters = {}; + + console.log("Loaded stock filters: " + filterstring); + + split.forEach(function(item, index) { + var f = item.split('='); + + if (f.length == 2) { + filters[f[0]] = f[1]; + } else { + console.log("Improperly formatted filter: " + item); + } + }); + + return filters; +} + + +function saveStockFilters(filters) { + // Save the stock table filters to session storage + + var strings = []; + + for (var key in filters) { + strings.push(key + "=" + filters[key]); + } + + var filterstring = strings.join('&'); + + console.log("Saving stock filters: " + filterstring); + + inventreeSave("stockfilters", filterstring); +} + + + /* Functions for interacting with stock management forms */ @@ -40,19 +82,23 @@ function loadStockTable(table, options) { * buttons - Which buttons to link to stock selection callbacks */ + // List of user-params which override the default filters var params = options.params || {}; - // Enforce 'cascade' option - // TODO - Make this user-configurable? - params.cascade = true; + var filters = loadStockFilters(); - console.log('load stock table'); + // Override the default values, or add new ones + for (var key in params) { + filters[key] = params[key]; + } table.inventreeTable({ method: 'get', formatNoMatches: function() { return 'No stock items matching query'; }, + url: options.url, + queryParams: filters, customSort: customGroupSorter, groupBy: true, groupByField: options.groupByField || 'part', @@ -241,8 +287,6 @@ function loadStockTable(table, options) { title: 'Notes', } ], - url: options.url, - queryParams: params, }); if (options.buttons) {