Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order of list entries #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions openwisp-config/files/lib/openwisp/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,20 @@ function utils.write_uci_option(cursor, config, name, key, value)
end
-- avoid duplicate list settings
if type(value) == 'table' then
-- create set with unique values
local set = {}
-- read existing value
local current = cursor:get(config, name, key)
if type(current) == 'table' then
set = utils.add_values_to_set(set, current)
end
set = utils.add_values_to_set(set, value)
-- reset value var with set contents
value = {}
for item_value, present in pairs(set) do
table.insert(value, item_value)
for k_new, v_new in pairs(value) do
found = false
for k_old, v_old in pairs(current) do
if v_new == v_old then
found = true
end
end
if found == false then
table.insert(current, v_new)
end
end
value = current
end
end
cursor:set(config, name, key, value)
Expand Down