From 96277edcf18704f2ad3ca5c4caf80baadbce5dfc Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 21 Oct 2020 00:49:17 +1100 Subject: [PATCH] Improvements to progress bar function --- .../static/script/inventree/inventree.js | 33 ++++++++++++++----- InvenTree/build/api.py | 4 ++- InvenTree/build/serializers.py | 1 + InvenTree/templates/js/build.html | 9 +++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/InvenTree/InvenTree/static/script/inventree/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js index 263e28fc01..7532b51f58 100644 --- a/InvenTree/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/InvenTree/static/script/inventree/inventree.js @@ -94,7 +94,7 @@ function makeIconButton(icon, cls, pk, title) { return html; } -function makeProgressBar(value, maximum, opts) { +function makeProgressBar(value, maximum, opts={}) { /* * Render a progessbar! * @@ -120,20 +120,35 @@ function makeProgressBar(value, maximum, opts) { var extraclass = ''; - if (maximum) { - // TODO - Special color? - } - else if (value > maximum) { + if (value > maximum) { extraclass='progress-bar-over'; } else if (value < maximum) { extraclass = 'progress-bar-under'; } - var text = value; + var style = options.style || ''; - if (maximum) { - text += ' / '; - text += maximum; + var text = ''; + + if (style == 'percent') { + // Display e.g. "50%" + + text = `${percent}%`; + } else if (style == 'max') { + // Display just the maximum value + text = `${maximum}`; + } else if (style == 'value') { + // Display just the current value + text = `${value}`; + } else if (style == 'blank') { + // No display! + text = ''; + } else { + /* Default style + * Display e.g. "5 / 10" + */ + + text = `${value} / ${maximum}`; } var id = options.id || 'progress-bar'; diff --git a/InvenTree/build/api.py b/InvenTree/build/api.py index d4e458c506..9b39e19844 100644 --- a/InvenTree/build/api.py +++ b/InvenTree/build/api.py @@ -119,6 +119,7 @@ class BuildItemList(generics.ListCreateAPIView): return query def filter_queryset(self, queryset): + queryset = super().filter_queryset(queryset) # Does the user wish to filter by part? @@ -135,7 +136,8 @@ class BuildItemList(generics.ListCreateAPIView): filter_fields = [ 'build', - 'stock_item' + 'stock_item', + 'install_into', ] diff --git a/InvenTree/build/serializers.py b/InvenTree/build/serializers.py index 6367673ce9..4423619b8a 100644 --- a/InvenTree/build/serializers.py +++ b/InvenTree/build/serializers.py @@ -75,6 +75,7 @@ class BuildItemSerializer(InvenTreeModelSerializer): fields = [ 'pk', 'build', + 'install_into', 'part', 'part_name', 'part_image', diff --git a/InvenTree/templates/js/build.html b/InvenTree/templates/js/build.html index b72d3d179a..886657a2bc 100644 --- a/InvenTree/templates/js/build.html +++ b/InvenTree/templates/js/build.html @@ -102,6 +102,15 @@ function loadBuildTable(table, options) { field: 'quantity', title: '{% trans "Quantity" %}', sortable: true, + formatter: function(value, row, index, field) { + return makeProgressBar( + row.completed, + row.quantity, + { + style: 'max', + } + ); + } }, { field: 'status',