From 1f003b3f543c1ec0b3bddf6ab5f668483c5d5857 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 29 Mar 2022 23:27:44 +1100 Subject: [PATCH] Add results for part categories and stock locations --- InvenTree/InvenTree/static/css/inventree.css | 1 + .../js/translated/model_renderers.js | 2 + InvenTree/templates/js/translated/search.js | 82 +++++++++++++------ 3 files changed, 60 insertions(+), 25 deletions(-) diff --git a/InvenTree/InvenTree/static/css/inventree.css b/InvenTree/InvenTree/static/css/inventree.css index 78f3f4addc..c2179995a2 100644 --- a/InvenTree/InvenTree/static/css/inventree.css +++ b/InvenTree/InvenTree/static/css/inventree.css @@ -1044,4 +1044,5 @@ a { border-top: 1px solid var(--border-color); padding: 3px; margin-top: 3px; + overflow: hidden; } \ No newline at end of file diff --git a/InvenTree/templates/js/translated/model_renderers.js b/InvenTree/templates/js/translated/model_renderers.js index 5f81cb9abf..8924687d3c 100644 --- a/InvenTree/templates/js/translated/model_renderers.js +++ b/InvenTree/templates/js/translated/model_renderers.js @@ -10,7 +10,9 @@ renderCompany, renderManufacturerPart, renderOwner, + renderPart, renderPartCategory, + renderStockItem, renderStockLocation, renderSupplierPart, */ diff --git a/InvenTree/templates/js/translated/search.js b/InvenTree/templates/js/translated/search.js index 4a59bd0a34..5a5fd21eed 100644 --- a/InvenTree/templates/js/translated/search.js +++ b/InvenTree/templates/js/translated/search.js @@ -78,32 +78,64 @@ function updateSearch() { // Show the "searching" text $('#offcanvas-search').find('#search-pending').show(); - // Search for matching parts - addSearchQuery( - 'part', - '{% trans "Parts" %}', - '{% url "api-part-list" %}', - {}, - renderPart, - { - url: '/part', - } - ); + if (user_settings.SEARCH_PREVIEW_SHOW_PARTS) { + // Search for matching parts + addSearchQuery( + 'part', + '{% trans "Parts" %}', + '{% url "api-part-list" %}', + {}, + renderPart, + { + url: '/part', + } + ); + } - // Search for matching stock items - addSearchQuery( - 'stock', - '{% trans "Stock Items" %}', - '{% url "api-stock-list" %}', - { - part_detail: true, - location_detail: true, - }, - renderStockItem, - { - url: '/stock/item', - } - ); + if (user_settings.SEARCH_PREVIEW_SHOW_CATEGORIES) { + // Search for matching part categories + addSearchQuery( + 'category', + '{% trans "Part Categories" %}', + '{% url "api-part-category-list" %}', + {}, + renderPartCategory, + { + url: '/part/category', + }, + ); + } + + if (user_settings.SEARCH_PREVIEW_SHOW_STOCK) { + // Search for matching stock items + addSearchQuery( + 'stock', + '{% trans "Stock Items" %}', + '{% url "api-stock-list" %}', + { + part_detail: true, + location_detail: true, + }, + renderStockItem, + { + url: '/stock/item', + } + ); + } + + if (user_settings.SEARCH_PREVIEW_SHOW_LOCATIONS) { + // Search for matching stock locations + addSearchQuery( + 'location', + '{% trans "Stock Locations" %}', + '{% url "api-location-list" %}', + {}, + renderStockLocation, + { + url: '/stock/location', + } + ); + } // Wait until all the pending queries are completed $.when.apply($, searchQueries).done(function() {