firewall/filter: Use fetch_options from opnsense_ui.js to build interface_select selectpicker (#8493)

* firewall/filter: Use fetch_options from opnsense_ui.js to build interface_select selectpicker

* Update src/opnsense/mvc/app/controllers/OPNsense/Firewall/Api/FilterController.php

Co-authored-by: Franco Fichtner <franco@opnsense.org>

---------

Co-authored-by: Franco Fichtner <franco@opnsense.org>
This commit is contained in:
Monviech 2025-03-27 11:23:35 +01:00 committed by GitHub
parent d73ec9feae
commit 92881adb40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 33 deletions

View File

@ -342,7 +342,8 @@ class FilterController extends FilterBaseController
'items' => [
[
'value' => '',
'label' => gettext('Any')
'label' => gettext('Any'),
'selected' => true,
]
]
],

View File

@ -500,38 +500,8 @@
});
// Populate interface selectpicker
$('#interface_select').fetch_options('/api/firewall/filter/get_interface_list');
$("#interface_select_container").show();
ajaxCall('/api/firewall/filter/get_interface_list', {},
function(data, status) {
const $select = $('#interface_select');
$select.empty();
for (const [groupkey, group] of Object.entries(data)) {
if (group.items.length > 0) {
let $optgroup = $('<optgroup>', {
"label": `${group.label}`,
"data-icon": `${group.icon}`
});
group.items.forEach(function(iface) {
let optprops = {
value: iface.value,
'data-subtext': group.label,
text: iface.label
};
if (iface.value === '') {
/* floating selected by default */
optprops['selected'] = 'selected';
}
$optgroup.append($('<option>', optprops));
});
$select.append($optgroup);
}
}
$select.selectpicker('refresh');
},
function(xhr, textStatus, errorThrown) {
console.error("Failed to load interface list:", textStatus, errorThrown);
}
);
// move selectpickers into action bar
$("#interface_select_container").detach().insertBefore('#{{formGridFilterRule["table_id"]}}-header > .row > .actionBar > .search');

View File

@ -672,7 +672,8 @@ $.fn.fetch_options = function(url, params, data_callback, store_data) {
$('<option>', {
value: item.value,
text: item.label,
'data-subtext': group.label
'data-subtext': group.label,
selected: item.selected ? 'selected' : undefined
})
);
}