From 124fab3eeedea4b50ffea0d527b249868390e470 Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@gmail.com>
Date: Mon, 13 Apr 2020 21:30:17 +1000
Subject: [PATCH] Display a part as 'starred' in the part table

---
 InvenTree/InvenTree/static/script/inventree/part.js | 4 ++++
 InvenTree/part/api.py                               | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/InvenTree/InvenTree/static/script/inventree/part.js b/InvenTree/InvenTree/static/script/inventree/part.js
index 927afca2e6..05328dbbd8 100644
--- a/InvenTree/InvenTree/static/script/inventree/part.js
+++ b/InvenTree/InvenTree/static/script/inventree/part.js
@@ -147,6 +147,10 @@ function loadPartTable(table, url, options={}) {
                 display += `<span class='fas fa-tools label-right' title='Assembled part'></span>`;
             }
 
+            if (row.starred) {
+                display += `<span class='fas fa-star label-right' title='Starred part'></span>`;
+            }
+
             /*
             if (row.component) {
                 display = display + `<span class='fas fa-cogs label-right' title='Component part'></span>`;
diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py
index 629136af05..6615b4df43 100644
--- a/InvenTree/part/api.py
+++ b/InvenTree/part/api.py
@@ -258,12 +258,18 @@ class PartList(generics.ListCreateAPIView):
                 # Filter items which have an 'in_stock' level higher than 'minimum_stock'
                 data = data.filter(Q(in_stock__gte=F('minimum_stock')))
 
+        # Get a list of the parts that this user has starred
+        starred_parts = [star.part.pk for star in self.request.user.starred_parts.all()]
+
         # Reduce the number of lookups we need to do for the part categories
         categories = {}
 
         for item in data:
 
             if item['image']:
+                # Is this part 'starred' for the current user?
+                item['starred'] = item['pk'] in starred_parts
+
                 img = item['image']
 
                 # Use the 'thumbnail' image here instead of the full-size image