From f95346f21458204530dc445a54d1c714ec168e63 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 4 Aug 2021 12:10:49 +1000 Subject: [PATCH 1/2] Make the part thumbnail selection window searchable --- InvenTree/part/api.py | 16 +++++++++++++--- InvenTree/part/templates/part/part_base.html | 10 +++++++--- InvenTree/templates/js/translated/tables.js | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index c0d049ecc7..773631459c 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -338,9 +338,7 @@ class PartThumbs(generics.ListAPIView): - Images may be used for multiple parts! """ - queryset = self.get_queryset() - - # TODO - We should return the thumbnails here, not the full image! + queryset = self.filter_queryset(self.get_queryset()) # Return the most popular parts first data = queryset.values( @@ -349,6 +347,18 @@ class PartThumbs(generics.ListAPIView): return Response(data) + filter_backends = [ + filters.SearchFilter, + ] + + search_fields = [ + 'name', + 'description', + 'IPN', + 'revision', + 'keywords', + 'category__name', + ] class PartThumbsUpdate(generics.RetrieveUpdateAPIView): """ API endpoint for updating Part thumbnails""" diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 5191399f0a..ec637412a8 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -415,13 +415,16 @@ // Callback when the image-selection modal form is displayed // Populate the form with image data (requested via AJAX) - $("#modal-form").find("#image-select-table").bootstrapTable({ - pagination: true, - pageSize: 25, + $("#modal-form").find("#image-select-table").inventreeTable({ url: "{% url 'api-part-thumbs' %}", showHeader: false, + showColumns: false, clickToSelect: true, + sidePagination: 'server', singleSelect: true, + formatNoMatches: function() { + return '{% trans "No matching images found" %}'; + }, columns: [ { checkbox: true, @@ -429,6 +432,7 @@ { field: 'image', title: 'Image', + searchable: true, formatter: function(value, row, index, field) { return "" } diff --git a/InvenTree/templates/js/translated/tables.js b/InvenTree/templates/js/translated/tables.js index afe1fefbc9..88d9a5f99a 100644 --- a/InvenTree/templates/js/translated/tables.js +++ b/InvenTree/templates/js/translated/tables.js @@ -187,7 +187,7 @@ $.fn.inventreeTable = function(options) { if (!options.disablePagination) { options.pagination = true; options.paginationVAlign = options.paginationVAlign || 'both'; - options.pageSize = inventreeLoad(varName, 25); + options.pageSize = options.pageSize || inventreeLoad(varName, 25); options.pageList = [25, 50, 100, 250, 'all']; options.totalField = 'count'; options.dataField = 'results'; From 56c0e289bd7544c1a9b3a87b79b954dca5b30f67 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 4 Aug 2021 12:13:24 +1000 Subject: [PATCH 2/2] Style fix --- InvenTree/part/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 773631459c..a01b05034f 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -360,6 +360,7 @@ class PartThumbs(generics.ListAPIView): 'category__name', ] + class PartThumbsUpdate(generics.RetrieveUpdateAPIView): """ API endpoint for updating Part thumbnails"""