From 0e55911a6ba38f47fdea6123eb87d6e6f16f5f8f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 13 Apr 2020 22:07:14 +1000 Subject: [PATCH] Index page rendering is now a lot faster - Hide some elements which are currently very expensive to compute - --- InvenTree/InvenTree/views.py | 7 ++-- InvenTree/part/api.py | 4 +- InvenTree/templates/InvenTree/index.html | 38 ++++++++++++------- InvenTree/templates/InvenTree/low_stock.html | 15 ++++++++ .../templates/InvenTree/parts_to_order.html | 15 -------- .../templates/InvenTree/starred_parts.html | 12 +++--- InvenTree/templates/base.html | 1 + 7 files changed, 53 insertions(+), 39 deletions(-) create mode 100644 InvenTree/templates/InvenTree/low_stock.html delete mode 100644 InvenTree/templates/InvenTree/parts_to_order.html diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index e1258385a5..59833d3e6b 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -494,15 +494,16 @@ class IndexView(TemplateView): context = super(TemplateView, self).get_context_data(**kwargs) - context['starred'] = [star.part for star in self.request.user.starred_parts.all()] + # TODO - Re-implement this when a less expensive method is worked out + # context['starred'] = [star.part for star in self.request.user.starred_parts.all()] # Generate a list of orderable parts which have stock below their minimum values # TODO - Is there a less expensive way to get these from the database - context['to_order'] = [part for part in Part.objects.filter(purchaseable=True) if part.need_to_restock()] + # context['to_order'] = [part for part in Part.objects.filter(purchaseable=True) if part.need_to_restock()] # Generate a list of assembly parts which have stock below their minimum values # TODO - Is there a less expensive way to get these from the database - context['to_build'] = [part for part in Part.objects.filter(assembly=True) if part.need_to_restock()] + # context['to_build'] = [part for part in Part.objects.filter(assembly=True) if part.need_to_restock()] return context diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 6615b4df43..e36d4a568b 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -301,7 +301,9 @@ class PartList(generics.ListCreateAPIView): return Response(data) def get_queryset(self): - + """ + Implement custom filtering for the Part list API + """ # Start with all objects parts_list = Part.objects.all() diff --git a/InvenTree/templates/InvenTree/index.html b/InvenTree/templates/InvenTree/index.html index c4eb5990cc..570378e55d 100644 --- a/InvenTree/templates/InvenTree/index.html +++ b/InvenTree/templates/InvenTree/index.html @@ -9,13 +9,7 @@ InvenTree | Index
{% include "InvenTree/starred_parts.html" with collapse_id="starred" %} -{% if to_order %} -{% include "InvenTree/parts_to_order.html" with collapse_id="order" %} -{% endif %} - -{% if to_build %} -{% include "InvenTree/parts_to_build.html" with collapse_id="build" %} -{% endif %} +{% include "InvenTree/low_stock.html" with collapse_id="order" %} {% endblock %} @@ -25,15 +19,31 @@ InvenTree | Index {% block js_ready %} -console.log("abcde?"); - {{ block.super }} -//TODO: These calls to bootstrapTable() are failing, for some reason? -//$("#to-build-table").bootstrapTable(); -//$("#to-order-table").bootstrapTable(); -//$("#starred-parts-table").bootstrapTable(); +loadPartTable("#starred-parts-table", "{% url 'api-part-list' %}", { + params: { + "starred": true, + } +}); + +loadPartTable("#low-stock-table", "{% url 'api-part-list' %}", { + params: { + "low_stock": true, + } +}); + +$("#starred-parts-table").on('load-success.bs.table', function() { + var count = $("#starred-parts-table").bootstrapTable('getData').length; + + $("#starred-parts-count").html(count); +}); + +$("#low-stock-table").on('load-success.bs.table', function() { + var count = $("#low-stock-table").bootstrapTable('getData').length; + + $("#low-stock-count").html(count); +}); -console.log("Got to here..."); {% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/low_stock.html b/InvenTree/templates/InvenTree/low_stock.html new file mode 100644 index 0000000000..edafab1756 --- /dev/null +++ b/InvenTree/templates/InvenTree/low_stock.html @@ -0,0 +1,15 @@ +{% extends "collapse.html" %} + +{% load i18n %} + +{% block collapse_title %} + +{% trans "Low Stock" %}0 +{% endblock %} + +{% block collapse_content %} + + +
+ +{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/parts_to_order.html b/InvenTree/templates/InvenTree/parts_to_order.html deleted file mode 100644 index 5d2c3472b4..0000000000 --- a/InvenTree/templates/InvenTree/parts_to_order.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "collapse.html" %} -{% block collapse_title %} - -Parts to Order{{ to_order | length }} -{% endblock %} - -{% block collapse_heading %} -There are {{ to_order | length }} parts which need to be ordered. -{% endblock %} - -{% block collapse_content %} - -{% include "required_part_table.html" with parts=to_order table_id="to-order-table" %} - -{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/starred_parts.html b/InvenTree/templates/InvenTree/starred_parts.html index 091afde064..f13987e3c5 100644 --- a/InvenTree/templates/InvenTree/starred_parts.html +++ b/InvenTree/templates/InvenTree/starred_parts.html @@ -1,15 +1,15 @@ {% extends "collapse.html" %} + +{% load i18n %} + {% block collapse_title %} -Starred Parts{{ starred | length }} -{% endblock %} - -{% block collapse_heading %} -You have {{ starred | length }} favourite parts +{% trans "Starred Parts" %}0 {% endblock %} {% block collapse_content %} -{% include "required_part_table.html" with parts=starred table_id="starred-parts-table" %} + +
{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/base.html b/InvenTree/templates/base.html index 3cae9fd37b..8559e6d5f1 100644 --- a/InvenTree/templates/base.html +++ b/InvenTree/templates/base.html @@ -102,6 +102,7 @@ InvenTree +