2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
15 module("luci.controller.mini.uci", package.seeall)
18 local i18n = luci.i18n.translate
20 entry({"mini", "uci"}, nil, i18n("config"))
21 entry({"mini", "uci", "changes"}, call("action_changes"), i18n("changes"), 30)
22 entry({"mini", "uci", "revert"}, call("action_revert"), i18n("revert"), 20)
23 entry({"mini", "uci", "saveapply"}, call("action_apply"), i18n("saveapply"), 10)
26 function convert_changes(changes)
27 local util = require "luci.util"
30 for r, tbl in pairs(changes) do
31 for s, os in pairs(tbl) do
32 for o, v in pairs(os) do
33 ret = (ret and ret.."\n" or "") .. "%s%s.%s%s%s" % {
34 v == "" and "-" or "",
37 o ~= ".type" and "."..o or "",
38 v ~= "" and "="..util.pcdata(v) or ""
46 function action_changes()
47 local changes = convert_changes(luci.model.uci.cursor():changes())
48 luci.template.render("mini/uci_changes", {changes=changes})
51 function action_apply()
52 local path = luci.dispatcher.context.path
53 local uci = luci.model.uci.cursor()
54 local changes = uci:changes()
57 -- Collect files to be applied and commit changes
58 for r, tbl in pairs(changes) do
59 table.insert(reload, r)
65 local function _reload()
66 local cmd = uci:apply(reload, true)
70 luci.template.render("mini/uci_apply", {changes=convert_changes(changes), reload=_reload})
74 function action_revert()
75 local uci = luci.model.uci.cursor()
76 local changes = uci:changes()
78 -- Collect files to be reverted
79 for r, tbl in pairs(changes) do
85 luci.template.render("mini/uci_revert", {changes=convert_changes(changes)})