diff --git a/dashboard/templates/base.html b/dashboard/templates/base.html
index 7b80134..6a26db3 100644
--- a/dashboard/templates/base.html
+++ b/dashboard/templates/base.html
@@ -114,6 +114,19 @@
{% endif %}
+
+
+
+ {% trans 'Device' %}
+
+
+
@@ -148,17 +161,17 @@
- {% trans 'Upload one' %}
+ {% trans 'Upload with JSON file' %}
- {% trans 'Upload Spreadsheet' %}
+ {% trans 'Upload with Spreadsheet' %}
- {% trans 'Create one' %}
+ {% trans 'Upload with Web Form' %}
diff --git a/dashboard/urls.py b/dashboard/urls.py
index 4e27760..cf19b31 100644
--- a/dashboard/urls.py
+++ b/dashboard/urls.py
@@ -5,6 +5,7 @@ app_name = 'dashboard'
urlpatterns = [
path("", views.UnassignedDevicesView.as_view(), name="unassigned"),
+ path("all", views.AllDevicesView.as_view(), name="all_device"),
path("/", views.LotDashboardView.as_view(), name="lot"),
path("search", views.SearchView.as_view(), name="search"),
]
diff --git a/dashboard/views.py b/dashboard/views.py
index 4917bb8..0d9ebff 100644
--- a/dashboard/views.py
+++ b/dashboard/views.py
@@ -22,6 +22,17 @@ class UnassignedDevicesView(InventaryMixin):
return Device.get_unassigned(self.request.user.institution, offset, limit)
+class AllDevicesView(InventaryMixin):
+ template_name = "unassigned_devices.html"
+ section = "All"
+ title = _("All Devices")
+ breadcrumb = "Devices / All Devices"
+
+ def get_devices(self, user, offset, limit):
+ import pdb; pdb.set_trace()
+ return Device.get_all(self.request.user.institution, offset, limit)
+
+
class LotDashboardView(InventaryMixin, DetailsMixin):
template_name = "unassigned_devices.html"
section = "dashboard_lot"
diff --git a/device/models.py b/device/models.py
index a385895..78d2e44 100644
--- a/device/models.py
+++ b/device/models.py
@@ -136,6 +136,87 @@ class Device:
self.lots = [
x.lot for x in DeviceLot.objects.filter(device_id=self.id)]
+ def get_all(cls, institution, offset=0, limit=None):
+ sql = """
+ WITH RankedAnnotations AS (
+ SELECT
+ t1.value,
+ t1.key,
+ ROW_NUMBER() OVER (
+ PARTITION BY t1.uuid
+ ORDER BY
+ CASE
+ WHEN t1.key = 'CUSTOM_ID' THEN 1
+ WHEN t1.key = 'hidalgo1' THEN 2
+ ELSE 3
+ END,
+ t1.created DESC
+ ) AS row_num
+ FROM evidence_annotation AS t1
+ WHERE t1.owner_id = {institution}
+ AND t1.type = {type}
+ )
+ SELECT DISTINCT
+ value
+ FROM
+ RankedAnnotations
+ WHERE
+ row_num = 1
+ """.format(
+ institution=institution.id,
+ type=Annotation.Type.SYSTEM,
+ )
+ if limit:
+ sql += " limit {} offset {}".format(int(limit), int(offset))
+
+ sql += ";"
+
+ annotations = []
+ with connection.cursor() as cursor:
+ cursor.execute(sql)
+ annotations = cursor.fetchall()
+
+ devices = [cls(id=x[0]) for x in annotations]
+ count = cls.get_all_count(institution)
+ return devices, count
+
+ @classmethod
+ def get_all_count(cls, institution):
+
+ sql = """
+ WITH RankedAnnotations AS (
+ SELECT
+ t1.value,
+ t1.key,
+ ROW_NUMBER() OVER (
+ PARTITION BY t1.uuid
+ ORDER BY
+ CASE
+ WHEN t1.key = 'CUSTOM_ID' THEN 1
+ WHEN t1.key = 'hidalgo1' THEN 2
+ ELSE 3
+ END,
+ t1.created DESC
+ ) AS row_num
+ FROM evidence_annotation AS t1
+ WHERE t1.owner_id = {institution}
+ AND t1.type = {type}
+ )
+ SELECT
+ COUNT(DISTINCT value)
+ FROM
+ RankedAnnotations
+ WHERE
+ row_num = 1
+ """.format(
+ institution=institution.id,
+ type=Annotation.Type.SYSTEM,
+ )
+ with connection.cursor() as cursor:
+ cursor.execute(sql)
+ return cursor.fetchall()[0][0]
+
+
@classmethod
def get_unassigned(cls, institution, offset=0, limit=None):