Skip to content

Commit 27297c7

Browse files
stuntguy3000jeremystretch
authored andcommitted
Add Hide Disconnected Button to Interface Summary, Remove Unused Table Caption Descriptor - Close #12732
1 parent 685ac5f commit 27297c7

File tree

5 files changed

+41
-64
lines changed

5 files changed

+41
-64
lines changed

netbox/dcim/tables/devices.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,19 @@ def get_interface_state_attribute(record):
6464
Get interface enabled state as string to attach to <tr/> DOM element.
6565
"""
6666
if record.enabled:
67-
return "enabled"
67+
return 'enabled'
6868
else:
69-
return "disabled"
69+
return 'disabled'
70+
71+
72+
def get_interface_connected_attribute(record):
73+
"""
74+
Get interface disconnected state as string to attach to <tr/> DOM element.
75+
"""
76+
if record.mark_connected or record.cable:
77+
return 'connected'
78+
else:
79+
return 'disconnected'
7080

7181

7282
#
@@ -674,6 +684,7 @@ class Meta(DeviceComponentTable.Meta):
674684
'data-name': lambda record: record.name,
675685
'data-enabled': get_interface_state_attribute,
676686
'data-type': lambda record: record.type,
687+
'data-connected': get_interface_connected_attribute
677688
}
678689

679690

netbox/project-static/dist/netbox.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/dist/netbox.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/src/tables/interfaceTable.ts

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ class TableState {
141141
private virtualButton: ButtonState;
142142

143143
/**
144-
* Underlying DOM Table Caption Element.
144+
* Instance of ButtonState for the 'show/hide virtual rows' button.
145145
*/
146-
private caption: Nullable<HTMLTableCaptionElement> = null;
146+
// @ts-expect-error null handling is performed in the constructor
147+
private disconnectedButton: ButtonState;
147148

148149
/**
149150
* All table rows in table
@@ -166,9 +167,10 @@ class TableState {
166167
this.table,
167168
'button.toggle-virtual',
168169
);
169-
170-
const caption = this.table.querySelector('caption');
171-
this.caption = caption;
170+
const toggleDisconnectedButton = findFirstAdjacent<HTMLButtonElement>(
171+
this.table,
172+
'button.toggle-disconnected',
173+
);
172174

173175
if (toggleEnabledButton === null) {
174176
throw new TableStateError("Table is missing a 'toggle-enabled' button.", table);
@@ -182,10 +184,15 @@ class TableState {
182184
throw new TableStateError("Table is missing a 'toggle-virtual' button.", table);
183185
}
184186

187+
if (toggleDisconnectedButton === null) {
188+
throw new TableStateError("Table is missing a 'toggle-disconnected' button.", table);
189+
}
190+
185191
// Attach event listeners to the buttons elements.
186192
toggleEnabledButton.addEventListener('click', event => this.handleClick(event, this));
187193
toggleDisabledButton.addEventListener('click', event => this.handleClick(event, this));
188194
toggleVirtualButton.addEventListener('click', event => this.handleClick(event, this));
195+
toggleDisconnectedButton.addEventListener('click', event => this.handleClick(event, this));
189196

190197
// Instantiate ButtonState for each button for state management.
191198
this.enabledButton = new ButtonState(
@@ -200,6 +207,10 @@ class TableState {
200207
toggleVirtualButton,
201208
table.querySelectorAll<HTMLTableRowElement>('tr[data-type="virtual"]'),
202209
);
210+
this.disconnectedButton = new ButtonState(
211+
toggleDisconnectedButton,
212+
table.querySelectorAll<HTMLTableRowElement>('tr[data-connected="disconnected"]'),
213+
);
203214
} catch (err) {
204215
if (err instanceof TableStateError) {
205216
// This class is useless for tables that don't have toggle buttons.
@@ -211,52 +222,6 @@ class TableState {
211222
}
212223
}
213224

214-
/**
215-
* Get the table caption's text.
216-
*/
217-
private get captionText(): string {
218-
if (this.caption !== null) {
219-
return this.caption.innerText;
220-
}
221-
return '';
222-
}
223-
224-
/**
225-
* Set the table caption's text.
226-
*/
227-
private set captionText(value: string) {
228-
if (this.caption !== null) {
229-
this.caption.innerText = value;
230-
}
231-
}
232-
233-
/**
234-
* Update the table caption's text based on the state of each toggle button.
235-
*/
236-
private toggleCaption(): void {
237-
const showEnabled = this.enabledButton.buttonState === 'show';
238-
const showDisabled = this.disabledButton.buttonState === 'show';
239-
const showVirtual = this.virtualButton.buttonState === 'show';
240-
241-
if (showEnabled && !showDisabled && !showVirtual) {
242-
this.captionText = 'Showing Enabled Interfaces';
243-
} else if (showEnabled && showDisabled && !showVirtual) {
244-
this.captionText = 'Showing Enabled & Disabled Interfaces';
245-
} else if (!showEnabled && showDisabled && !showVirtual) {
246-
this.captionText = 'Showing Disabled Interfaces';
247-
} else if (!showEnabled && !showDisabled && !showVirtual) {
248-
this.captionText = 'Hiding Enabled, Disabled & Virtual Interfaces';
249-
} else if (!showEnabled && !showDisabled && showVirtual) {
250-
this.captionText = 'Showing Virtual Interfaces';
251-
} else if (showEnabled && !showDisabled && showVirtual) {
252-
this.captionText = 'Showing Enabled & Virtual Interfaces';
253-
} else if (showEnabled && showDisabled && showVirtual) {
254-
this.captionText = 'Showing Enabled, Disabled & Virtual Interfaces';
255-
} else {
256-
this.captionText = '';
257-
}
258-
}
259-
260225
/**
261226
* When toggle buttons are clicked, reapply visability all rows and
262227
* pass the event to all button handlers
@@ -272,7 +237,7 @@ class TableState {
272237
instance.enabledButton.handleClick(event);
273238
instance.disabledButton.handleClick(event);
274239
instance.virtualButton.handleClick(event);
275-
instance.toggleCaption();
240+
instance.disconnectedButton.handleClick(event);
276241
}
277242
}
278243

netbox/templates/dcim/device/inc/interface_table_controls.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<button type="button" class="dropdown-item toggle-enabled" data-state="show">{% trans "Hide Enabled" %}</button>
1010
<button type="button" class="dropdown-item toggle-disabled" data-state="show">{% trans "Hide Disabled" %}</button>
1111
<button type="button" class="dropdown-item toggle-virtual" data-state="show">{% trans "Hide Virtual" %}</button>
12+
<button type="button" class="dropdown-item toggle-disconnected" data-state="show">{% trans "Hide Disconnected" %}</button>
1213
</ul>
1314
{% endblock extra_table_controls %}

0 commit comments

Comments
 (0)