From 946b42e2346b03fc174e3c3bc49fe4dc282a9085 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Tue, 13 Mar 2018 18:56:11 +0100 Subject: [PATCH] gluon-config-mode-domain-select: allow hiding of individual domain codes --- .../gluon-config-mode-domain-select/check_site.lua | 8 +++++++- .../config-mode/wizard/0200-domain-select.lua | 14 +++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/package/gluon-config-mode-domain-select/check_site.lua b/package/gluon-config-mode-domain-select/check_site.lua index 18994ecd..6a6fd47b 100644 --- a/package/gluon-config-mode-domain-select/check_site.lua +++ b/package/gluon-config-mode-domain-select/check_site.lua @@ -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) diff --git a/package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua b/package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua index 8046e006..9496e99f 100644 --- a/package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua +++ b/package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua @@ -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],