Removed UCI Save/Apply cache from Essentials
authorSteven Barth <steven@midlink.org>
Fri, 31 Oct 2008 09:35:11 +0000 (09:35 +0000)
committerSteven Barth <steven@midlink.org>
Fri, 31 Oct 2008 09:35:11 +0000 (09:35 +0000)
Made CBI controllers configurable

15 files changed:
applications/luci-ddns/luasrc/controller/ddns.lua
applications/luci-fw/luasrc/controller/luci_fw/luci_fw.lua
applications/luci-ntpc/luasrc/controller/ntpc.lua
applications/luci-qos/luasrc/controller/qos.lua
applications/luci-upnp/luasrc/controller/upnp.lua
libs/cbi/luasrc/cbi.lua
libs/cbi/luasrc/view/cbi/footer.htm
libs/web/luasrc/dispatcher.lua
modules/admin-mini/luasrc/controller/mini/index.lua
modules/admin-mini/luasrc/controller/mini/network.lua
modules/admin-mini/luasrc/controller/mini/system.lua
modules/admin-mini/luasrc/controller/mini/uci.lua [deleted file]
modules/admin-mini/luasrc/view/mini/uci_apply.htm [deleted file]
modules/admin-mini/luasrc/view/mini/uci_changes.htm [deleted file]
modules/admin-mini/luasrc/view/mini/uci_revert.htm [deleted file]

index f989136..0adc6ab 100644 (file)
@@ -26,7 +26,7 @@ function index()
        page.dependent = true
        
        
        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
        page.i18n = "ddns"
        page.dependent = true
 end
\ No newline at end of file
index d952b60..90213cf 100644 (file)
@@ -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({"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"
        
        for i,n in ipairs(nodes) do
                n.i18n = "luci-fw"
index 5866a24..8fa690f 100644 (file)
@@ -26,7 +26,7 @@ function index()
        page.dependent = true
        
        
        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
        page.i18n = "ntpc"
        page.dependent = true
 end
\ No newline at end of file
index 0222806..5a9ef5e 100644 (file)
@@ -23,7 +23,7 @@ function index()
        page.dependent = true
        
        
        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
        page.i18n = "qos"
        page.dependent = true
 end
\ No newline at end of file
index fe93b9f..a7fd66f 100644 (file)
@@ -24,7 +24,7 @@ function index()
        page.dependent = true
        
        
        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
        page.i18n = "upnp"
        page.dependent = true
 end
\ No newline at end of file
index 94ac964..316b74f 100644 (file)
@@ -322,7 +322,7 @@ function Map.parse(self)
                for i, config in ipairs(self.parsechain) do
                        self.uci:save(config)
                end
                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)
 
                        for i, config in ipairs(self.parsechain) do
                                self.uci:commit(config)
 
index da59266..6f90bb9 100644 (file)
@@ -14,7 +14,9 @@ $Id$
 -%>
 
        <div class="cbi-page-actions">
 -%>
 
        <div class="cbi-page-actions">
-               <input class="cbi-button cbi-button-apply" type="submit" name="cbi.apply" value="<%:saveapply%>" />
+               <% if not autoapply then%>
+                       <input class="cbi-button cbi-button-apply" type="submit" name="cbi.apply" value="<%:saveapply%>" />
+               <% end %>
                <input class="cbi-button cbi-button-save" type="submit" value="<%:save%>" />
                <input class="cbi-button cbi-button-reset" type="reset" value="<%:reset%>" />
                <script type="text/javascript">cbi_d_update();</script>
                <input class="cbi-button cbi-button-save" type="submit" value="<%:save%>" />
                <input class="cbi-button cbi-button-reset" type="reset" value="<%:reset%>" />
                <script type="text/javascript">cbi_d_update();</script>
index 03e7c7d..645ea97 100644 (file)
@@ -499,7 +499,8 @@ end
 
 --- Create a CBI model dispatching target.
 -- @param      model   CBI model tpo be rendered
 
 --- 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")
        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
                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
                        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
                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
 
        end
 end
 
index 4813b83..b538310 100644 (file)
@@ -31,12 +31,11 @@ function index()
        page.i18n    = "admin-core"
        page.sysauth = "root"
        page.sysauth_authenticator = "htmlauth"
        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
        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
 
        entry({"mini", "index", "logout"}, call("action_logout"), i18n("logout"))
 end
 
index 56ffc30..ab933cc 100644 (file)
@@ -20,7 +20,7 @@ function index()
        local i18n = luci.i18n.translate
 
        entry({"mini", "network"}, alias("mini", "network", "index"), i18n("network"), 20).index = true
        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
 end
\ No newline at end of file
index 9d0ef0c..936d263 100644 (file)
@@ -20,7 +20,7 @@ function index()
        local i18n = luci.i18n.translate
 
        entry({"mini", "system"}, alias("mini", "system", "index"), i18n("system"), 40).index = true
        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)
        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 (file)
index 4687c83..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
---[[
-LuCI - Lua Configuration Interface
-
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-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 (file)
index a908b6a..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<%#
-LuCI - Lua Configuration Interface
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-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%>
-<div>
-<a href="<%=luci.http.formvalue("redir")%>">&lt;&lt; <%:back%></a>
-<br />
-<br />
-</div>
-<h2><a id="content" name="content"><%:config%></a></h2>
-<p><%:uci_applied%>:</p>
-<code><%=(changes or "-")%>
-
-<%
-local fp = reload()
-local line = fp:read()
-while line do 
-       write(line.."\n")
-       line = fp:read()
-end
-fp:close()
-%></code>
-<div>
-<a href="<%=luci.http.formvalue("redir")%>">&lt;&lt; <%:back%></a>
-<br />
-<br />
-</div>
-<%+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 (file)
index 89df99d..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<%#
-LuCI - Lua Configuration Interface
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-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%>
-<div>
-<a href="<%=luci.http.formvalue("redir")%>">&lt;&lt; <%:back%></a>
-<br />
-<br />
-</div>
-<h2><a id="content" name="content"><%:config%></a></h2>
-<h3><%:changes%></h3>
-<code><%=changes%></code>
-<br /><br />
-<form class="inline" method="get" action="<%=controller%>/admin/uci/apply">
-       <input type="submit" value="<%:apply%>" />
-</form>
-<form class="inline" method="get" action="<%=controller%>/admin/uci/saveapply">
-       <input type="submit" value="<%:saveapply%>" />
-</form>
-<form class="inline" method="get" action="<%=controller%>/admin/uci/revert">
-       <input type="submit" value="<%:revert%>" />
-</form>
-
-<div>
-<br />
-<a href="<%=luci.http.formvalue("redir")%>">&lt;&lt; <%:back%></a>
-</div>
-<%+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 (file)
index e8515dc..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<%#
-LuCI - Lua Configuration Interface
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-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%>
-<div>
-<a href="<%=luci.http.formvalue("redir")%>">&lt;&lt; <%:back%></a>
-<br />
-<br />
-</div>
-<h2><a id="content" name="content"><%:config%></a></h2>
-<p><%:uci_reverted%>:</p>
-<code><%=(changes or "-")%></code>
-<div>
-<a href="<%=luci.http.formvalue("redir")%>">&lt;&lt; <%:back%></a>
-<br />
-<br />
-</div>
-<%+footer%>
\ No newline at end of file