Deduplicate and sort tag names in Advanced DHCP Options selector. (#1078)

* Deduplicate and sort tag names in Advanced DHCP Options selector.

* Only build the deduplicated list of tag names once.

* Build DHCP option tag table more efficiently.
This commit is contained in:
Paul K3PGM 2024-01-22 21:27:12 -05:00 committed by GitHub
parent 29cc59ac9c
commit 35316299c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 9 deletions

View File

@ -1666,18 +1666,30 @@ function print_dhcp_tags()
html.print("</table>")
end
function print_dhcp_tag_selector(row, tag_name)
local field_name = "dhcpopt" .. row .. "_tag"
html.print("<td><select name='" .. field_name .. "' title='Only send this option to clients with this tag'>")
function get_dhcp_tag_names()
local tag_hash = {}
local names = {}
html.print("<option value=''>[any]</option>")
for val = 1,parms.dhcptags_num
do
local name = parms["dhcptag" .. val .. "_name"] or ""
local sel = ""
if name ~= "" and name == tag_name then
sel = "selected "
local name = parms["dhcptag" .. val .. "_name"]
if name and not tag_hash[name] then
tag_hash[name] = 0
table.insert(names, name)
end
end
table.sort(names)
return names
end
function print_dhcp_tag_selector(row, tag_name, all_tags)
local field_name = "dhcpopt" .. row .. "_tag"
html.print("<td><select name='" .. field_name .. "' title='Only send this option to clients with this tag'>")
html.print("<option value=''>[any]</option>")
for _, name in ipairs(all_tags)
do
local sel = name == tag_name and "selected " or ""
html.print("<option " .. sel .. "value=\"" .. name .. "\">" .. name .. "</option>")
end
html.print("</select></td>")
@ -1737,6 +1749,7 @@ function print_dhcp_options()
html.print("<tr><td align=center>For Tag</td><td align=center>Always</td><td align=center>Send DHCP Option</td><td align=center style='width:99%'>With Value</td></tr>")
local known_options = load_known_options()
local all_tags = get_dhcp_tag_names()
local list = make_addable_list(parms.dhcpoptions_num)
for _, val in ipairs(list)
@ -1749,7 +1762,7 @@ function print_dhcp_options()
print_new_entry_vsep(val, list, 5)
html.print("<tr>")
print_dhcp_tag_selector(val, tag)
print_dhcp_tag_selector(val, tag, all_tags)
html.print("<td align=center><input type='checkbox' name='" .. prefix .. "force' value='force' "
.. (force == "force" and "checked " or "")
.. "title='Send option even when not requested by client'/></td>")