modules/admin-full: rework changes/apply/revert pages
This commit is contained in:
parent
79674ec6ab
commit
670648ad21
5 changed files with 115 additions and 65 deletions
|
@ -2,6 +2,7 @@
|
||||||
LuCI - Lua Configuration Interface
|
LuCI - Lua Configuration Interface
|
||||||
|
|
||||||
Copyright 2008 Steven Barth <steven@midlink.org>
|
Copyright 2008 Steven Barth <steven@midlink.org>
|
||||||
|
Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -11,13 +12,14 @@ You may obtain a copy of the License at
|
||||||
|
|
||||||
$Id$
|
$Id$
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
module("luci.controller.admin.uci", package.seeall)
|
module("luci.controller.admin.uci", package.seeall)
|
||||||
|
|
||||||
function index()
|
function index()
|
||||||
local i18n = luci.i18n.translate
|
local i18n = luci.i18n.translate
|
||||||
local redir = luci.http.formvalue("redir", true) or
|
local redir = luci.http.formvalue("redir", true) or
|
||||||
luci.dispatcher.build_url(unpack(luci.dispatcher.context.request))
|
luci.dispatcher.build_url(unpack(luci.dispatcher.context.request))
|
||||||
|
|
||||||
entry({"admin", "uci"}, nil, i18n("Configuration"))
|
entry({"admin", "uci"}, nil, i18n("Configuration"))
|
||||||
entry({"admin", "uci", "changes"}, call("action_changes"), i18n("Changes"), 40).query = {redir=redir}
|
entry({"admin", "uci", "changes"}, call("action_changes"), i18n("Changes"), 40).query = {redir=redir}
|
||||||
entry({"admin", "uci", "revert"}, call("action_revert"), i18n("Revert"), 30).query = {redir=redir}
|
entry({"admin", "uci", "revert"}, call("action_revert"), i18n("Revert"), 30).query = {redir=redir}
|
||||||
|
@ -25,29 +27,13 @@ function index()
|
||||||
entry({"admin", "uci", "saveapply"}, call("action_apply"), i18n("Save & Apply"), 10).query = {redir=redir}
|
entry({"admin", "uci", "saveapply"}, call("action_apply"), i18n("Save & Apply"), 10).query = {redir=redir}
|
||||||
end
|
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()
|
function action_changes()
|
||||||
local changes = convert_changes(luci.model.uci.cursor():changes())
|
local uci = luci.model.uci.cursor()
|
||||||
luci.template.render("admin_uci/changes", {changes=changes})
|
local changes = uci:changes()
|
||||||
|
|
||||||
|
luci.template.render("admin_uci/changes", {
|
||||||
|
changes = next(changes) and changes
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function action_apply()
|
function action_apply()
|
||||||
|
@ -65,13 +51,11 @@ function action_apply()
|
||||||
uci:unload(r)
|
uci:unload(r)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function _reload()
|
luci.template.render("admin_uci/apply", {
|
||||||
local cmd = uci:apply(reload, true)
|
changes = next(changes) and changes,
|
||||||
return io.popen(cmd)
|
configs = reload
|
||||||
end
|
})
|
||||||
|
|
||||||
luci.template.render("admin_uci/apply", {changes=convert_changes(changes), reload=_reload})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,6 +69,8 @@ function action_revert()
|
||||||
uci:revert(r)
|
uci:revert(r)
|
||||||
uci:unload(r)
|
uci:unload(r)
|
||||||
end
|
end
|
||||||
|
|
||||||
luci.template.render("admin_uci/revert", {changes=convert_changes(changes)})
|
luci.template.render("admin_uci/revert", {
|
||||||
|
changes = next(changes) and changes
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,31 +12,21 @@ You may obtain a copy of the License at
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
<%+header%>
|
<%+header%>
|
||||||
|
|
||||||
<h2><a id="content" name="content"><%:Configuration%></a></h2>
|
<h2><a id="content" name="content"><%:Configuration / Apply%></a></h2>
|
||||||
<p><strong><%:The following changes have been applied%>:</strong></p>
|
|
||||||
|
|
||||||
<div class="cbi-section">
|
<% if changes then %>
|
||||||
<code><%=(changes or "-")%></code>
|
<%+cbi/apply_xhr%>
|
||||||
</div>
|
<%+admin_uci/changelog%>
|
||||||
|
|
||||||
<fieldset class="cbi-section">
|
<%- cbi_apply_xhr('uci-apply', configs) -%>
|
||||||
<ul class="cbi-apply"><%-
|
|
||||||
local fp = reload()
|
|
||||||
local line = fp:read()
|
|
||||||
while line do
|
|
||||||
write("<li>" .. luci.util.pcdata(line) .. "</li>\n")
|
|
||||||
line = fp:read()
|
|
||||||
end
|
|
||||||
fp:close()
|
|
||||||
-%></ul>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<div class="cbi-page-actions">
|
<p><strong><%:The following changes have been comitted%>:</strong></p>
|
||||||
<form class="inline" method="get" action="<%=luci.util.pcdata(luci.http.formvalue("redir"))%>">
|
<%- uci_changelog(changes) -%>
|
||||||
<input class="cbi-button" style="margin:0" type="submit" value="« <%:back%>" />
|
<% else %>
|
||||||
</form>
|
<p><strong><%:There are no pending changes to apply!%></strong></p>
|
||||||
</div>
|
<% end %>
|
||||||
|
|
||||||
<%+footer%>
|
<%+footer%>
|
||||||
|
|
67
modules/admin-full/luasrc/view/admin_uci/changelog.htm
Normal file
67
modules/admin-full/luasrc/view/admin_uci/changelog.htm
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
<%#
|
||||||
|
LuCI - Lua Configuration Interface
|
||||||
|
Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
|
||||||
|
|
||||||
|
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$
|
||||||
|
|
||||||
|
-%>
|
||||||
|
|
||||||
|
<% export("uci_changelog", function(changes) -%>
|
||||||
|
<fieldset class="cbi-section">
|
||||||
|
<strong><%:Legend:%></strong>
|
||||||
|
<div class="uci-change-legend">
|
||||||
|
<div class="uci-change-legend-label"><ins> </ins> <%:Section added%></div>
|
||||||
|
<div class="uci-change-legend-label"><del> </del> <%:Section removed%></div>
|
||||||
|
<div class="uci-change-legend-label"><var><ins> </ins></var> <%:Option changed%></div>
|
||||||
|
<div class="uci-change-legend-label"><var><del> </del></var> <%:Option removed%></div>
|
||||||
|
<br style="clear:both" />
|
||||||
|
</div>
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<div class="uci-change-list"><%
|
||||||
|
local util = luci.util
|
||||||
|
local ret = { }
|
||||||
|
|
||||||
|
for r, tbl in pairs(changes) do
|
||||||
|
for s, os in pairs(tbl) do
|
||||||
|
-- section add
|
||||||
|
if os['.type'] and os['.type'] ~= "" then
|
||||||
|
ret[#ret+1] = "<ins>%s.%s=<strong>%s</strong>" %{ r, s, os['.type'] }
|
||||||
|
for o, v in util.kspairs(os) do
|
||||||
|
if o:sub(1,1) ~= "." then
|
||||||
|
ret[#ret+1] = "<br />%s.%s.%s=<strong>%s</strong>" %{ r, s, o, util.pcdata(v) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ret[#ret+1] = "</ins><br />"
|
||||||
|
|
||||||
|
-- section delete
|
||||||
|
elseif os['.type'] and os['.type'] == "" then
|
||||||
|
ret[#ret+1] = "<del>%s.<strong>%s</strong></del><br />" %{ r, s }
|
||||||
|
|
||||||
|
-- modifications
|
||||||
|
else
|
||||||
|
ret[#ret+1] = "<var>%s.%s<br />" %{ r, s }
|
||||||
|
for o, v in util.kspairs(os) do
|
||||||
|
if o:sub(1,1) ~= "." then
|
||||||
|
if v and v ~= "" then
|
||||||
|
ret[#ret+1] = "<ins>%s.%s.%s=<strong>%s</strong><br /></ins>" %{ r, s, o, util.pcdata(v) }
|
||||||
|
else
|
||||||
|
ret[#ret+1] = "<del>%s.%s.<strong>%s</strong><br /></del>" %{ r, s, o }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ret[#ret+1] = "</var><br />"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
write(table.concat(ret))
|
||||||
|
%></div>
|
||||||
|
</fieldset>
|
||||||
|
<%- end) %>
|
|
@ -15,17 +15,19 @@ $Id$
|
||||||
|
|
||||||
<%+header%>
|
<%+header%>
|
||||||
|
|
||||||
<h2><a id="content" name="content"><%:Configuration%></a></h2>
|
<h2><a id="content" name="content"><%:Configuration / Changes%></a></h2>
|
||||||
<p><strong><%:Changes%>:</strong></p>
|
|
||||||
|
|
||||||
<div class="cbi-section">
|
<% if changes then %>
|
||||||
<code><%=changes%></code>
|
<%+admin_uci/changelog%>
|
||||||
</div>
|
<%- uci_changelog(changes) -%>
|
||||||
|
<% else %>
|
||||||
|
<p><strong><%:There are no pending changes!%></strong></p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="cbi-page-actions">
|
<div class="cbi-page-actions">
|
||||||
<div style="float:left">
|
<div style="float:left">
|
||||||
<form class="inline" method="get" action="<%=luci.util.pcdata(luci.http.formvalue("redir"))%>">
|
<form class="inline" method="get" action="<%=luci.util.pcdata(luci.http.formvalue("redir"))%>">
|
||||||
<input class="cbi-button" style="float:left; margin:0" type="submit" value="« <%:back%>" />
|
<input class="cbi-button" style="float:left; margin:0" type="submit" value="<%:« Back%>" />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,17 @@ $Id$
|
||||||
|
|
||||||
<%+header%>
|
<%+header%>
|
||||||
|
|
||||||
<h2><a id="content" name="content"><%:Configuration%></a></h2>
|
<h2><a id="content" name="content"><%:Configuration / Revert%></a></h2>
|
||||||
<p><strong><%:The following changes have been reverted%>:</strong></p>
|
|
||||||
|
|
||||||
<div class="cbi-section">
|
<% if changes then %>
|
||||||
<code><%=(changes or "-")%></code>
|
<%+cbi/apply_xhr%>
|
||||||
</div>
|
<%+admin_uci/changelog%>
|
||||||
|
|
||||||
|
<p><strong><%:The following changes have been reverted%>:</strong></p>
|
||||||
|
<%- uci_changelog(changes) -%>
|
||||||
|
<% else %>
|
||||||
|
<p><strong><%:There are no pending changes to revert!%></strong></p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="cbi-page-actions">
|
<div class="cbi-page-actions">
|
||||||
<form class="inline" method="get" action="<%=luci.util.pcdata(luci.http.formvalue("redir"))%>">
|
<form class="inline" method="get" action="<%=luci.util.pcdata(luci.http.formvalue("redir"))%>">
|
||||||
|
|
Loading…
Reference in a new issue