mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Convert device console server ports list to table
This commit is contained in:
parent
99352a5d30
commit
60c30b92ba
@ -11,13 +11,15 @@ from utilities.tables import (
|
|||||||
TagColumn, ToggleColumn,
|
TagColumn, ToggleColumn,
|
||||||
)
|
)
|
||||||
from .template_code import (
|
from .template_code import (
|
||||||
CABLETERMINATION, CONSOLEPORT_BUTTONS, DEVICE_LINK, INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS,
|
CABLETERMINATION, CONSOLEPORT_BUTTONS, CONSOLESERVERPORT_BUTTONS, DEVICE_LINK, INTERFACE_IPADDRESSES,
|
||||||
|
INTERFACE_TAGGED_VLANS,
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ConsolePortTable',
|
'ConsolePortTable',
|
||||||
'ConsoleServerPortTable',
|
'ConsoleServerPortTable',
|
||||||
'DeviceConsolePortTable',
|
'DeviceConsolePortTable',
|
||||||
|
'DeviceConsoleServerPortTable',
|
||||||
'DeviceImportTable',
|
'DeviceImportTable',
|
||||||
'DeviceTable',
|
'DeviceTable',
|
||||||
'DeviceBayTable',
|
'DeviceBayTable',
|
||||||
@ -272,6 +274,27 @@ class ConsoleServerPortTable(DeviceComponentTable, PathEndpointTable):
|
|||||||
default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
|
default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceConsoleServerPortTable(ConsoleServerPortTable):
|
||||||
|
name = tables.TemplateColumn(
|
||||||
|
template_code='<i class="fa fa-keyboard-o"></i> <a href="{{ record.get_absolute_url }}">{{ value }}</a>'
|
||||||
|
)
|
||||||
|
actions = ButtonsColumn(
|
||||||
|
model=ConsoleServerPort,
|
||||||
|
buttons=('edit', 'delete'),
|
||||||
|
prepend_template=CONSOLESERVERPORT_BUTTONS
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta(DeviceComponentTable.Meta):
|
||||||
|
model = ConsoleServerPort
|
||||||
|
fields = (
|
||||||
|
'pk', 'name', 'label', 'type', 'description', 'cable', 'cable_peer', 'connection', 'tags', 'actions'
|
||||||
|
)
|
||||||
|
default_columns = ('pk', 'name', 'label', 'type', 'description', 'cable', 'cable_peer', 'actions')
|
||||||
|
row_attrs = {
|
||||||
|
'class': lambda record: record.cable.get_status_class() if record.cable else ''
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class PowerPortTable(DeviceComponentTable, PathEndpointTable):
|
class PowerPortTable(DeviceComponentTable, PathEndpointTable):
|
||||||
tags = TagColumn(
|
tags = TagColumn(
|
||||||
url_name='dcim:powerport_list'
|
url_name='dcim:powerport_list'
|
||||||
|
@ -94,3 +94,20 @@ CONSOLEPORT_BUTTONS = """
|
|||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
CONSOLESERVERPORT_BUTTONS = """
|
||||||
|
{% if record.cable %}
|
||||||
|
{% include 'dcim/inc/cable_toggle_buttons.html' with cable=record.cable %}
|
||||||
|
{% elif perms.dcim.add_cable %}
|
||||||
|
<span class="dropdown">
|
||||||
|
<button type="button" class="btn btn-success btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
<span class="glyphicon glyphicon-resize-small" aria-hidden="true"></span>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-right">
|
||||||
|
<li><a href="{% url 'dcim:consoleserverport_connect' termination_a_id=record.pk termination_b_type='console-port' %}?return_url={{ device.get_absolute_url }}">Console Port</a></li>
|
||||||
|
<li><a href="{% url 'dcim:consoleserverport_connect' termination_a_id=record.pk termination_b_type='front-port' %}?return_url={{ device.get_absolute_url }}">Front Port</a></li>
|
||||||
|
<li><a href="{% url 'dcim:consoleserverport_connect' termination_a_id=record.pk termination_b_type='rear-port' %}?return_url={{ device.get_absolute_url }}">Rear Port</a></li>
|
||||||
|
</ul>
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
"""
|
||||||
|
@ -1029,6 +1029,10 @@ class DeviceView(ObjectView):
|
|||||||
).prefetch_related(
|
).prefetch_related(
|
||||||
'cable', '_path__destination',
|
'cable', '_path__destination',
|
||||||
)
|
)
|
||||||
|
consoleserverport_table = tables.DeviceConsoleServerPortTable(consoleserverports, orderable=False)
|
||||||
|
if request.user.has_perm('dcim.change_consoleserverport') or \
|
||||||
|
request.user.has_perm('dcim.delete_consoleserverport'):
|
||||||
|
consoleserverport_table.columns.show('pk')
|
||||||
|
|
||||||
# Power ports
|
# Power ports
|
||||||
powerports = PowerPort.objects.restrict(request.user, 'view').filter(device=device).prefetch_related(
|
powerports = PowerPort.objects.restrict(request.user, 'view').filter(device=device).prefetch_related(
|
||||||
@ -1083,7 +1087,7 @@ class DeviceView(ObjectView):
|
|||||||
return render(request, 'dcim/device.html', {
|
return render(request, 'dcim/device.html', {
|
||||||
'device': device,
|
'device': device,
|
||||||
'consoleport_table': consoleport_table,
|
'consoleport_table': consoleport_table,
|
||||||
'consoleserverports': consoleserverports,
|
'consoleserverport_table': consoleserverport_table,
|
||||||
'powerports': powerports,
|
'powerports': powerports,
|
||||||
'poweroutlets': poweroutlets,
|
'poweroutlets': poweroutlets,
|
||||||
'interfaces': interfaces,
|
'interfaces': interfaces,
|
||||||
|
@ -134,7 +134,7 @@
|
|||||||
<a href="#consoleports" role="tab" data-toggle="tab">Console Ports {% badge consoleport_table.rows|length %}</a>
|
<a href="#consoleports" role="tab" data-toggle="tab">Console Ports {% badge consoleport_table.rows|length %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<a href="#consoleserverports" role="tab" data-toggle="tab">Console Server Ports {% badge consoleserverports|length %}</a>
|
<a href="#consoleserverports" role="tab" data-toggle="tab">Console Server Ports {% badge consoleserverport_table.rows|length %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<a href="#powerports" role="tab" data-toggle="tab">Power Ports {% badge powerports|length %}</a>
|
<a href="#powerports" role="tab" data-toggle="tab">Power Ports {% badge powerports|length %}</a>
|
||||||
@ -707,29 +707,9 @@
|
|||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<strong>Console Server Ports</strong>
|
<strong>Console Server Ports</strong>
|
||||||
</div>
|
</div>
|
||||||
<table class="table table-hover table-headings panel-body component-list">
|
{% include 'responsive_table.html' with table=consoleserverport_table %}
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
{% if perms.dcim.change_consoleserverport or perms.dcim.delete_consoleserverport %}
|
|
||||||
<th class="pk"><input type="checkbox" class="toggle" title="Toggle all" /></th>
|
|
||||||
{% endif %}
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Type</th>
|
|
||||||
<th>Description</th>
|
|
||||||
<th>Cable</th>
|
|
||||||
<th colspan="2">Cable Termination</th>
|
|
||||||
<th colspan="2">Connection</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for csp in consoleserverports %}
|
|
||||||
{% include 'dcim/inc/consoleserverport.html' %}
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<div class="panel-footer noprint">
|
<div class="panel-footer noprint">
|
||||||
{% if consoleserverports and perms.dcim.change_consoleport %}
|
{% if perms.dcim.change_consoleport %}
|
||||||
<button type="submit" name="_rename" formaction="{% url 'dcim:consoleserverport_bulk_rename' %}?return_url={{ device.get_absolute_url }}" class="btn btn-warning btn-xs">
|
<button type="submit" name="_rename" formaction="{% url 'dcim:consoleserverport_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>
|
||||||
@ -740,7 +720,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 consoleserverports and perms.dcim.delete_consoleserverport %}
|
{% if perms.dcim.delete_consoleserverport %}
|
||||||
<button type="submit" formaction="{% url 'dcim:consoleserverport_bulk_delete' %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs">
|
<button type="submit" formaction="{% url 'dcim:consoleserverport_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>
|
||||||
@ -751,8 +731,8 @@
|
|||||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add console server ports
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add console server ports
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix"></div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,79 +0,0 @@
|
|||||||
{% load helpers %}
|
|
||||||
|
|
||||||
<tr class="consoleserverport{% if csp.cable %} {{ csp.cable.get_status_class }}{% endif %}">
|
|
||||||
|
|
||||||
{# Checkbox #}
|
|
||||||
{% if perms.dcim.change_consoleserverport or perms.dcim.delete_consoleserverport %}
|
|
||||||
<td class="pk">
|
|
||||||
<input name="pk" type="checkbox" value="{{ csp.pk }}" />
|
|
||||||
</td>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{# Name #}
|
|
||||||
<td>
|
|
||||||
<i class="fa fa-fw fa-keyboard-o"></i>
|
|
||||||
<a href="{{ csp.get_absolute_url }}">{{ csp }}</a>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
{# Type #}
|
|
||||||
<td>
|
|
||||||
{% if csp.type %}{{ csp.get_type_display }}{% else %}—{% endif %}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
{# Description #}
|
|
||||||
<td>
|
|
||||||
{{ csp.description|placeholder }}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
{# Cable #}
|
|
||||||
{% if csp.cable %}
|
|
||||||
<td>
|
|
||||||
<a href="{{ csp.cable.get_absolute_url }}">{{ csp.cable }}</a>
|
|
||||||
<a href="{% url 'dcim:consoleserverport_trace' pk=csp.pk %}" class="btn btn-primary btn-xs" title="Trace">
|
|
||||||
<i class="fa fa-share-alt" aria-hidden="true"></i>
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
{% include 'dcim/inc/cabletermination.html' with termination=csp.get_cable_peer %}
|
|
||||||
{% else %}
|
|
||||||
<td colspan="3">
|
|
||||||
<span class="text-muted">Not connected</span>
|
|
||||||
</td>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{# Connection #}
|
|
||||||
{% include 'dcim/inc/endpoint_connection.html' with path=csp.path %}
|
|
||||||
|
|
||||||
{# Actions #}
|
|
||||||
<td class="text-right noprint">
|
|
||||||
{% if csp.cable %}
|
|
||||||
{% include 'dcim/inc/cable_toggle_buttons.html' with cable=csp.cable %}
|
|
||||||
{% elif perms.dcim.add_cable %}
|
|
||||||
<span class="dropdown">
|
|
||||||
<button type="button" class="btn btn-success btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
||||||
<span class="glyphicon glyphicon-resize-small" aria-hidden="true"></span>
|
|
||||||
</button>
|
|
||||||
<ul class="dropdown-menu dropdown-menu-right">
|
|
||||||
<li><a href="{% url 'dcim:consoleserverport_connect' termination_a_id=csp.pk termination_b_type='console-port' %}?return_url={{ device.get_absolute_url }}">Console Port</a></li>
|
|
||||||
<li><a href="{% url 'dcim:consoleserverport_connect' termination_a_id=csp.pk termination_b_type='front-port' %}?return_url={{ device.get_absolute_url }}">Front Port</a></li>
|
|
||||||
<li><a href="{% url 'dcim:consoleserverport_connect' termination_a_id=csp.pk termination_b_type='rear-port' %}?return_url={{ device.get_absolute_url }}">Rear Port</a></li>
|
|
||||||
</ul>
|
|
||||||
</span>
|
|
||||||
{% endif %}
|
|
||||||
{% if perms.dcim.change_consoleserverport %}
|
|
||||||
<a href="{% url 'dcim:consoleserverport_edit' pk=csp.pk %}?return_url={{ device.get_absolute_url }}" title="Edit port" class="btn btn-info btn-xs">
|
|
||||||
<i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
{% if perms.dcim.delete_consoleserverport %}
|
|
||||||
{% if csp.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:consoleserverport_delete' pk=csp.pk %}?return_url={{ device.get_absolute_url }}" title="Delete port" class="btn btn-danger btn-xs">
|
|
||||||
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
Loading…
Reference in New Issue
Block a user