From a5c6e56adfde18c3354059b6588bc9937b1c1b8b Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Fri, 31 Oct 2008 09:35:53 +0000 Subject: [PATCH] Removed UCI Save/Apply cache from Essentials Made CBI controllers configurable --- .../luci-ddns/luasrc/controller/ddns.lua | 2 +- .../luasrc/controller/luci_fw/luci_fw.lua | 2 +- .../luci-ntpc/luasrc/controller/ntpc.lua | 2 +- .../luci-qos/luasrc/controller/qos.lua | 2 +- .../luci-upnp/luasrc/controller/upnp.lua | 2 +- libs/cbi/luasrc/cbi.lua | 2 +- libs/cbi/luasrc/view/cbi/footer.htm | 4 +- libs/web/luasrc/dispatcher.lua | 8 +- .../luasrc/controller/mini/index.lua | 3 +- .../luasrc/controller/mini/network.lua | 6 +- .../luasrc/controller/mini/system.lua | 2 +- .../admin-mini/luasrc/controller/mini/uci.lua | 88 ------------------- .../admin-mini/luasrc/view/mini/uci_apply.htm | 39 -------- .../luasrc/view/mini/uci_changes.htm | 39 -------- .../luasrc/view/mini/uci_revert.htm | 29 ------ 15 files changed, 20 insertions(+), 210 deletions(-) delete mode 100644 modules/admin-mini/luasrc/controller/mini/uci.lua delete mode 100644 modules/admin-mini/luasrc/view/mini/uci_apply.htm delete mode 100644 modules/admin-mini/luasrc/view/mini/uci_changes.htm delete mode 100644 modules/admin-mini/luasrc/view/mini/uci_revert.htm diff --git a/applications/luci-ddns/luasrc/controller/ddns.lua b/applications/luci-ddns/luasrc/controller/ddns.lua index f98913655..0adc6abb5 100644 --- a/applications/luci-ddns/luasrc/controller/ddns.lua +++ b/applications/luci-ddns/luasrc/controller/ddns.lua @@ -26,7 +26,7 @@ function index() page.dependent = true - local page = entry({"mini", "network", "ddns"}, cbi("ddns/ddnsmini"), luci.i18n.translate("ddns"), 60) + local page = entry({"mini", "network", "ddns"}, cbi("ddns/ddnsmini", {autoapply=true}), luci.i18n.translate("ddns"), 60) page.i18n = "ddns" page.dependent = true end \ No newline at end of file diff --git a/applications/luci-fw/luasrc/controller/luci_fw/luci_fw.lua b/applications/luci-fw/luasrc/controller/luci_fw/luci_fw.lua index d952b6043..90213cf54 100644 --- a/applications/luci-fw/luasrc/controller/luci_fw/luci_fw.lua +++ b/applications/luci-fw/luasrc/controller/luci_fw/luci_fw.lua @@ -18,7 +18,7 @@ function index() table.insert(nodes, entry({"admin", "network", "firewall", "redirect"}, cbi("luci_fw/rrule"))) nodes[#nodes].leaf = true - table.insert(nodes, entry({"mini", "network", "portfw"}, cbi("luci_fw/miniportfw"), i18n("fw_portfw", "Portweiterleitung"), 70)) + table.insert(nodes, entry({"mini", "network", "portfw"}, cbi("luci_fw/miniportfw", {autoapply=true}), i18n("fw_portfw", "Portweiterleitung"), 70)) for i,n in ipairs(nodes) do n.i18n = "luci-fw" diff --git a/applications/luci-ntpc/luasrc/controller/ntpc.lua b/applications/luci-ntpc/luasrc/controller/ntpc.lua index 5866a241f..8fa690f66 100644 --- a/applications/luci-ntpc/luasrc/controller/ntpc.lua +++ b/applications/luci-ntpc/luasrc/controller/ntpc.lua @@ -26,7 +26,7 @@ function index() page.dependent = true - local page = entry({"mini", "system", "ntpc"}, cbi("ntpc/ntpcmini"), luci.i18n.translate("ntpc"), 50) + local page = entry({"mini", "system", "ntpc"}, cbi("ntpc/ntpcmini", {autoapply=true}), luci.i18n.translate("ntpc"), 50) page.i18n = "ntpc" page.dependent = true end \ No newline at end of file diff --git a/applications/luci-qos/luasrc/controller/qos.lua b/applications/luci-qos/luasrc/controller/qos.lua index 0222806bb..5a9ef5e15 100644 --- a/applications/luci-qos/luasrc/controller/qos.lua +++ b/applications/luci-qos/luasrc/controller/qos.lua @@ -23,7 +23,7 @@ function index() page.dependent = true - local page = entry({"mini", "network", "qos"}, cbi("qos/qosmini"), "QoS") + local page = entry({"mini", "network", "qos"}, cbi("qos/qosmini", {autoapply=true}), "QoS") page.i18n = "qos" page.dependent = true end \ No newline at end of file diff --git a/applications/luci-upnp/luasrc/controller/upnp.lua b/applications/luci-upnp/luasrc/controller/upnp.lua index fe93b9fe9..a7fd66fc1 100644 --- a/applications/luci-upnp/luasrc/controller/upnp.lua +++ b/applications/luci-upnp/luasrc/controller/upnp.lua @@ -24,7 +24,7 @@ function index() page.dependent = true - local page = entry({"mini", "network", "upnp"}, cbi("upnp/upnpmini"), "UPNP") + local page = entry({"mini", "network", "upnp"}, cbi("upnp/upnpmini", {autoapply=true}), "UPNP") page.i18n = "upnp" page.dependent = true end \ No newline at end of file diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua index 94ac96483..316b74f35 100644 --- a/libs/cbi/luasrc/cbi.lua +++ b/libs/cbi/luasrc/cbi.lua @@ -322,7 +322,7 @@ function Map.parse(self) for i, config in ipairs(self.parsechain) do self.uci:save(config) end - if luci.http.formvalue("cbi.apply") then + if self:submitstate() and (self.autoapply or luci.http.formvalue("cbi.apply")) then for i, config in ipairs(self.parsechain) do self.uci:commit(config) diff --git a/libs/cbi/luasrc/view/cbi/footer.htm b/libs/cbi/luasrc/view/cbi/footer.htm index da5926601..6f90bb9cf 100644 --- a/libs/cbi/luasrc/view/cbi/footer.htm +++ b/libs/cbi/luasrc/view/cbi/footer.htm @@ -14,7 +14,9 @@ $Id$ -%>
- + <% if not autoapply then%> + + <% end %> diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index 03e7c7d65..645ea972e 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -499,7 +499,8 @@ end --- Create a CBI model dispatching target. -- @param model CBI model tpo be rendered -function cbi(model) +function cbi(model, config) + config = config or {} return function(...) require("luci.cbi") require("luci.template") @@ -510,6 +511,9 @@ function cbi(model) local state = nil for i, res in ipairs(maps) do + if config.autoapply then + res.autoapply = config.autoapply + end local cstate = res:parse() if not state or cstate < state then state = cstate @@ -521,7 +525,7 @@ function cbi(model) for i, res in ipairs(maps) do res:render() end - luci.template.render("cbi/footer", {state = state}) + luci.template.render("cbi/footer", {state = state, autoapply = config.autoapply}) end end diff --git a/modules/admin-mini/luasrc/controller/mini/index.lua b/modules/admin-mini/luasrc/controller/mini/index.lua index 4813b838e..b538310aa 100644 --- a/modules/admin-mini/luasrc/controller/mini/index.lua +++ b/modules/admin-mini/luasrc/controller/mini/index.lua @@ -31,12 +31,11 @@ function index() page.i18n = "admin-core" page.sysauth = "root" page.sysauth_authenticator = "htmlauth" - page.ucidata = true page.index = true entry({"mini", "index"}, alias("mini", "index", "index"), i18n("overview"), 10).index = true entry({"mini", "index", "index"}, form("mini/index"), i18n("general"), 1).ignoreindex = true - entry({"mini", "index", "luci"}, cbi("mini/luci"), i18n("settings"), 10) + entry({"mini", "index", "luci"}, cbi("mini/luci", {autoapply=true}), i18n("settings"), 10) entry({"mini", "index", "logout"}, call("action_logout"), i18n("logout")) end diff --git a/modules/admin-mini/luasrc/controller/mini/network.lua b/modules/admin-mini/luasrc/controller/mini/network.lua index 56ffc30f2..ab933ccac 100644 --- a/modules/admin-mini/luasrc/controller/mini/network.lua +++ b/modules/admin-mini/luasrc/controller/mini/network.lua @@ -20,7 +20,7 @@ function index() local i18n = luci.i18n.translate entry({"mini", "network"}, alias("mini", "network", "index"), i18n("network"), 20).index = true - entry({"mini", "network", "index"}, cbi("mini/network"), i18n("general"), 1) - entry({"mini", "network", "wifi"}, cbi("mini/wifi"), i18n("wifi"), 10).i18n="wifi" - entry({"mini", "network", "dhcp"}, cbi("mini/dhcp"), "DHCP", 20) + entry({"mini", "network", "index"}, cbi("mini/network", {autoapply=true}), i18n("general"), 1) + entry({"mini", "network", "wifi"}, cbi("mini/wifi", {autoapply=true}), i18n("wifi"), 10).i18n="wifi" + entry({"mini", "network", "dhcp"}, cbi("mini/dhcp", {autoapply=true}), "DHCP", 20) end \ No newline at end of file diff --git a/modules/admin-mini/luasrc/controller/mini/system.lua b/modules/admin-mini/luasrc/controller/mini/system.lua index 9d0ef0c63..936d2634a 100644 --- a/modules/admin-mini/luasrc/controller/mini/system.lua +++ b/modules/admin-mini/luasrc/controller/mini/system.lua @@ -20,7 +20,7 @@ function index() local i18n = luci.i18n.translate entry({"mini", "system"}, alias("mini", "system", "index"), i18n("system"), 40).index = true - entry({"mini", "system", "index"}, cbi("mini/system"), i18n("general"), 1) + entry({"mini", "system", "index"}, cbi("mini/system", {autoapply=true}), i18n("general"), 1) entry({"mini", "system", "passwd"}, form("mini/passwd"), i18n("a_s_changepw"), 10) entry({"mini", "system", "backup"}, call("action_backup"), i18n("a_s_backup"), 80) entry({"mini", "system", "upgrade"}, call("action_upgrade"), i18n("a_s_flash"), 90) diff --git a/modules/admin-mini/luasrc/controller/mini/uci.lua b/modules/admin-mini/luasrc/controller/mini/uci.lua deleted file mode 100644 index 4687c839d..000000000 --- a/modules/admin-mini/luasrc/controller/mini/uci.lua +++ /dev/null @@ -1,88 +0,0 @@ ---[[ -LuCI - Lua Configuration Interface - -Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -$Id$ -]]-- -module("luci.controller.mini.uci", package.seeall) - -function index() - local i18n = luci.i18n.translate - local redir = luci.http.formvalue("redir", true) or - luci.dispatcher.build_url(unpack(luci.dispatcher.context.request)) - - entry({"mini", "uci"}, nil, i18n("config")) - entry({"mini", "uci", "changes"}, call("action_changes"), i18n("changes"), 30).query = {redir=redir} - entry({"mini", "uci", "revert"}, call("action_revert"), i18n("revert"), 20).query = {redir=redir} - entry({"mini", "uci", "saveapply"}, call("action_apply"), i18n("saveapply"), 10).query = {redir=redir} -end - -function convert_changes(changes) - local util = require "luci.util" - - local ret - for r, tbl in pairs(changes) do - for s, os in pairs(tbl) do - for o, v in pairs(os) do - ret = (ret and ret.."\n" or "") .. "%s%s.%s%s%s" % { - v == "" and "-" or "", - r, - s, - o ~= ".type" and "."..o or "", - v ~= "" and "="..util.pcdata(v) or "" - } - end - end - end - return ret -end - -function action_changes() - local changes = convert_changes(luci.model.uci.cursor():changes()) - luci.template.render("mini/uci_changes", {changes=changes}) -end - -function action_apply() - local path = luci.dispatcher.context.path - local uci = luci.model.uci.cursor() - local changes = uci:changes() - local reload = {} - - -- Collect files to be applied and commit changes - for r, tbl in pairs(changes) do - table.insert(reload, r) - uci:load(r) - uci:commit(r) - uci:unload(r) - end - - local function _reload() - local cmd = uci:apply(reload, true) - return io.popen(cmd) - end - - luci.template.render("mini/uci_apply", {changes=convert_changes(changes), reload=_reload}) -end - - -function action_revert() - local uci = luci.model.uci.cursor() - local changes = uci:changes() - - -- Collect files to be reverted - for r, tbl in pairs(changes) do - uci:load(r) - uci:revert(r) - uci:unload(r) - end - - luci.template.render("mini/uci_revert", {changes=convert_changes(changes)}) -end diff --git a/modules/admin-mini/luasrc/view/mini/uci_apply.htm b/modules/admin-mini/luasrc/view/mini/uci_apply.htm deleted file mode 100644 index a908b6a8b..000000000 --- a/modules/admin-mini/luasrc/view/mini/uci_apply.htm +++ /dev/null @@ -1,39 +0,0 @@ -<%# -LuCI - Lua Configuration Interface -Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -$Id$ - --%> -<%+header%> - -

<%:config%>

-

<%:uci_applied%>:

-<%=(changes or "-")%> - -<% -local fp = reload() -local line = fp:read() -while line do - write(line.."\n") - line = fp:read() -end -fp:close() -%> - -<%+footer%> \ No newline at end of file diff --git a/modules/admin-mini/luasrc/view/mini/uci_changes.htm b/modules/admin-mini/luasrc/view/mini/uci_changes.htm deleted file mode 100644 index 89df99dab..000000000 --- a/modules/admin-mini/luasrc/view/mini/uci_changes.htm +++ /dev/null @@ -1,39 +0,0 @@ -<%# -LuCI - Lua Configuration Interface -Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -$Id$ - --%> -<%+header%> - -

<%:config%>

-

<%:changes%>

-<%=changes%> -

-
- -
-
- -
-
- -
- - -<%+footer%> \ No newline at end of file diff --git a/modules/admin-mini/luasrc/view/mini/uci_revert.htm b/modules/admin-mini/luasrc/view/mini/uci_revert.htm deleted file mode 100644 index e8515dc41..000000000 --- a/modules/admin-mini/luasrc/view/mini/uci_revert.htm +++ /dev/null @@ -1,29 +0,0 @@ -<%# -LuCI - Lua Configuration Interface -Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -$Id$ - --%> -<%+header%> - -

<%:config%>

-

<%:uci_reverted%>:

-<%=(changes or "-")%> - -<%+footer%> \ No newline at end of file -- 2.25.1