Removed UCI Save/Apply cache from Essentials

Made CBI controllers configurable
This commit is contained in:
Steven Barth 2008-10-31 09:35:53 +00:00
parent 023880275f
commit a5c6e56adf
15 changed files with 20 additions and 210 deletions

View file

@ -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

View 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({"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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -14,7 +14,9 @@ $Id$
-%>
<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>

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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%>

View file

@ -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%>

View file

@ -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%>