From 670648ad214ed26e74b25801e04f1430662de470 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 15 Oct 2010 21:53:28 +0000 Subject: [PATCH] modules/admin-full: rework changes/apply/revert pages --- .../luasrc/controller/admin/uci.lua | 52 ++++++-------- .../luasrc/view/admin_uci/apply.htm | 38 ++++------- .../luasrc/view/admin_uci/changelog.htm | 67 +++++++++++++++++++ .../luasrc/view/admin_uci/changes.htm | 14 ++-- .../luasrc/view/admin_uci/revert.htm | 15 +++-- 5 files changed, 118 insertions(+), 68 deletions(-) create mode 100644 modules/admin-full/luasrc/view/admin_uci/changelog.htm diff --git a/modules/admin-full/luasrc/controller/admin/uci.lua b/modules/admin-full/luasrc/controller/admin/uci.lua index 09b773121..51320a089 100644 --- a/modules/admin-full/luasrc/controller/admin/uci.lua +++ b/modules/admin-full/luasrc/controller/admin/uci.lua @@ -2,6 +2,7 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth +Copyright 2010 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. @@ -11,13 +12,14 @@ You may obtain a copy of the License at $Id$ ]]-- + module("luci.controller.admin.uci", package.seeall) function index() 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)) - + entry({"admin", "uci"}, nil, i18n("Configuration")) 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} @@ -25,29 +27,13 @@ function index() entry({"admin", "uci", "saveapply"}, call("action_apply"), i18n("Save & Apply"), 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("admin_uci/changes", {changes=changes}) + local uci = luci.model.uci.cursor() + local changes = uci:changes() + + luci.template.render("admin_uci/changes", { + changes = next(changes) and changes + }) end function action_apply() @@ -65,13 +51,11 @@ function action_apply() uci:unload(r) end end - - local function _reload() - local cmd = uci:apply(reload, true) - return io.popen(cmd) - end - - luci.template.render("admin_uci/apply", {changes=convert_changes(changes), reload=_reload}) + + luci.template.render("admin_uci/apply", { + changes = next(changes) and changes, + configs = reload + }) end @@ -85,6 +69,8 @@ function action_revert() uci:revert(r) uci:unload(r) end - - luci.template.render("admin_uci/revert", {changes=convert_changes(changes)}) + + luci.template.render("admin_uci/revert", { + changes = next(changes) and changes + }) end diff --git a/modules/admin-full/luasrc/view/admin_uci/apply.htm b/modules/admin-full/luasrc/view/admin_uci/apply.htm index e9de29a91..a9fbbfe9e 100644 --- a/modules/admin-full/luasrc/view/admin_uci/apply.htm +++ b/modules/admin-full/luasrc/view/admin_uci/apply.htm @@ -12,31 +12,21 @@ You may obtain a copy of the License at $Id$ -%> + <%+header%> -

<%:Configuration%>

-

<%:The following changes have been applied%>:

- -
- <%=(changes or "-")%> -
- -
-
    <%- - local fp = reload() - local line = fp:read() - while line do - write("
  • " .. luci.util.pcdata(line) .. "
  • \n") - line = fp:read() - end - fp:close() - -%>
-
- -
-
"> - -
-
+

<%:Configuration / Apply%>

+ +<% if changes then %> + <%+cbi/apply_xhr%> + <%+admin_uci/changelog%> + + <%- cbi_apply_xhr('uci-apply', configs) -%> + +

<%:The following changes have been comitted%>:

+ <%- uci_changelog(changes) -%> +<% else %> +

<%:There are no pending changes to apply!%>

+<% end %> <%+footer%> diff --git a/modules/admin-full/luasrc/view/admin_uci/changelog.htm b/modules/admin-full/luasrc/view/admin_uci/changelog.htm new file mode 100644 index 000000000..13bbdffcb --- /dev/null +++ b/modules/admin-full/luasrc/view/admin_uci/changelog.htm @@ -0,0 +1,67 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2010 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$ + +-%> + +<% export("uci_changelog", function(changes) -%> +
+ <%:Legend:%> +
+
  <%:Section added%>
+
  <%:Section removed%>
+
  <%:Option changed%>
+
  <%:Option removed%>
+
+
+
+ +
<% + 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] = "%s.%s=%s" %{ r, s, os['.type'] } + for o, v in util.kspairs(os) do + if o:sub(1,1) ~= "." then + ret[#ret+1] = "
%s.%s.%s=%s" %{ r, s, o, util.pcdata(v) } + end + end + ret[#ret+1] = "

" + + -- section delete + elseif os['.type'] and os['.type'] == "" then + ret[#ret+1] = "%s.%s
" %{ r, s } + + -- modifications + else + ret[#ret+1] = "%s.%s
" %{ r, s } + for o, v in util.kspairs(os) do + if o:sub(1,1) ~= "." then + if v and v ~= "" then + ret[#ret+1] = "%s.%s.%s=%s
" %{ r, s, o, util.pcdata(v) } + else + ret[#ret+1] = "%s.%s.%s
" %{ r, s, o } + end + end + end + ret[#ret+1] = "

" + end + end + end + + write(table.concat(ret)) + %>
+
+<%- end) %> diff --git a/modules/admin-full/luasrc/view/admin_uci/changes.htm b/modules/admin-full/luasrc/view/admin_uci/changes.htm index 6dd3e5990..34968c05a 100644 --- a/modules/admin-full/luasrc/view/admin_uci/changes.htm +++ b/modules/admin-full/luasrc/view/admin_uci/changes.htm @@ -15,17 +15,19 @@ $Id$ <%+header%> -

<%:Configuration%>

-

<%:Changes%>:

+

<%:Configuration / Changes%>

-
- <%=changes%> -
+<% if changes then %> + <%+admin_uci/changelog%> + <%- uci_changelog(changes) -%> +<% else %> +

<%:There are no pending changes!%>

+<% end %>
"> - +
diff --git a/modules/admin-full/luasrc/view/admin_uci/revert.htm b/modules/admin-full/luasrc/view/admin_uci/revert.htm index 863cfda86..b0b3dabd9 100644 --- a/modules/admin-full/luasrc/view/admin_uci/revert.htm +++ b/modules/admin-full/luasrc/view/admin_uci/revert.htm @@ -15,12 +15,17 @@ $Id$ <%+header%> -

<%:Configuration%>

-

<%:The following changes have been reverted%>:

+

<%:Configuration / Revert%>

-
- <%=(changes or "-")%> -
+<% if changes then %> + <%+cbi/apply_xhr%> + <%+admin_uci/changelog%> + +

<%:The following changes have been reverted%>:

+ <%- uci_changelog(changes) -%> +<% else %> +

<%:There are no pending changes to revert!%>

+<% end %>
"> -- 2.25.1