From e1d1f522ff07c573979eb494c02c9befb07cd202 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Fri, 3 Jan 2020 19:38:51 +0000 Subject: [PATCH 1/7] Closes #3090: Filter field for interface --- docs/release-notes/version-2.6.md | 6 ++++++ netbox/templates/dcim/device.html | 19 +++++++++++++++++++ .../virtualization/virtualmachine.html | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 2bf55d857..c4589a009 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -1,3 +1,9 @@ +# v2.6.12 (FUTURE) + +## Enhancements + +* [#3090](https://github.com/netbox-community/netbox/issues/3090) - Add filter field for device interfaces + # v2.6.11 (2020-01-03) ## Bug Fixes diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 57e2b03b8..55332ca80 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -556,6 +556,9 @@ Show IPs +
+ +
@@ -912,6 +915,22 @@ $('button.toggle-ips').click(function() { $(this).children('span').toggleClass('glyphicon-check glyphicon-unchecked'); return false; }); +$('input.interface-filter').on('input', function() { + var filter = new RegExp(this.value); + + for (interface of $(this).closest('form').find('tbody > tr')) { + // Slice off 'interface_' at the start of the ID + if (filter && filter.test(interface.id.slice(10))) { + // Match the toggle in case the filter now matches the interface + $(interface).find('input:checkbox[name=pk]').prop('checked', $('input.toggle').prop('checked')); + $(interface).show(); + } else { + // Uncheck to prevent actions from including it when it doesn't match + $(interface).find('input:checkbox[name=pk]').prop('checked', false); + $(interface).hide(); + } + } +}); diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index 2498039ff..736d6bc5c 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -253,6 +253,9 @@ Show IPs +
+ +
@@ -325,5 +328,21 @@ $('button.toggle-ips').click(function() { $(this).children('span').toggleClass('glyphicon-check glyphicon-unchecked'); return false; }); +$('input.interface-filter').on('input', function() { + var filter = new RegExp(this.value); + + for (interface of $(this).closest('form').find('tbody > tr')) { + // Slice off 'interface_' at the start of the ID + if (filter && filter.test(interface.id.slice(10))) { + // Match the toggle in case the filter now matches the interface + $(interface).find('input:checkbox[name=pk]').prop('checked', $('input.toggle').prop('checked')); + $(interface).show(); + } else { + // Uncheck to prevent actions from including it when it doesn't match + $(interface).find('input:checkbox[name=pk]').prop('checked', false); + $(interface).hide(); + } + } +}); {% endblock %} From 3556051d14b71de5785339976b1a992d8c2c115d Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Fri, 3 Jan 2020 19:58:41 +0000 Subject: [PATCH 2/7] Height was a touch off --- netbox/templates/dcim/device.html | 2 +- netbox/templates/virtualization/virtualmachine.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 55332ca80..3b3beb3e0 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -557,7 +557,7 @@
- +
diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index 736d6bc5c..298daf94f 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -254,7 +254,7 @@
- +
From 28eca9a02606e4ee11dde3b6b157ca20c5dc2396 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Fri, 3 Jan 2020 20:12:21 +0000 Subject: [PATCH 3/7] Forgot le seperator --- docs/release-notes/version-2.6.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index c4589a009..c099d5115 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -4,6 +4,8 @@ * [#3090](https://github.com/netbox-community/netbox/issues/3090) - Add filter field for device interfaces +--- + # v2.6.11 (2020-01-03) ## Bug Fixes From 07a1baef13e0a4251f7aa28db4a4ce40a5193b16 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Mon, 6 Jan 2020 20:05:07 +0000 Subject: [PATCH 4/7] Limit toggle selector to visible input fields --- netbox/project-static/js/forms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/project-static/js/forms.js b/netbox/project-static/js/forms.js index 55f9afbd5..20d6c9126 100644 --- a/netbox/project-static/js/forms.js +++ b/netbox/project-static/js/forms.js @@ -7,7 +7,7 @@ $(document).ready(function() { // "Toggle" checkbox for object lists (PK column) $('input:checkbox.toggle').click(function() { - $(this).closest('table').find('input:checkbox[name=pk]').prop('checked', $(this).prop('checked')); + $(this).closest('table').find('input:checkbox[name=pk]:visible').prop('checked', $(this).prop('checked')); // Show the "select all" box if present if ($(this).is(':checked')) { From a7ec0c14f75fd201efb7c408d40aaed78aea94a3 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Mon, 6 Jan 2020 20:18:44 +0000 Subject: [PATCH 5/7] Move toggles js code to static --- netbox/project-static/js/interface_toggles.js | 30 +++++++++++++++++ netbox/templates/dcim/device.html | 29 +---------------- .../virtualization/virtualmachine.html | 32 ++----------------- 3 files changed, 33 insertions(+), 58 deletions(-) create mode 100644 netbox/project-static/js/interface_toggles.js diff --git a/netbox/project-static/js/interface_toggles.js b/netbox/project-static/js/interface_toggles.js new file mode 100644 index 000000000..a3649558a --- /dev/null +++ b/netbox/project-static/js/interface_toggles.js @@ -0,0 +1,30 @@ +// Toggle the display of IP addresses under interfaces +$('button.toggle-ips').click(function() { + var selected = $(this).attr('selected'); + if (selected) { + $('#interfaces_table tr.ipaddresses').hide(); + } else { + $('#interfaces_table tr.ipaddresses').show(); + } + $(this).attr('selected', !selected); + $(this).children('span').toggleClass('glyphicon-check glyphicon-unchecked'); + return false; +}); + +// Inteface filtering +$('input.interface-filter').on('input', function() { + var filter = new RegExp(this.value); + + for (interface of $(this).closest('form').find('tbody > tr')) { + // Slice off 'interface_' at the start of the ID + if (filter && filter.test(interface.id.slice(10))) { + // Match the toggle in case the filter now matches the interface + $(interface).find('input:checkbox[name=pk]').prop('checked', $('input.toggle').prop('checked')); + $(interface).show(); + } else { + // Uncheck to prevent actions from including it when it doesn't match + $(interface).find('input:checkbox[name=pk]').prop('checked', false); + $(interface).hide(); + } + } +}); diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 3b3beb3e0..f88838028 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -903,35 +903,8 @@ function toggleConnection(elem) { $(".cable-toggle").click(function() { return toggleConnection($(this)); }); -// Toggle the display of IP addresses under interfaces -$('button.toggle-ips').click(function() { - var selected = $(this).attr('selected'); - if (selected) { - $('#interfaces_table tr.ipaddresses').hide(); - } else { - $('#interfaces_table tr.ipaddresses').show(); - } - $(this).attr('selected', !selected); - $(this).children('span').toggleClass('glyphicon-check glyphicon-unchecked'); - return false; -}); -$('input.interface-filter').on('input', function() { - var filter = new RegExp(this.value); - - for (interface of $(this).closest('form').find('tbody > tr')) { - // Slice off 'interface_' at the start of the ID - if (filter && filter.test(interface.id.slice(10))) { - // Match the toggle in case the filter now matches the interface - $(interface).find('input:checkbox[name=pk]').prop('checked', $('input.toggle').prop('checked')); - $(interface).show(); - } else { - // Uncheck to prevent actions from including it when it doesn't match - $(interface).find('input:checkbox[name=pk]').prop('checked', false); - $(interface).hide(); - } - } -}); + {% endblock %} diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index 298daf94f..6477c71ad 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -1,5 +1,6 @@ {% extends '_base.html' %} {% load custom_links %} +{% load static %} {% load helpers %} {% block header %} @@ -315,34 +316,5 @@ {% endblock %} {% block javascript %} - + {% endblock %} From 6a3cd83efcecc21a157cca164a7913852158597d Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Mon, 6 Jan 2020 23:33:18 +0000 Subject: [PATCH 6/7] Moved regex note to tooltip --- netbox/project-static/js/forms.js | 6 +++--- netbox/templates/dcim/device.html | 2 +- netbox/templates/virtualization/virtualmachine.html | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/netbox/project-static/js/forms.js b/netbox/project-static/js/forms.js index 0b8c7d719..b7dbb1cfa 100644 --- a/netbox/project-static/js/forms.js +++ b/netbox/project-static/js/forms.js @@ -400,8 +400,8 @@ $(document).ready(function() { window.addEventListener('hashchange', headerOffsetScroll); // Offset between the preview window and the window edges - const IMAGE_PREVIEW_OFFSET_X = 20 - const IMAGE_PREVIEW_OFFSET_Y = 10 + const IMAGE_PREVIEW_OFFSET_X = 20; + const IMAGE_PREVIEW_OFFSET_Y = 10; // Preview an image attachment when the link is hovered over $('a.image-preview').on('mouseover', function(e) { @@ -435,6 +435,6 @@ $(document).ready(function() { // Fade the image out; it will be deleted when another one is previewed $('a.image-preview').on('mouseout', function() { - $('#image-preview-window').fadeOut('fast') + $('#image-preview-window').fadeOut('fast'); }); }); diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index f88838028..74d469a12 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -557,7 +557,7 @@
- +
diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index 6477c71ad..5e73935d0 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -255,7 +255,7 @@
- +
From 996d49de670159d62b6ca82c76830901b3f702c2 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Wed, 8 Jan 2020 10:49:58 +0000 Subject: [PATCH 7/7] Fixes #3440: Total cable trace length --- docs/release-notes/version-2.6.md | 1 + netbox/dcim/models.py | 2 ++ netbox/dcim/views.py | 5 ++++- netbox/templates/dcim/cable_trace.html | 5 ++++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index f3ff8798a..86bdc44c7 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -4,6 +4,7 @@ * [#2050](https://github.com/netbox-community/netbox/issues/2050) - Preview image attachments when hovering the link * [#3187](https://github.com/netbox-community/netbox/issues/3187) - Add rack selection field to rack elevations +* [#3440](https://github.com/netbox-community/netbox/issues/3440) - Add total length to cable trace ## Bug Fixes diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 8f95fa19a..2c7105a80 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -2950,6 +2950,8 @@ class Cable(ChangeLoggedModel): # Store the given length (if any) in meters for use in database ordering if self.length and self.length_unit: self._abs_length = to_meters(self.length, self.length_unit) + else: + self._abs_length = None # Store the parent Device for the A and B terminations (if applicable) to enable filtering if hasattr(self.termination_a, 'device'): diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 2d98515cf..55a08fdb8 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -1754,10 +1754,13 @@ class CableTraceView(PermissionRequiredMixin, View): def get(self, request, model, pk): obj = get_object_or_404(model, pk=pk) + trace = obj.trace(follow_circuits=True) + total_length = sum([entry[1]._abs_length for entry in trace if entry[1] and entry[1]._abs_length]) return render(request, 'dcim/cable_trace.html', { 'obj': obj, - 'trace': obj.trace(follow_circuits=True), + 'trace': trace, + 'total_length': total_length, }) diff --git a/netbox/templates/dcim/cable_trace.html b/netbox/templates/dcim/cable_trace.html index c9da88c46..4dd145058 100644 --- a/netbox/templates/dcim/cable_trace.html +++ b/netbox/templates/dcim/cable_trace.html @@ -10,7 +10,10 @@

Near End

-
+
+ {% if total_length %}
Total length: {{ total_length|floatformat:"-2" }} Meters
{% endif %} +
+

Far End