From f405c676e8a254aa009155c5ea46df93806ee95c Mon Sep 17 00:00:00 2001 From: Sophronia Koilpillai Date: Tue, 27 Feb 2024 03:33:22 +0000 Subject: [PATCH] luci-base: force menu to regenerate after uci change Because the menu JSON can have 'depends' in them, uci changes should force the menu to regenerate. Signed-off-by: James Haggerty --- .../luci-base/htdocs/luci-static/resources/uci.js | 2 ++ modules/luci-base/htdocs/luci-static/resources/ui.js | 4 ++++ modules/luci-base/ucode/dispatcher.uc | 12 +++++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/uci.js b/modules/luci-base/htdocs/luci-static/resources/uci.js index 76b274470b19..c56ce4016a24 100644 --- a/modules/luci-base/htdocs/luci-static/resources/uci.js +++ b/modules/luci-base/htdocs/luci-static/resources/uci.js @@ -919,6 +919,8 @@ return baseclass.extend(/** @lends LuCI.uci.prototype */ { window.setTimeout(try_confirm, 250); else return Promise.reject(rv); + } else { + document.dispatchEvent(new CustomEvent('uci-applied')); } return rv; diff --git a/modules/luci-base/htdocs/luci-static/resources/ui.js b/modules/luci-base/htdocs/luci-static/resources/ui.js index 2533f45cec70..0ecb56a9fe44 100644 --- a/modules/luci-base/htdocs/luci-static/resources/ui.js +++ b/modules/luci-base/htdocs/luci-static/resources/ui.js @@ -3516,6 +3516,10 @@ var UITable = baseclass.extend(/** @lends LuCI.ui.table.prototype */ { } }); +// Because the menu can depend on uci values, we need to flush the cache +// after uci mutations. +document.addEventListener('uci-applied', () => UIMenu.flushCache()); + /** * @class ui * @memberof LuCI diff --git a/modules/luci-base/ucode/dispatcher.uc b/modules/luci-base/ucode/dispatcher.uc index 8717385be217..8458372c4dc7 100644 --- a/modules/luci-base/ucode/dispatcher.uc +++ b/modules/luci-base/ucode/dispatcher.uc @@ -358,7 +358,7 @@ function build_pagetree() { firstchild_ineligible: 'bool' }; - let files = glob('/usr/share/luci/menu.d/*.json', '/usr/lib/lua/luci/controller/*.lua', '/usr/lib/lua/luci/controller/*/*.lua'); + let files = glob('/usr/share/luci/menu.d/*.json', '/etc/config/*', '/usr/lib/lua/luci/controller/*.lua', '/usr/lib/lua/luci/controller/*/*.lua'); let cachefile; if (indexcache) { @@ -375,13 +375,15 @@ function build_pagetree() { for (let file in files) { let data; - if (substr(file, -5) == '.json') data = read_jsonfile(file); - else if (load_luabridge(true)) - data = runtime.call('luci.dispatcher', 'process_lua_controller', file); + else if (substr(file, -4) == '.lua') + if (load_luabridge(true)) + data = runtime.call('luci.dispatcher', 'process_lua_controller', file); + else + warn(`Lua controller ${file} present but no Lua runtime installed.\n`); else - warn(`Lua controller ${file} present but no Lua runtime installed.\n`); + continue; if (type(data) == 'object') { for (let path, spec in data) {