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 committed by Matthias Schiffer
parent 85c0bd6f57
commit 946b42e234
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
2 changed files with 20 additions and 2 deletions

View File

@ -1 +1,7 @@
need_boolean(in_domain({'hide_domain'}), false)
local valid_domain_codes = table_keys(need_table(in_domain({'domain_names'})))
alternatives(function()
need_boolean(in_domain({'hide_domain'}), false)
end, function()
need_array_of(in_domain({'hide_domain'}), valid_domain_codes, false)
end)

View File

@ -1,20 +1,32 @@
return function(form, uci)
local site_i18n = i18n 'gluon-site'
local fs = require 'nixio.fs'
local json = require 'jsonc'
local site = require 'gluon.site'
local util = require 'gluon.util'
local selected_domain = uci:get('gluon', 'core', 'domain')
local configured = uci:get_first('gluon-setup-mode','setup_mode', 'configured') == '1' or (selected_domain ~= site.default_domain())
local function hide_domain_code(domain, code)
if configured and code == selected_domain then
return false
elseif type(domain.hide_domain) == 'table' then
return util.contains(domain.hide_domain, code)
else
return domain.hide_domain
end
end
local function get_domain_list()
local list = {}
for domain_path in fs.glob('/lib/gluon/domains/*.json') do
local domain_code = domain_path:match('([^/]+)%.json$')
local domain = assert(json.load(domain_path))
if not domain.hide_domain or (configured and domain.domain_code == selected_domain) then
if not hide_domain_code(domain, domain_code) then
table.insert(list, {
domain_code = domain_code,
domain_name = domain.domain_names[domain_code],