From 3d091912af4130752cdf5f806ed2d605434886fe Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sat, 6 Jun 2020 16:58:00 +0200
Subject: [PATCH] gluon-web-wifi-config: make mesh VIF options depend on
 outdoor=false

Instead of relying on the existence of interface sections only (which is
still used for the case of interface types that are not configured at
all in the site config), add a proper dependency.

This fixes section visiblity with enabled outdoor mode after the following
fix, and gives the user immediate feedback (allowing to disable outdoor
mode and enable meshing in a single step).

(cherry picked from commit d012d7d32fa5235fd260efab64142005f8d36c2f)
---
 .../config-mode/model/admin/wifi-config.lua     | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/package/gluon-web-wifi-config/luasrc/lib/gluon/config-mode/model/admin/wifi-config.lua b/package/gluon-web-wifi-config/luasrc/lib/gluon/config-mode/model/admin/wifi-config.lua
index d8de670ac..98501bd8a 100644
--- a/package/gluon-web-wifi-config/luasrc/lib/gluon/config-mode/model/admin/wifi-config.lua
+++ b/package/gluon-web-wifi-config/luasrc/lib/gluon/config-mode/model/admin/wifi-config.lua
@@ -47,13 +47,18 @@ f:section(Section, nil, translate(
 ))
 
 
+local mesh_vifs_5ghz = {}
+
+
 uci:foreach('wireless', 'wifi-device', function(config)
 	local radio = config['.name']
 
+	local is_5ghz = false
 	local title
 	if config.hwmode == '11g' or config.hwmode == '11ng' then
 		title = translate("2.4GHz WLAN")
 	elseif config.hwmode == '11a' or config.hwmode == '11na' then
+		is_5ghz = true
 		title = translate("5GHz WLAN")
 	else
 		return
@@ -95,10 +100,16 @@ uci:foreach('wireless', 'wifi-device', function(config)
 				uci:set('wireless', interface .. '_' .. radio, 'disabled', not data)
 			end
 		end
+
+		return o
 	end
 
 	vif_option('client', {'client', 'owe'}, translate('Enable client network (access point)'))
-	vif_option('mesh', {'mesh'}, translate("Enable mesh network (802.11s)"))
+
+	local mesh_vif = vif_option('mesh', {'mesh'}, translate("Enable mesh network (802.11s)"))
+	if is_5ghz then
+		table.insert(mesh_vifs_5ghz, mesh_vif)
+	end
 
 	local phy = wireless.find_phy(config)
 	if not phy then
@@ -142,6 +153,10 @@ if has_5ghz_radio() then
 	local outdoor = r:option(Flag, 'outdoor', translate("Node will be installed outdoors"))
 	outdoor.default = uci:get_bool('gluon', 'wireless', 'outdoor')
 
+	for _, mesh_vif in ipairs(mesh_vifs_5ghz) do
+		mesh_vif:depends(outdoor, false)
+	end
+
 	function outdoor:write(data)
 		uci:set('gluon', 'wireless', 'outdoor', data)
 	end
-- 
GitLab