1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Convert device power outlets list to table

This commit is contained in:
Jeremy Stretch
2020-10-16 15:16:36 -04:00
parent 3a47e0e2ed
commit eed2e4a15b
5 changed files with 44 additions and 119 deletions

View File

@ -12,7 +12,7 @@ from utilities.tables import (
) )
from .template_code import ( from .template_code import (
CABLETERMINATION, CONSOLEPORT_BUTTONS, CONSOLESERVERPORT_BUTTONS, DEVICE_LINK, INTERFACE_IPADDRESSES, CABLETERMINATION, CONSOLEPORT_BUTTONS, CONSOLESERVERPORT_BUTTONS, DEVICE_LINK, INTERFACE_IPADDRESSES,
INTERFACE_TAGGED_VLANS, POWERPORT_BUTTONS, INTERFACE_TAGGED_VLANS, POWEROUTLET_BUTTONS, POWERPORT_BUTTONS,
) )
__all__ = ( __all__ = (
@ -23,6 +23,7 @@ __all__ = (
'DeviceConsoleServerPortTable', 'DeviceConsoleServerPortTable',
'DeviceImportTable', 'DeviceImportTable',
'DevicePowerPortTable', 'DevicePowerPortTable',
'DevicePowerOutletTable',
'DeviceRoleTable', 'DeviceRoleTable',
'DeviceTable', 'DeviceTable',
'FrontPortTable', 'FrontPortTable',
@ -349,6 +350,30 @@ class PowerOutletTable(DeviceComponentTable, PathEndpointTable):
default_columns = ('pk', 'device', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description') default_columns = ('pk', 'device', 'name', 'label', 'type', 'power_port', 'feed_leg', 'description')
class DevicePowerOutletTable(PowerOutletTable):
name = tables.TemplateColumn(
template_code='<i class="fa fa-bolt"></i> <a href="{{ record.get_absolute_url }}">{{ value }}</a>'
)
actions = ButtonsColumn(
model=PowerOutlet,
buttons=('edit', 'delete'),
prepend_template=POWEROUTLET_BUTTONS
)
class Meta(DeviceComponentTable.Meta):
model = PowerOutlet
fields = (
'pk', 'name', 'label', 'type', 'description', 'power_port', 'feed_leg', 'cable', 'cable_peer', 'connection',
'tags', 'actions',
)
default_columns = (
'pk', 'name', 'label', 'type', 'maximum_draw', 'power_port', 'feed_leg', 'cable', 'cable_peer', 'actions',
)
row_attrs = {
'class': lambda record: record.cable.get_status_class() if record.cable else ''
}
class BaseInterfaceTable(BaseTable): class BaseInterfaceTable(BaseTable):
enabled = BooleanColumn() enabled = BooleanColumn()
ip_addresses = tables.TemplateColumn( ip_addresses = tables.TemplateColumn(

View File

@ -127,3 +127,13 @@ POWERPORT_BUTTONS = """
</span> </span>
{% endif %} {% endif %}
""" """
POWEROUTLET_BUTTONS = """
{% if record.cable %}
{% include 'dcim/inc/cable_toggle_buttons.html' with cable=record.cable %}
{% elif perms.dcim.add_cable %}
<a href="{% url 'dcim:poweroutlet_connect' termination_a_id=record.pk termination_b_type='power-port' %}?return_url={{ device.get_absolute_url }}" title="Connect" class="btn btn-success btn-xs">
<i class="glyphicon glyphicon-resize-small" aria-hidden="true"></i>
</a>
{% endif %}
"""

View File

@ -1046,6 +1046,9 @@ class DeviceView(ObjectView):
poweroutlets = PowerOutlet.objects.restrict(request.user, 'view').filter(device=device).prefetch_related( poweroutlets = PowerOutlet.objects.restrict(request.user, 'view').filter(device=device).prefetch_related(
'cable', 'power_port', '_path__destination', 'cable', 'power_port', '_path__destination',
) )
poweroutlet_table = tables.DevicePowerOutletTable(poweroutlets, orderable=False)
if request.user.has_perm('dcim.change_poweroutlet') or request.user.has_perm('dcim.delete_poweroutlet'):
poweroutlet_table.columns.show('pk')
# Interfaces # Interfaces
interfaces = device.vc_interfaces.restrict(request.user, 'view').prefetch_related( interfaces = device.vc_interfaces.restrict(request.user, 'view').prefetch_related(
@ -1092,7 +1095,7 @@ class DeviceView(ObjectView):
'consoleport_table': consoleport_table, 'consoleport_table': consoleport_table,
'consoleserverport_table': consoleserverport_table, 'consoleserverport_table': consoleserverport_table,
'powerport_table': powerport_table, 'powerport_table': powerport_table,
'poweroutlets': poweroutlets, 'poweroutlet_table': poweroutlet_table,
'interfaces': interfaces, 'interfaces': interfaces,
'frontports': frontports, 'frontports': frontports,
'rearports': rearports, 'rearports': rearports,

View File

@ -140,7 +140,7 @@
<a href="#powerports" role="tab" data-toggle="tab">Power Ports {% badge powerport_table.rows|length %}</a> <a href="#powerports" role="tab" data-toggle="tab">Power Ports {% badge powerport_table.rows|length %}</a>
</li> </li>
<li role="presentation"> <li role="presentation">
<a href="#poweroutlets" role="tab" data-toggle="tab">Power Outlets {% badge poweroutlets|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 devicebays|length %}</a>
@ -780,29 +780,9 @@
<div class="panel-heading"> <div class="panel-heading">
<strong>Power Outlets</strong> <strong>Power Outlets</strong>
</div> </div>
<table class="table table-hover table-headings panel-body component-list"> {% include 'responsive_table.html' with table=poweroutlet_table %}
<thead>
<tr>
{% if perms.dcim.change_poweroutlet or perms.dcim.delete_poweroutlet %}
<th class="pk"><input type="checkbox" class="toggle" title="Toggle all" /></th>
{% endif %}
<th>Name</th>
<th>Type</th>
<th>Input/Leg</th>
<th>Description</th>
<th>Cable</th>
<th colspan="3">Connection</th>
<th></th>
</tr>
</thead>
<tbody>
{% for po in poweroutlets %}
{% include 'dcim/inc/poweroutlet.html' %}
{% endfor %}
</tbody>
</table>
<div class="panel-footer noprint"> <div class="panel-footer noprint">
{% if poweroutlets and perms.dcim.change_powerport %} {% if perms.dcim.change_powerport %}
<button type="submit" name="_rename" formaction="{% url 'dcim:poweroutlet_bulk_rename' %}?return_url={{ device.get_absolute_url }}" class="btn btn-warning btn-xs"> <button type="submit" name="_rename" formaction="{% url 'dcim:poweroutlet_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>
@ -813,7 +793,7 @@
<span class="glyphicon glyphicon-resize-full" aria-hidden="true"></span> Disconnect <span class="glyphicon glyphicon-resize-full" aria-hidden="true"></span> Disconnect
</button> </button>
{% endif %} {% endif %}
{% if poweroutlets and perms.dcim.delete_poweroutlet %} {% if perms.dcim.delete_poweroutlet %}
<button type="submit" formaction="{% url 'dcim:poweroutlet_bulk_delete' %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs"> <button type="submit" formaction="{% url 'dcim:poweroutlet_bulk_delete' %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
</button> </button>

View File

@ -1,93 +0,0 @@
{% load helpers %}
<tr class="poweroutlet{% if po.cable %} {{ po.cable.get_status_class }}{% endif %}">
{# Checkbox #}
{% if perms.dcim.change_poweroutlet or perms.dcim.delete_poweroutlet %}
<td class="pk">
<input name="pk" type="checkbox" value="{{ po.pk }}" />
</td>
{% endif %}
{# Name #}
<td>
<i class="fa fa-fw fa-bolt"></i>
<a href="{{ po.get_absolute_url }}">{{ po }}</a>
</td>
{# Type #}
<td>
{{ po.get_type_display }}
</td>
{# Input/leg #}
<td>
{% if po.power_port %}
{{ po.power_port }}{% if po.feed_leg %} / {{ po.get_feed_leg_display }}{% endif %}
{% elif po.feed_leg %}
{{ po.get_feed_leg_display }}
{% else %}
<span class="text-warning">None</span>
{% endif %}
</td>
{# Description #}
<td>
{{ po.description|placeholder }}
</td>
{# Cable #}
{% if po.cable %}
<td>
<a href="{{ po.cable.get_absolute_url }}">{{ po.cable }}</a>
<a href="{% url 'dcim:poweroutlet_trace' pk=po.pk %}" class="btn btn-primary btn-xs" title="Trace">
<i class="fa fa-share-alt" aria-hidden="true"></i>
</a>
</td>
{% else %}
<td><span class="text-muted">Not connected</span></td>
{% endif %}
{# Connection #}
{% with path=po.path %}
{% include 'dcim/inc/endpoint_connection.html' %}
<td>
{% if paths|length == 1 %}
{% with pp=paths.0.destination %}
{% if pp.allocated_draw %}
{{ pp.allocated_draw }}W{% if pp.maximum_draw %} ({{ pp.maximum_draw }}W max){% endif %}
{% elif pp.maximum_draw %}
{{ pp.maximum_draw }}W
{% endif %}
{% endwith %}
{% endif %}
</td>
{% endwith %}
{# Actions #}
<td class="text-right noprint">
{% if po.cable %}
{% include 'dcim/inc/cable_toggle_buttons.html' with cable=po.cable %}
{% elif perms.dcim.add_cable %}
<a href="{% url 'dcim:poweroutlet_connect' termination_a_id=po.pk termination_b_type='power-port' %}?return_url={{ device.get_absolute_url }}" title="Connect" class="btn btn-success btn-xs">
<i class="glyphicon glyphicon-resize-small" aria-hidden="true"></i>
</a>
{% endif %}
{% if perms.dcim.change_poweroutlet %}
<a href="{% url 'dcim:poweroutlet_edit' pk=po.pk %}?return_url={{ device.get_absolute_url }}" title="Edit outlet" class="btn btn-info btn-xs">
<i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
</a>
{% endif %}
{% if perms.dcim.delete_poweroutlet %}
{% if po.connected_endpoint %}
<button class="btn btn-danger btn-xs" disabled="disabled">
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
</button>
{% else %}
<a href="{% url 'dcim:poweroutlet_delete' pk=po.pk %}?return_url={{ device.get_absolute_url }}" title="Delete outlet" class="btn btn-danger btn-xs">
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
</a>
{% endif %}
{% endif %}
</td>
</tr>