diff --git a/netbox/netbox/forms/__init__.py b/netbox/netbox/forms/__init__.py index 14e4d0566..daa5cf904 100644 --- a/netbox/netbox/forms/__init__.py +++ b/netbox/netbox/forms/__init__.py @@ -15,21 +15,10 @@ LOOKUP_CHOICES = ( ) -def build_options(choices): - options = [{"label": choices[0][1], "items": []}] - - for label, choices in choices[1:]: - items = [] - - for value, choice_label in choices: - items.append({"label": choice_label, "value": value}) - - options.append({"label": label, "items": items}) - return options - - class SearchForm(BootstrapMixin, forms.Form): - q = forms.CharField(label='Search') + q = forms.CharField( + label='Search' + ) obj_types = forms.MultipleChoiceField( choices=[], required=False, @@ -43,15 +32,7 @@ class SearchForm(BootstrapMixin, forms.Form): widget=StaticSelect() ) - options = None - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['obj_types'].choices = search_backend.get_object_types() - - def get_options(self): - if not self.options: - self.options = build_options(search_backend.get_object_types()) - - return self.options diff --git a/netbox/project-static/dist/netbox.js b/netbox/project-static/dist/netbox.js index 1213d719f..19cdae0bd 100644 Binary files a/netbox/project-static/dist/netbox.js and b/netbox/project-static/dist/netbox.js differ diff --git a/netbox/project-static/dist/netbox.js.map b/netbox/project-static/dist/netbox.js.map index 90b87a262..d0563b9fc 100644 Binary files a/netbox/project-static/dist/netbox.js.map and b/netbox/project-static/dist/netbox.js.map differ diff --git a/netbox/project-static/src/netbox.ts b/netbox/project-static/src/netbox.ts index d711150ed..f19b879fe 100644 --- a/netbox/project-static/src/netbox.ts +++ b/netbox/project-static/src/netbox.ts @@ -1,6 +1,6 @@ import { initForms } from './forms'; import { initBootstrap } from './bs'; -import { initSearch } from './search'; +import { initQuickSearch } from './search'; import { initSelect } from './select'; import { initButtons } from './buttons'; import { initColorMode } from './colorMode'; @@ -20,7 +20,7 @@ function initDocument(): void { initColorMode, initMessages, initForms, - initSearch, + initQuickSearch, initSelect, initDateSelector, initButtons, diff --git a/netbox/project-static/src/search.ts b/netbox/project-static/src/search.ts index 97fe1826a..e3bdc18dc 100644 --- a/netbox/project-static/src/search.ts +++ b/netbox/project-static/src/search.ts @@ -1,31 +1,4 @@ -import { getElements, findFirstAdjacent, isTruthy } from './util'; - -/** - * Change the display value and hidden input values of the search filter based on dropdown - * selection. - * - * @param event "click" event for each dropdown item. - * @param button Each dropdown item element. - */ -function handleSearchDropdownClick(event: Event, button: HTMLButtonElement): void { - const dropdown = event.currentTarget as HTMLButtonElement; - const selectedValue = findFirstAdjacent(dropdown, 'span.search-obj-selected'); - const selectedType = findFirstAdjacent(dropdown, 'input.search-obj-type'); - const searchValue = dropdown.getAttribute('data-search-value'); - let selected = '' as string; - - if (selectedValue !== null && selectedType !== null) { - if (isTruthy(searchValue) && selected !== searchValue) { - selected = searchValue; - selectedValue.innerHTML = button.textContent ?? 'Error'; - selectedType.value = searchValue; - } else { - selected = ''; - selectedValue.innerHTML = 'All Objects'; - selectedType.value = ''; - } - } -} +import { isTruthy } from './util'; /** * Show/hide quicksearch clear button. @@ -44,23 +17,10 @@ function quickSearchEventHandler(event: Event): void { } } -/** - * Initialize Search Bar Elements. - */ -function initSearchBar(): void { - for (const dropdown of getElements('.search-obj-selector')) { - for (const button of dropdown.querySelectorAll( - 'li > button.dropdown-item', - )) { - button.addEventListener('click', event => handleSearchDropdownClick(event, button)); - } - } -} - /** * Initialize Quicksearch Event listener/handlers. */ -function initQuickSearch(): void { +export function initQuickSearch(): void { const quicksearch = document.getElementById("quicksearch") as HTMLInputElement; const clearbtn = document.getElementById("quicksearch_clear") as HTMLButtonElement; if (isTruthy(quicksearch)) { @@ -82,10 +42,3 @@ function initQuickSearch(): void { } } } - -export function initSearch(): void { - for (const func of [initSearchBar]) { - func(); - } - initQuickSearch(); -} diff --git a/netbox/templates/base/layout.html b/netbox/templates/base/layout.html index dd0412eac..2835e1ef2 100644 --- a/netbox/templates/base/layout.html +++ b/netbox/templates/base/layout.html @@ -1,7 +1,6 @@ {# Base layout for the core NetBox UI w/navbar and page content #} {% extends 'base/base.html' %} {% load helpers %} -{% load search %} {% load static %} {% comment %} @@ -41,7 +40,7 @@ Blocks:
- {% search_options request %} + {% include 'inc/searchbar.html' %}
@@ -53,7 +52,7 @@ Blocks: {# Search bar #}
- {% search_options request %} + {% include 'inc/searchbar.html' %}
{# Proflie/login button #} diff --git a/netbox/templates/inc/searchbar.html b/netbox/templates/inc/searchbar.html new file mode 100644 index 000000000..c8ef0d548 --- /dev/null +++ b/netbox/templates/inc/searchbar.html @@ -0,0 +1,6 @@ +
+ + +
diff --git a/netbox/utilities/templates/search/searchbar.html b/netbox/utilities/templates/search/searchbar.html deleted file mode 100644 index 8005cd47a..000000000 --- a/netbox/utilities/templates/search/searchbar.html +++ /dev/null @@ -1,49 +0,0 @@ -
- - - - - All Objects - - - - - - - -
diff --git a/netbox/utilities/templatetags/search.py b/netbox/utilities/templatetags/search.py deleted file mode 100644 index ca8f3ba2a..000000000 --- a/netbox/utilities/templatetags/search.py +++ /dev/null @@ -1,18 +0,0 @@ -from typing import Dict - -from django import template - -from netbox.forms import SearchForm - -register = template.Library() -search_form = SearchForm() - - -@register.inclusion_tag("search/searchbar.html") -def search_options(request) -> Dict: - - # Provide search options to template. - return { - 'options': search_form.get_options(), - 'request': request, - }