Skip to content

Commit

Permalink
feat(itam): status of device visible on device index page
Browse files Browse the repository at this point in the history
!21
  • Loading branch information
jon-nfc committed Jun 13, 2024
1 parent 7798dea commit e8cb685
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
32 changes: 32 additions & 0 deletions app/itam/models/device.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

from datetime import timedelta

from django.db import models

from access.fields import *
Expand Down Expand Up @@ -86,6 +88,36 @@ def __str__(self):

return self.name

@property
def status(self) -> str:
""" Fetch Device status
Returns:
str: Current status of the item
"""

if self.inventorydate:

check_date = self.inventorydate

else:

check_date = now() + timedelta(days=99)

one = (now() - check_date).days

if (now() - check_date).days >= 0 and (now() - check_date).days <= 1:

return 'OK'

elif (now() - check_date).days >= 2 and (now() - check_date).days < 3:

return 'WARN'

else:

return 'UNK'


def get_configuration(self, id):

Expand Down
75 changes: 74 additions & 1 deletion app/itam/templates/itam/device_index.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,64 @@

{% block content %}

<style>
a.status_icon {
display: inline-block;
height: 30px;
line-height: 30px;
/*background-color: aqua;*/
}
span.status_icon {
/* display: inline-block;*/
height: 30px;
line-height: 30px;
/*background-color: aqua;*/
width: auto;
align-items: center;
/*position: relative;*/
vertical-align: middle; padding: auto; margin: 0px
}
.status_icon_ok svg {
fill: #319c3a;
width: 22px;
height: 22px;
vertical-align: middle;
margin: 0px;
padding: 0px;
border: none;
border-radius: 11px;
/*background-color: #c7e2ca;*/
}
.status_icon_warn svg {
fill: #cf9925;
width: 22px;
height: 22px;
vertical-align: middle;
margin: 0px;
padding: 0px;
border: none;
border-radius: 11px;
/*background-color: #ffefc5;*/
}
.status_icon_ukn svg {
fill: #999;
width: 22px;
height: 22px;
border: none;
border-radius: 11px;
/*background-color: #e9e9e9;*/
}
</style>
<input type="button" value="New Device" onclick="window.location='{% url 'ITAM:_device_add' %}';">
<table class="data">
<tr>
<th style="width: 50px;">&nbsp;</th>
<th>Name</th>
<th>Device Type</th>
<th>Manufacturer</th>
Expand All @@ -17,7 +72,25 @@
</tr>
{% for device in devices %}
<tr>
<td><a href="{% url 'ITAM:_device_view' pk=device.id %}">{{ device.name }}</a></td>
<td>
<span class="status_icon status_icon_ok">
{% if device.status == 'OK' %}
<span class="status_icon status_icon_ok">
{% include 'icons/status_ok.svg' %}
</span>
{% elif device.status == 'WARN' %}
<span class="status_icon status_icon_warn">
{% include 'icons/status_ok.svg' %}
</span>
{% else %}
<span class="status_icon status_icon_ukn">
{% include 'icons/status_unknown.svg' %}
</span>
{% endif %}
</td>
<td>
<a href="{% url 'ITAM:_device_view' pk=device.id %}">{{ device.name }}</a>
</td>
<td>
{% if device.device_type %}
{{ device.device_type }}
Expand Down
1 change: 1 addition & 0 deletions app/templates/icons/status_ok.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/templates/icons/status_unknown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/projects/django-template/itam/device.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ For each device within your inventory, the following fields/tabs are available t
- [Change History](../index.md#history)


### Status at a glance

On the devices list page you can quickly gauge the status of a device. It's a simple colour system: green=OK, Orange=Warning and Grey=Unknown. This status icon denotes the age of the last inventory report, being: within 24-hours, within 48-hours and unknown.


### Details

This tab display the details of the device.
Expand Down

0 comments on commit e8cb685

Please sign in to comment.