mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-23 12:08:43 -06:00
Compare commits
1 Commits
main
...
19869-prov
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a45b6b170d |
@@ -20,9 +20,7 @@ from utilities.forms.fields import (
|
|||||||
DynamicModelChoiceField, DynamicModelMultipleChoiceField, JSONField, NumericArrayField, SlugField,
|
DynamicModelChoiceField, DynamicModelMultipleChoiceField, JSONField, NumericArrayField, SlugField,
|
||||||
)
|
)
|
||||||
from utilities.forms.rendering import FieldSet, InlineFields, TabbedGroups
|
from utilities.forms.rendering import FieldSet, InlineFields, TabbedGroups
|
||||||
from utilities.forms.widgets import (
|
from utilities.forms.widgets import APISelect, ClearableFileInput, HTMXSelect, NumberWithOptions, SelectWithPK
|
||||||
APISelect, ClearableFileInput, ClearableSelect, HTMXSelect, NumberWithOptions, SelectWithPK,
|
|
||||||
)
|
|
||||||
from utilities.jsonschema import JSONSchemaProperty
|
from utilities.jsonschema import JSONSchemaProperty
|
||||||
from virtualization.models import Cluster, VMInterface
|
from virtualization.models import Cluster, VMInterface
|
||||||
from wireless.models import WirelessLAN, WirelessLANGroup
|
from wireless.models import WirelessLAN, WirelessLANGroup
|
||||||
@@ -594,14 +592,6 @@ class DeviceForm(TenancyForm, PrimaryModelForm):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
face = forms.ChoiceField(
|
|
||||||
label=_('Face'),
|
|
||||||
choices=add_blank_choice(DeviceFaceChoices),
|
|
||||||
required=False,
|
|
||||||
widget=ClearableSelect(
|
|
||||||
requires_fields=['rack']
|
|
||||||
)
|
|
||||||
)
|
|
||||||
device_type = DynamicModelChoiceField(
|
device_type = DynamicModelChoiceField(
|
||||||
label=_('Device type'),
|
label=_('Device type'),
|
||||||
queryset=DeviceType.objects.all(),
|
queryset=DeviceType.objects.all(),
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ __all__ = (
|
|||||||
'DeviceTable',
|
'DeviceTable',
|
||||||
'FrontPortTable',
|
'FrontPortTable',
|
||||||
'InterfaceTable',
|
'InterfaceTable',
|
||||||
|
'InterfaceLAGMemberTable',
|
||||||
'InventoryItemRoleTable',
|
'InventoryItemRoleTable',
|
||||||
'InventoryItemTable',
|
'InventoryItemTable',
|
||||||
'MACAddressTable',
|
'MACAddressTable',
|
||||||
@@ -689,6 +690,33 @@ class InterfaceTable(BaseInterfaceTable, ModularDeviceComponentTable, PathEndpoi
|
|||||||
default_columns = ('pk', 'name', 'device', 'label', 'enabled', 'type', 'description')
|
default_columns = ('pk', 'name', 'device', 'label', 'enabled', 'type', 'description')
|
||||||
|
|
||||||
|
|
||||||
|
class InterfaceLAGMemberTable(PathEndpointTable, NetBoxTable):
|
||||||
|
parent = tables.Column(
|
||||||
|
verbose_name=_('Parent'),
|
||||||
|
accessor=Accessor('device'),
|
||||||
|
linkify=True,
|
||||||
|
)
|
||||||
|
name = tables.Column(
|
||||||
|
verbose_name=_('Name'),
|
||||||
|
linkify=True,
|
||||||
|
order_by=('_name',),
|
||||||
|
)
|
||||||
|
connection = columns.TemplateColumn(
|
||||||
|
accessor='connected_endpoints',
|
||||||
|
template_code=INTERFACE_LAG_MEMBERS_LINKTERMINATION,
|
||||||
|
verbose_name=_('Peer'),
|
||||||
|
orderable=False,
|
||||||
|
)
|
||||||
|
tags = columns.TagColumn(
|
||||||
|
url_name='dcim:interface_list'
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta(NetBoxTable.Meta):
|
||||||
|
model = models.Interface
|
||||||
|
fields = ('pk', 'parent', 'name', 'type', 'connection')
|
||||||
|
default_columns = ('pk', 'parent', 'name', 'type', 'connection')
|
||||||
|
|
||||||
|
|
||||||
class DeviceInterfaceTable(InterfaceTable):
|
class DeviceInterfaceTable(InterfaceTable):
|
||||||
name = tables.TemplateColumn(
|
name = tables.TemplateColumn(
|
||||||
verbose_name=_('Name'),
|
verbose_name=_('Name'),
|
||||||
|
|||||||
@@ -24,6 +24,24 @@ INTERFACE_LINKTERMINATION = """
|
|||||||
{% else %}""" + LINKTERMINATION + """{% endif %}
|
{% else %}""" + LINKTERMINATION + """{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
INTERFACE_LAG_MEMBERS_LINKTERMINATION = """
|
||||||
|
{% for termination in value %}
|
||||||
|
{% if termination.parent_object %}
|
||||||
|
<a href="{{ termination.parent_object.get_absolute_url }}">{{ termination.parent_object }}</a>
|
||||||
|
<i class="mdi mdi-chevron-right"></i>
|
||||||
|
{% endif %}
|
||||||
|
<a href="{{ termination.get_absolute_url }}">{{ termination }}</a>
|
||||||
|
{% if termination.lag %}
|
||||||
|
<i class="mdi mdi-chevron-right"></i>
|
||||||
|
<a href="{{ termination.lag.get_absolute_url }}">{{ termination.lag }}</a>
|
||||||
|
<span class="text-muted">(LAG)</span>
|
||||||
|
{% endif %}
|
||||||
|
{% if not forloop.last %}<br />{% endif %}
|
||||||
|
{% empty %}
|
||||||
|
{{ ''|placeholder }}
|
||||||
|
{% endfor %}
|
||||||
|
"""
|
||||||
|
|
||||||
CABLE_LENGTH = """
|
CABLE_LENGTH = """
|
||||||
{% load helpers %}
|
{% load helpers %}
|
||||||
{% if record.length %}{{ record.length|floatformat:"-2" }} {{ record.length_unit }}{% endif %}
|
{% if record.length %}{{ record.length|floatformat:"-2" }} {{ record.length_unit }}{% endif %}
|
||||||
|
|||||||
@@ -3135,6 +3135,14 @@ class InterfaceView(generic.ObjectView):
|
|||||||
)
|
)
|
||||||
child_interfaces_table.configure(request)
|
child_interfaces_table.configure(request)
|
||||||
|
|
||||||
|
# Get LAG interfaces
|
||||||
|
lag_interfaces = Interface.objects.restrict(request.user, 'view').filter(lag=instance)
|
||||||
|
lag_interfaces_table = tables.InterfaceLAGMemberTable(
|
||||||
|
lag_interfaces,
|
||||||
|
orderable=False
|
||||||
|
)
|
||||||
|
lag_interfaces_table.configure(request)
|
||||||
|
|
||||||
# Get assigned VLANs and annotate whether each is tagged or untagged
|
# Get assigned VLANs and annotate whether each is tagged or untagged
|
||||||
vlans = []
|
vlans = []
|
||||||
if instance.untagged_vlan is not None:
|
if instance.untagged_vlan is not None:
|
||||||
@@ -3164,6 +3172,7 @@ class InterfaceView(generic.ObjectView):
|
|||||||
'bridge_interfaces': bridge_interfaces,
|
'bridge_interfaces': bridge_interfaces,
|
||||||
'bridge_interfaces_table': bridge_interfaces_table,
|
'bridge_interfaces_table': bridge_interfaces_table,
|
||||||
'child_interfaces_table': child_interfaces_table,
|
'child_interfaces_table': child_interfaces_table,
|
||||||
|
'lag_interfaces_table': lag_interfaces_table,
|
||||||
'vlan_table': vlan_table,
|
'vlan_table': vlan_table,
|
||||||
'vlan_translation_table': vlan_translation_table,
|
'vlan_translation_table': vlan_translation_table,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ def enqueue_event(queue, instance, request, event_type):
|
|||||||
|
|
||||||
|
|
||||||
def process_event_rules(event_rules, object_type, event_type, data, username=None, snapshots=None, request=None):
|
def process_event_rules(event_rules, object_type, event_type, data, username=None, snapshots=None, request=None):
|
||||||
user = None # To be resolved from the username if needed
|
user = User.objects.get(username=username) if username else None
|
||||||
|
|
||||||
for event_rule in event_rules:
|
for event_rule in event_rules:
|
||||||
|
|
||||||
@@ -134,10 +134,6 @@ def process_event_rules(event_rules, object_type, event_type, data, username=Non
|
|||||||
# Resolve the script from action parameters
|
# Resolve the script from action parameters
|
||||||
script = event_rule.action_object.python_class()
|
script = event_rule.action_object.python_class()
|
||||||
|
|
||||||
# Retrieve the User if not already resolved
|
|
||||||
if user is None:
|
|
||||||
user = User.objects.get(username=username)
|
|
||||||
|
|
||||||
# Enqueue a Job to record the script's execution
|
# Enqueue a Job to record the script's execution
|
||||||
from extras.jobs import ScriptJob
|
from extras.jobs import ScriptJob
|
||||||
params = {
|
params = {
|
||||||
|
|||||||
8
netbox/project-static/dist/netbox.js
vendored
8
netbox/project-static/dist/netbox.js
vendored
File diff suppressed because one or more lines are too long
8
netbox/project-static/dist/netbox.js.map
vendored
8
netbox/project-static/dist/netbox.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -1,40 +0,0 @@
|
|||||||
import TomSelect from 'tom-select';
|
|
||||||
import { getElements } from '../util';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize clear-field dependencies.
|
|
||||||
* When a required field is cleared, dependent fields with data-requires-fields attribute will also be cleared.
|
|
||||||
*/
|
|
||||||
export function initClearField(): void {
|
|
||||||
// Find all fields with data-requires-fields attribute
|
|
||||||
for (const field of getElements<HTMLSelectElement>('[data-requires-fields]')) {
|
|
||||||
const requiredFieldsAttr = field.getAttribute('data-requires-fields');
|
|
||||||
if (!requiredFieldsAttr) continue;
|
|
||||||
|
|
||||||
// Parse the comma-separated list of required field names
|
|
||||||
const requiredFields = requiredFieldsAttr.split(',').map(name => name.trim());
|
|
||||||
|
|
||||||
// Set up listeners for each required field
|
|
||||||
for (const requiredFieldName of requiredFields) {
|
|
||||||
const requiredField = document.querySelector<HTMLSelectElement>(
|
|
||||||
`[name="${requiredFieldName}"]`,
|
|
||||||
);
|
|
||||||
if (!requiredField) continue;
|
|
||||||
|
|
||||||
// Listen for changes on the required field
|
|
||||||
requiredField.addEventListener('change', () => {
|
|
||||||
// If required field is cleared, also clear this dependent field
|
|
||||||
if (!requiredField.value || requiredField.value === '') {
|
|
||||||
// Check if this field uses TomSelect
|
|
||||||
const tomselect = (field as HTMLSelectElement & { tomselect?: TomSelect }).tomselect;
|
|
||||||
if (tomselect) {
|
|
||||||
tomselect.clear();
|
|
||||||
} else {
|
|
||||||
// Regular select field
|
|
||||||
field.value = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
import { initClearField } from './clearField';
|
|
||||||
import { initFormElements } from './elements';
|
import { initFormElements } from './elements';
|
||||||
import { initFilterModifiers } from './filterModifiers';
|
import { initFilterModifiers } from './filterModifiers';
|
||||||
import { initSpeedSelector } from './speedSelector';
|
import { initSpeedSelector } from './speedSelector';
|
||||||
|
|
||||||
export function initForms(): void {
|
export function initForms(): void {
|
||||||
for (const func of [initFormElements, initSpeedSelector, initFilterModifiers, initClearField]) {
|
for (const func of [initFormElements, initSpeedSelector, initFilterModifiers]) {
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,33 +370,6 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if object.is_lag %}
|
|
||||||
<div class="card">
|
|
||||||
<h2 class="card-header">{% trans "LAG Members" %}</h2>
|
|
||||||
<table class="table table-hover">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>{% trans "Parent" %}</th>
|
|
||||||
<th>{% trans "Interface" %}</th>
|
|
||||||
<th>{% trans "Type" %}</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for member in object.member_interfaces.all %}
|
|
||||||
<tr>
|
|
||||||
<td>{{ member.device|linkify }}</td>
|
|
||||||
<td>{{ member|linkify }}</td>
|
|
||||||
<td>{{ member.get_type_display }}</td>
|
|
||||||
</tr>
|
|
||||||
{% empty %}
|
|
||||||
<tr>
|
|
||||||
<td colspan="3" class="text-muted">{% trans "No member interfaces" %}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% include 'ipam/inc/panels/fhrp_groups.html' %}
|
{% include 'ipam/inc/panels/fhrp_groups.html' %}
|
||||||
{% include 'dcim/inc/panels/inventory_items.html' %}
|
{% include 'dcim/inc/panels/inventory_items.html' %}
|
||||||
{% plugin_right_page object %}
|
{% plugin_right_page object %}
|
||||||
@@ -441,6 +414,13 @@
|
|||||||
{% include 'inc/panel_table.html' with table=vlan_table heading="VLANs" %}
|
{% include 'inc/panel_table.html' with table=vlan_table heading="VLANs" %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% if object.is_lag %}
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col col-md-12">
|
||||||
|
{% include 'inc/panel_table.html' with table=lag_interfaces_table heading="LAG Members" %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% if object.vlan_translation_policy %}
|
{% if object.vlan_translation_policy %}
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col col-md-12">
|
<div class="col col-md-12">
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from ..utils import add_blank_choice
|
|||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'BulkEditNullBooleanSelect',
|
'BulkEditNullBooleanSelect',
|
||||||
'ClearableSelect',
|
|
||||||
'ColorSelect',
|
'ColorSelect',
|
||||||
'HTMXSelect',
|
'HTMXSelect',
|
||||||
'SelectWithPK',
|
'SelectWithPK',
|
||||||
@@ -29,21 +28,6 @@ class BulkEditNullBooleanSelect(forms.NullBooleanSelect):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ClearableSelect(forms.Select):
|
|
||||||
"""
|
|
||||||
A Select widget that will be automatically cleared when one or more required fields are cleared.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
requires_fields: A list of field names that this field depends on. When any of these fields
|
|
||||||
are cleared, this field will also be cleared automatically via JavaScript.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, *args, requires_fields=None, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
if requires_fields:
|
|
||||||
self.attrs['data-requires-fields'] = ','.join(requires_fields)
|
|
||||||
|
|
||||||
|
|
||||||
class ColorSelect(forms.Select):
|
class ColorSelect(forms.Select):
|
||||||
"""
|
"""
|
||||||
Extends the built-in Select widget to colorize each <option>.
|
Extends the built-in Select widget to colorize each <option>.
|
||||||
|
|||||||
Reference in New Issue
Block a user