add all devices view
This commit is contained in:
parent
a2d1080a75
commit
9b701d9804
|
@ -114,6 +114,19 @@
|
|||
</ul>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="nav-item">
|
||||
<a class="admin {% if path in 'all_device' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_device" aria-expanded="false" aria-controls="ul_lots" href="javascript:void()">
|
||||
<i class="bi bi-database icon_sidebar"></i>
|
||||
{% trans 'Device' %}
|
||||
</a>
|
||||
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if path in 'all_device' %}expanded{% else %}collapse{% endif %}" id="ul_device" data-bs-parent="#sidebarMenu">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'all_device' %} active2{% endif %}" href="{% url 'dashboard:all_device' %}">
|
||||
{% trans 'All' %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="admin {% if path == 'tags' or path == 'lot' or path in 'unassigned dashboard' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_lots" aria-expanded="false" aria-controls="ul_lots" href="javascript:void()">
|
||||
<i class="bi bi-database icon_sidebar"></i>
|
||||
|
@ -148,17 +161,17 @@
|
|||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'upload' %} active2{% endif %}" href="{% url 'evidence:upload' %}">
|
||||
{% trans 'Upload one' %}
|
||||
{% trans 'Upload with JSON file' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'import' %} active2{% endif %}" href="{% url 'evidence:import' %}">
|
||||
{% trans 'Upload Spreadsheet' %}
|
||||
{% trans 'Upload with Spreadsheet' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'add' %} active2{% endif %}" href="{% url 'device:add' %}">
|
||||
{% trans 'Create one' %}
|
||||
{% trans 'Upload with Web Form' %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -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("<int:pk>/", views.LotDashboardView.as_view(), name="lot"),
|
||||
path("search", views.SearchView.as_view(), name="search"),
|
||||
]
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
Loading…
Reference in a new issue