mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Convert device device bays list to table
This commit is contained in:
parent
2146c38748
commit
7c1316619b
@ -11,8 +11,9 @@ from utilities.tables import (
|
|||||||
TagColumn, ToggleColumn,
|
TagColumn, ToggleColumn,
|
||||||
)
|
)
|
||||||
from .template_code import (
|
from .template_code import (
|
||||||
CABLETERMINATION, CONSOLEPORT_BUTTONS, CONSOLESERVERPORT_BUTTONS, DEVICE_LINK, FRONTPORT_BUTTONS, INTERFACE_BUTTONS,
|
CABLETERMINATION, CONSOLEPORT_BUTTONS, CONSOLESERVERPORT_BUTTONS, DEVICE_LINK, DEVICEBAY_BUTTONS, FRONTPORT_BUTTONS,
|
||||||
INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS, POWEROUTLET_BUTTONS, POWERPORT_BUTTONS, REARPORT_BUTTONS,
|
INTERFACE_BUTTONS, INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS, POWEROUTLET_BUTTONS, POWERPORT_BUTTONS,
|
||||||
|
REARPORT_BUTTONS,
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -21,6 +22,7 @@ __all__ = (
|
|||||||
'DeviceBayTable',
|
'DeviceBayTable',
|
||||||
'DeviceConsolePortTable',
|
'DeviceConsolePortTable',
|
||||||
'DeviceConsoleServerPortTable',
|
'DeviceConsoleServerPortTable',
|
||||||
|
'DeviceDeviceBayTable',
|
||||||
'DeviceFrontPortTable',
|
'DeviceFrontPortTable',
|
||||||
'DeviceImportTable',
|
'DeviceImportTable',
|
||||||
'DeviceInterfaceTable',
|
'DeviceInterfaceTable',
|
||||||
@ -464,7 +466,7 @@ class DeviceFrontPortTable(FrontPortTable):
|
|||||||
model = FrontPort
|
model = FrontPort
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'cable', 'cable_peer',
|
'pk', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'cable', 'cable_peer',
|
||||||
'connection', 'tags', 'actions',
|
'tags', 'actions',
|
||||||
)
|
)
|
||||||
default_columns = (
|
default_columns = (
|
||||||
'pk', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'cable', 'cable_peer',
|
'pk', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'cable', 'cable_peer',
|
||||||
@ -500,8 +502,7 @@ class DeviceRearPortTable(RearPortTable):
|
|||||||
class Meta(DeviceComponentTable.Meta):
|
class Meta(DeviceComponentTable.Meta):
|
||||||
model = RearPort
|
model = RearPort
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'name', 'label', 'type', 'positions', 'description', 'cable', 'cable_peer', 'connection', 'tags',
|
'pk', 'name', 'label', 'type', 'positions', 'description', 'cable', 'cable_peer', 'tags', 'actions',
|
||||||
'actions',
|
|
||||||
)
|
)
|
||||||
default_columns = (
|
default_columns = (
|
||||||
'pk', 'name', 'label', 'type', 'positions', 'description', 'cable', 'cable_peer', 'actions',
|
'pk', 'name', 'label', 'type', 'positions', 'description', 'cable', 'cable_peer', 'actions',
|
||||||
@ -525,6 +526,27 @@ class DeviceBayTable(DeviceComponentTable):
|
|||||||
default_columns = ('pk', 'device', 'name', 'label', 'installed_device', 'description')
|
default_columns = ('pk', 'device', 'name', 'label', 'installed_device', 'description')
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceDeviceBayTable(DeviceBayTable):
|
||||||
|
name = tables.TemplateColumn(
|
||||||
|
template_code='<i class="fa fa-square{% if record.installed_device %}dot-circle-o{% else %}circle-o{% endif %}'
|
||||||
|
'"></i> <a href="{{ record.get_absolute_url }}">{{ value }}</a>'
|
||||||
|
)
|
||||||
|
actions = ButtonsColumn(
|
||||||
|
model=DeviceBay,
|
||||||
|
buttons=('edit', 'delete'),
|
||||||
|
prepend_template=DEVICEBAY_BUTTONS
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta(DeviceComponentTable.Meta):
|
||||||
|
model = DeviceBay
|
||||||
|
fields = (
|
||||||
|
'pk', 'name', 'label', 'installed_device', 'description', 'tags', 'actions',
|
||||||
|
)
|
||||||
|
default_columns = (
|
||||||
|
'pk', 'name', 'label', 'installed_device', 'description', 'actions',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class InventoryItemTable(DeviceComponentTable):
|
class InventoryItemTable(DeviceComponentTable):
|
||||||
manufacturer = tables.Column(
|
manufacturer = tables.Column(
|
||||||
linkify=True
|
linkify=True
|
||||||
|
@ -200,3 +200,17 @@ REARPORT_BUTTONS = """
|
|||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
DEVICEBAY_BUTTONS = """
|
||||||
|
{% if perms.dcim.change_devicebay %}
|
||||||
|
{% if record.installed_device %}
|
||||||
|
<a href="{% url 'dcim:devicebay_depopulate' pk=record.pk %}" class="btn btn-danger btn-xs">
|
||||||
|
<i class="glyphicon glyphicon-remove" aria-hidden="true" title="Remove device"></i>
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url 'dcim:devicebay_populate' pk=record.pk %}" class="btn btn-success btn-xs">
|
||||||
|
<i class="glyphicon glyphicon-plus" aria-hidden="true" title="Install device"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
"""
|
||||||
|
@ -1078,6 +1078,9 @@ class DeviceView(ObjectView):
|
|||||||
devicebays = DeviceBay.objects.restrict(request.user, 'view').filter(device=device).prefetch_related(
|
devicebays = DeviceBay.objects.restrict(request.user, 'view').filter(device=device).prefetch_related(
|
||||||
'installed_device__device_type__manufacturer',
|
'installed_device__device_type__manufacturer',
|
||||||
)
|
)
|
||||||
|
devicebay_table = tables.DeviceDeviceBayTable(devicebays, orderable=False)
|
||||||
|
if request.user.has_perm('dcim.change_devicebay') or request.user.has_perm('dcim.delete_devicebay'):
|
||||||
|
devicebay_table.columns.show('pk')
|
||||||
|
|
||||||
# Inventory items
|
# Inventory items
|
||||||
inventoryitems = InventoryItem.objects.restrict(request.user, 'view').filter(
|
inventoryitems = InventoryItem.objects.restrict(request.user, 'view').filter(
|
||||||
@ -1108,7 +1111,7 @@ class DeviceView(ObjectView):
|
|||||||
'interface_table': interface_table,
|
'interface_table': interface_table,
|
||||||
'frontport_table': frontport_table,
|
'frontport_table': frontport_table,
|
||||||
'rearport_table': rearport_table,
|
'rearport_table': rearport_table,
|
||||||
'devicebays': devicebays,
|
'devicebay_table': devicebay_table,
|
||||||
'inventoryitems': inventoryitems,
|
'inventoryitems': inventoryitems,
|
||||||
'services': services,
|
'services': services,
|
||||||
'secrets': secrets,
|
'secrets': secrets,
|
||||||
|
@ -143,7 +143,7 @@
|
|||||||
<a href="#poweroutlets" role="tab" data-toggle="tab">Power Outlets {% badge poweroutlet_table.rows|length %}</a>
|
<a href="#poweroutlets" role="tab" data-toggle="tab">Power Outlets {% badge poweroutlet_table.rows|length %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<a href="#devicebays" role="tab" data-toggle="tab">Device Bays {% badge devicebays|length %}</a>
|
<a href="#devicebays" role="tab" data-toggle="tab">Device Bays {% badge devicebay_table.rows|length %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<a href="#inventoryitems" role="tab" data-toggle="tab">Inventory {% badge inventoryitems|length %}</a>
|
<a href="#inventoryitems" role="tab" data-toggle="tab">Inventory {% badge inventoryitems|length %}</a>
|
||||||
@ -754,36 +754,14 @@
|
|||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<strong>Device Bays</strong>
|
<strong>Device Bays</strong>
|
||||||
</div>
|
</div>
|
||||||
<table class="table table-hover table-headings panel-body component-list">
|
{% include 'responsive_table.html' with table=devicebay_table %}
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
{% if perms.dcim.change_devicebay or perms.dcim.delete_devicebay %}
|
|
||||||
<th class="pk"><input type="checkbox" class="toggle" title="Toggle all" /></th>
|
|
||||||
{% endif %}
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Status</th>
|
|
||||||
<th>Description</th>
|
|
||||||
<th colspan="2">Installed Device</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for devicebay in devicebays %}
|
|
||||||
{% include 'dcim/inc/devicebay.html' %}
|
|
||||||
{% empty %}
|
|
||||||
<tr>
|
|
||||||
<td colspan="5" class="text-center text-muted">— No device bays defined —</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<div class="panel-footer noprint">
|
<div class="panel-footer noprint">
|
||||||
{% if devicebays and perms.dcim.change_devicebay %}
|
{% if perms.dcim.change_devicebay %}
|
||||||
<button type="submit" name="_rename" formaction="{% url 'dcim:devicebay_bulk_rename' %}?return_url={{ device.get_absolute_url }}" class="btn btn-warning btn-xs">
|
<button type="submit" name="_rename" formaction="{% url 'dcim:devicebay_bulk_rename' %}?return_url={{ device.get_absolute_url }}" class="btn btn-warning btn-xs">
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Rename
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Rename
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if devicebays and perms.dcim.delete_devicebay %}
|
{% if perms.dcim.delete_devicebay %}
|
||||||
<button type="submit" formaction="{% url 'dcim:devicebay_bulk_delete' %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs">
|
<button type="submit" formaction="{% url 'dcim:devicebay_bulk_delete' %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs">
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete selected
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete selected
|
||||||
</button>
|
</button>
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
{% load helpers %}
|
|
||||||
|
|
||||||
<tr class="devicebay">
|
|
||||||
{% if perms.dcim.change_devicebay or perms.dcim.delete_devicebay %}
|
|
||||||
<td class="pk">
|
|
||||||
<input name="pk" type="checkbox" value="{{ devicebay.pk }}" />
|
|
||||||
</td>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{# Name #}
|
|
||||||
<td>
|
|
||||||
<i class="fa fa-fw fa-{% if devicebay.installed_device %}dot-circle-o{% else %}circle-o{% endif %}"></i>
|
|
||||||
<a href="{{ devicebay.get_absolute_url }}">{{ devicebay.name }}</a>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
{# Status #}
|
|
||||||
<td>
|
|
||||||
{% if devicebay.installed_device %}
|
|
||||||
<span class="label label-{{ devicebay.installed_device.get_status_class }}">
|
|
||||||
{{ devicebay.installed_device.get_status_display }}
|
|
||||||
</span>
|
|
||||||
{% else %}
|
|
||||||
<span class="label label-default">Vacant</span>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
{# Description #}
|
|
||||||
<td>
|
|
||||||
{{ devicebay.description|placeholder }}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
{# Installed device #}
|
|
||||||
{% if devicebay.installed_device %}
|
|
||||||
<td>
|
|
||||||
<a href="{% url 'dcim:device' pk=devicebay.installed_device.pk %}">{{ devicebay.installed_device }}</a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<span>{{ devicebay.installed_device.device_type.display_name }}</span>
|
|
||||||
</td>
|
|
||||||
{% else %}
|
|
||||||
<td colspan="2"></td>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<td class="text-right noprint">
|
|
||||||
{% if perms.dcim.change_devicebay %}
|
|
||||||
{% if devicebay.installed_device %}
|
|
||||||
<a href="{% url 'dcim:devicebay_depopulate' pk=devicebay.pk %}" class="btn btn-danger btn-xs">
|
|
||||||
<i class="glyphicon glyphicon-remove" aria-hidden="true" title="Remove device"></i>
|
|
||||||
</a>
|
|
||||||
{% else %}
|
|
||||||
<a href="{% url 'dcim:devicebay_populate' pk=devicebay.pk %}" class="btn btn-success btn-xs">
|
|
||||||
<i class="glyphicon glyphicon-plus" aria-hidden="true" title="Install device"></i>
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
<a href="{% url 'dcim:devicebay_edit' pk=devicebay.pk %}?return_url={{ device.get_absolute_url }}" class="btn btn-info btn-xs">
|
|
||||||
<i class="glyphicon glyphicon-pencil" aria-hidden="true" title="Edit device bay"></i>
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
{% if perms.dcim.delete_devicebay %}
|
|
||||||
{% if devicebay.installed_device %}
|
|
||||||
<button class="btn btn-danger btn-xs" disabled="disabled">
|
|
||||||
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
|
|
||||||
</button>
|
|
||||||
{% else %}
|
|
||||||
<a href="{% url 'dcim:devicebay_delete' pk=devicebay.pk %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs">
|
|
||||||
<i class="glyphicon glyphicon-trash" aria-hidden="true" title="Delete device bay"></i>
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
Loading…
Reference in New Issue
Block a user