{% else %}
diff --git a/InvenTree/templates/qr_button.html b/InvenTree/templates/qr_button.html
new file mode 100644
index 0000000000..7aafd834bc
--- /dev/null
+++ b/InvenTree/templates/qr_button.html
@@ -0,0 +1 @@
+
\ No newline at end of file
From fc5fd5e4774ffda41023ad3b96f9de1114f35d90 Mon Sep 17 00:00:00 2001
From: Oliver Walters
Date: Sun, 5 May 2019 11:18:38 +1000
Subject: [PATCH 12/15] Toggle part star status using AJAX
---
.../part/templates/part/part_app_base.html | 7 +++
InvenTree/part/templates/part/part_base.html | 8 +++
InvenTree/static/script/inventree/api.js | 6 +-
InvenTree/static/script/inventree/part.js | 56 +++++++++++++++++++
4 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/InvenTree/part/templates/part/part_app_base.html b/InvenTree/part/templates/part/part_app_base.html
index 30c9b30b6d..8c034dfa6e 100644
--- a/InvenTree/part/templates/part/part_app_base.html
+++ b/InvenTree/part/templates/part/part_app_base.html
@@ -1,5 +1,7 @@
{% extends "base.html" %}
+{% load static %}
+
{% block sidenav %}
{% endblock %}
@@ -14,6 +16,11 @@
{% endblock %}
+{% block js_load %}
+{{ block.super }}
+
+{% endblock %}
+
{% block js_ready %}
{{ block.super }}
loadTree("{% url 'api-part-tree' %}",
diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html
index 0cac700857..44e2d04d7f 100644
--- a/InvenTree/part/templates/part/part_base.html
+++ b/InvenTree/part/templates/part/part_base.html
@@ -105,6 +105,14 @@
);
});
+ $("#toggle-starred").click(function() {
+ toggleStar({
+ part: {{ part.id }},
+ user: {{ user.id }},
+ button: '#part-star-icon'
+ });
+ });
+
$('#toggle-starred').click(function() {
});
diff --git a/InvenTree/static/script/inventree/api.js b/InvenTree/static/script/inventree/api.js
index 530e816f68..27feec8b79 100644
--- a/InvenTree/static/script/inventree/api.js
+++ b/InvenTree/static/script/inventree/api.js
@@ -43,9 +43,6 @@ function inventreeGet(url, filters={}, options={}) {
}
function inventreeUpdate(url, data={}, options={}) {
- if ('final' in options && options.final) {
- data["_is_final"] = true;
- }
var method = options.method || 'PUT';
@@ -63,8 +60,7 @@ function inventreeUpdate(url, data={}, options={}) {
dataType: 'json',
contentType: 'application/json',
success: function(response, status) {
- response['_status_code'] = status;
- console.log('UPDATE object to ' + url + ' - result = ' + status);
+ console.log(method + ' - ' + url + ' : result = ' + status);
if (options.success) {
options.success(response, status);
}
diff --git a/InvenTree/static/script/inventree/part.js b/InvenTree/static/script/inventree/part.js
index 053355113b..7682d5a6c1 100644
--- a/InvenTree/static/script/inventree/part.js
+++ b/InvenTree/static/script/inventree/part.js
@@ -16,4 +16,60 @@ function getPartList(filters={}, options={}) {
function getBomList(filters={}, options={}) {
return inventreeGet('/api/bom/', filters, options);
+}
+
+function toggleStar(options) {
+ /* Toggle the 'starred' status of a part.
+ * Performs AJAX queries and updates the display on the button.
+ *
+ * options:
+ * - button: ID of the button (default = '#part-star-icon')
+ * - part: pk of the part object
+ * - user: pk of the user
+ */
+
+ var url = '/api/part/star/';
+
+ inventreeGet(
+ url,
+ {
+ part: options.part,
+ user: options.user,
+ },
+ {
+ success: function(response) {
+ if (response.length == 0) {
+ // Zero length response = star does not exist
+ // So let's add one!
+ inventreeUpdate(
+ url,
+ {
+ part: options.part,
+ user: options.user,
+ },
+ {
+ method: 'POST',
+ success: function(response, status) {
+ $(options.button).removeClass('glyphicon-star-empty').addClass('glyphicon-star');
+ },
+ }
+ );
+ } else {
+ var pk = response[0].pk;
+ // There IS a star (delete it!)
+ inventreeUpdate(
+ url + pk + "/",
+ {
+ },
+ {
+ method: 'DELETE',
+ success: function(response, status) {
+ $(options.button).removeClass('glyphicon-star').addClass('glyphicon-star-empty');
+ },
+ }
+ );
+ }
+ },
+ }
+ );
}
\ No newline at end of file
From aaff92ff9c429e80261c32ce0700fd208da0db0c Mon Sep 17 00:00:00 2001
From: Oliver Walters
Date: Sun, 5 May 2019 11:21:08 +1000
Subject: [PATCH 13/15] Make the star icon yellow
---
InvenTree/part/templates/part/part_base.html | 2 +-
InvenTree/static/css/inventree.css | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html
index 44e2d04d7f..5dc7add027 100644
--- a/InvenTree/part/templates/part/part_base.html
+++ b/InvenTree/part/templates/part/part_base.html
@@ -29,7 +29,7 @@
{% include "qr_button.html" %}
diff --git a/InvenTree/static/css/inventree.css b/InvenTree/static/css/inventree.css
index e2978f19b4..3a9c1be184 100644
--- a/InvenTree/static/css/inventree.css
+++ b/InvenTree/static/css/inventree.css
@@ -6,6 +6,10 @@
font-size: 20px;
}
+.starred-part {
+ color: #ffcc00;
+}
+
.btn-glyph {
padding-left: 6px;
padding-right: 6px;
From c75d892fd7d521aaad913552854f95375553f074 Mon Sep 17 00:00:00 2001
From: Oliver Walters
Date: Sun, 5 May 2019 11:41:42 +1000
Subject: [PATCH 14/15] Display collapsible list of starred-parts on the index
page
---
InvenTree/InvenTree/views.py | 6 +++++-
InvenTree/templates/InvenTree/index.html | 7 +++++++
InvenTree/templates/InvenTree/parts_to_build.html | 1 +
InvenTree/templates/InvenTree/parts_to_order.html | 1 +
InvenTree/templates/InvenTree/starred_parts.html | 15 +++++++++++++++
5 files changed, 29 insertions(+), 1 deletion(-)
create mode 100644 InvenTree/templates/InvenTree/starred_parts.html
diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py
index 15926715f6..68f6ebb4bd 100644
--- a/InvenTree/InvenTree/views.py
+++ b/InvenTree/InvenTree/views.py
@@ -328,11 +328,15 @@ class IndexView(TemplateView):
def get_context_data(self, **kwargs):
context = super(TemplateView, self).get_context_data(**kwargs)
-
+
+ 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()]
# Generate a list of buildable 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(buildable=True) if part.need_to_restock()]
return context
diff --git a/InvenTree/templates/InvenTree/index.html b/InvenTree/templates/InvenTree/index.html
index 91cac4c18c..12019ca7b0 100644
--- a/InvenTree/templates/InvenTree/index.html
+++ b/InvenTree/templates/InvenTree/index.html
@@ -3,6 +3,8 @@
{% block content %}
InvenTree
+{% include "InvenTree/starred_parts.html" with collapse_id="starred" %}
+
{% if to_order %}
{% include "InvenTree/parts_to_order.html" with collapse_id="order" %}
{% endif %}
@@ -19,4 +21,9 @@
{% block js_ready %}
{{ block.super }}
+
+$("#to-build-table").bootstrapTable();
+$("#to-order-table").bootstrapTable();
+$("#starred-parts-table").bootstrapTable();
+
{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/templates/InvenTree/parts_to_build.html b/InvenTree/templates/InvenTree/parts_to_build.html
index e9c1dcdee1..df9199853b 100644
--- a/InvenTree/templates/InvenTree/parts_to_build.html
+++ b/InvenTree/templates/InvenTree/parts_to_build.html
@@ -1,5 +1,6 @@
{% extends "collapse.html" %}
{% block collapse_title %}
+
Parts to Build{{ to_build | length }}
{% endblock %}
diff --git a/InvenTree/templates/InvenTree/parts_to_order.html b/InvenTree/templates/InvenTree/parts_to_order.html
index b68eda7e14..c9b18606d0 100644
--- a/InvenTree/templates/InvenTree/parts_to_order.html
+++ b/InvenTree/templates/InvenTree/parts_to_order.html
@@ -1,5 +1,6 @@
{% extends "collapse.html" %}
{% block collapse_title %}
+
Parts to Order{{ to_order | length }}
{% endblock %}
diff --git a/InvenTree/templates/InvenTree/starred_parts.html b/InvenTree/templates/InvenTree/starred_parts.html
new file mode 100644
index 0000000000..eebc251666
--- /dev/null
+++ b/InvenTree/templates/InvenTree/starred_parts.html
@@ -0,0 +1,15 @@
+{% extends "collapse.html" %}
+{% block collapse_title %}
+
+Starred Parts{{ starred | length }}
+{% endblock %}
+
+{% block collapse_heading %}
+You have {{ starred | length }} favourite parts
+{% endblock %}
+
+{% block collapse_content %}
+
+{% include "required_part_table.html" with parts=starred table_id="starred-parts-table" %}
+
+{% endblock %}
\ No newline at end of file
From 7987fcc7ccd56d4bded12fbb552b8a05aaca1a0f Mon Sep 17 00:00:00 2001
From: Oliver Walters
Date: Sun, 5 May 2019 11:44:23 +1000
Subject: [PATCH 15/15] PEP fixes
---
InvenTree/InvenTree/views.py | 2 +-
InvenTree/part/api.py | 1 -
InvenTree/part/serializers.py | 2 +-
3 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py
index 68f6ebb4bd..6118f00fd0 100644
--- a/InvenTree/InvenTree/views.py
+++ b/InvenTree/InvenTree/views.py
@@ -329,7 +329,7 @@ class IndexView(TemplateView):
context = super(TemplateView, self).get_context_data(**kwargs)
- context['starred'] = [star.part for star in self.request.user.starred_parts.all()]
+ 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
diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py
index 0ff95e1879..9db2bf102f 100644
--- a/InvenTree/part/api.py
+++ b/InvenTree/part/api.py
@@ -11,7 +11,6 @@ from rest_framework import status
from rest_framework.response import Response
from rest_framework import filters
from rest_framework import generics, permissions
-from rest_framework.serializers import ValidationError
from django.db.models import Q
from django.conf.urls import url, include
diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py
index 48839311e4..847b3bb1a8 100644
--- a/InvenTree/part/serializers.py
+++ b/InvenTree/part/serializers.py
@@ -4,7 +4,7 @@ JSON serializers for Part app
from rest_framework import serializers
-from .models import Part, PartStar, PartAttachment
+from .models import Part, PartStar
from .models import SupplierPart, SupplierPriceBreak
from .models import PartCategory
from .models import BomItem