gluon-config-mode-domain-select: allow hiding of individual domain codes

This commit is contained in:
Martin Weinelt 2018-03-13 18:56:11 +01:00
parent d66ff7b087
commit 1000c92c84
No known key found for this signature in database
GPG Key ID: BD4AA0528F63F17E
3 changed files with 21 additions and 1 deletions

View File

@ -1 +1,2 @@
need_boolean(in_domain({'hide_domain'}), false) need_boolean(in_domain({'hide_domain'}), false)
need_array_of(in_domain({'hide_domain_codes'}), table_keys(need_table(in_domain({'domain_names'}), nil, true)), false)

View File

@ -9,12 +9,23 @@ return function(form, uci)
local configured = uci:get_first('gluon-setup-mode','setup_mode', 'configured') == '1' or (selected_domain ~= site.default_domain()) local configured = uci:get_first('gluon-setup-mode','setup_mode', 'configured') == '1' or (selected_domain ~= site.default_domain())
local function get_domain_list() local function get_domain_list()
local function hidden_domain_code(domain, code)
if domain.hide_domain_codes ~= nil then
for _, hidden_code in ipairs(domain.hide_domain_codes) do
if code == hidden_code then
return true
end
end
end
return false
end
local list = {} local list = {}
for domain_path in fs.glob('/lib/gluon/domains/*.json') do for domain_path in fs.glob('/lib/gluon/domains/*.json') do
local domain_code = domain_path:match('([^/]+)%.json$') local domain_code = domain_path:match('([^/]+)%.json$')
local domain = assert(json.load(domain_path)) local domain = assert(json.load(domain_path))
if not domain.hide_domain or (configured and domain.domain_code == selected_domain) then if (not domain.hide_domain and not hidden_domain_code(domain, domain_code)) or (configured and domain.domain_code == selected_domain) then
table.insert(list, { table.insert(list, {
domain_code = domain_code, domain_code = domain_code,
domain_name = domain.domain_names[domain_code], domain_name = domain.domain_names[domain_code],

View File

@ -71,6 +71,14 @@ local function array_to_string(array)
return '[' .. table.concat(array, ', ') .. ']' return '[' .. table.concat(array, ', ') .. ']'
end end
function table_keys(tbl)
local keys = {}
for k, _ in pairs(tbl) do
keys[#keys + 1] = k
end
return keys
end
local loadpath local loadpath