Skip to content

Commit

Permalink
Design change related to issue ArnesSI#100
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholsk18 committed May 6, 2023
1 parent 6d035dd commit 7dd272e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,27 @@ <h5 class="card-header">Asset count by type & status</h5>
<thead>
<tr>
<th>Inventory Item Type</th>
<th>Status</th>
<th>Count</th>
<th>Status - Count</th>
</tr>
</thead>
<tbody>
{% for tsc in type_status_counts %}
{% for tsc in type_status_objects %}
<tr>
{% ifchanged tsc.inventoryitem_type %}
<td>
<a href="{% url 'plugins:netbox_inventory:inventoryitemtype' tsc.inventoryitem_type %}">
{{ tsc.inventoryitem_type__manufacturer__name }} {{ tsc.inventoryitem_type__model }}
</a>
</td>
{% else %}
<td>&nbsp;</td>
{% endifchanged %}
<td>
{% badge value=tsc.label bg_color=tsc.color %}
</td>
<td>
<a href="{% url 'plugins:netbox_inventory:asset_list' %}?inventoryitem_type_id={{ tsc.inventoryitem_type }}&status={{ tsc.status }}">
{{ tsc.count }}
</a>
<td class="d-flex">
{% for status in tsc.status_list %}
<a href="{% url 'plugins:netbox_inventory:asset_list' %}?inventoryitem_type_id={{ tsc.inventoryitem_type }}&status={{ status.status }}" class="w-100 me-2">
{% badge value=status.status|capfirst|add:' - '|add:status.count bg_color=status.color|add:' w-100' %}
</a>
{% endfor %}
</td>
</tr>
{% empty %}
<tr><td class="text-center text-muted" colspan="3">— No assets found —</td></tr>
<tr><td class="text-center text-muted" colspan="2">— No assets found —</td></tr>
{% endfor %}
</tbody>
</table>
Expand Down
30 changes: 30 additions & 0 deletions netbox_inventory/views/inventoryitem_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,35 @@ def get_extra_context(self, request, instance):

# get counts for each inventoryitem type and status combination
type_status_counts = asset_counts_type_status(instance, assets)

# change structure of stored objects
type_status_objects = []
prev_type = 0
asset_obj = {}
for tsc in type_status_counts:
if prev_type != tsc['inventoryitem_type']:
prev_type = tsc['inventoryitem_type']
# make sure skip first insert
if len(asset_obj.keys()) != 0:
type_status_objects.append(asset_obj)
asset_obj = {}

# collection of statuses for same types
status_list = {
'status': tsc['status'],
'count': str(tsc['count']), # needs to be a string to render
'color': tsc['color']
}
if len(asset_obj.keys()) != 0:
asset_obj.get('status_list').append(status_list)
else:
# initial list of assets
asset_obj = {
'inventoryitem_type__manufacturer__name': tsc['inventoryitem_type__manufacturer__name'],
'inventoryitem_type__model': tsc['inventoryitem_type__model'],
'inventoryitem_type': tsc['inventoryitem_type'],
'status_list': [status_list]
}

# counts by status, ignoring different inventoryitem_types
status_counts = asset_counts_status(type_status_counts)
Expand All @@ -58,6 +87,7 @@ def get_extra_context(self, request, instance):
'asset_table': asset_table,
'type_status_counts': type_status_counts,
'status_counts': status_counts,
'type_status_objects': type_status_objects
}


Expand Down

0 comments on commit 7dd272e

Please sign in to comment.