* Fixed an issue that prevented the controller from working with fastindex
[project/luci.git] / modules / admin-core / luasrc / controller / admin / uci.lua
index 9c0e1be..fc70b9b 100644 (file)
@@ -1,14 +1,40 @@
 module("luci.controller.admin.uci", package.seeall)
-require("luci.util")
-require("luci.sys")
 
 function index()
-       node("admin", "uci", "changes").target = template("admin_uci/changes")
+       node("admin", "uci", "changes").target = call("action_changes")
        node("admin", "uci", "revert").target  = call("action_revert")
        node("admin", "uci", "apply").target   = call("action_apply")
 end
 
--- This function has a higher priority than the admin_uci/apply template
+function convert_changes(changes)
+       local ret = {}
+       for r, tbl in pairs(changes) do
+               for s, os in pairs(tbl) do
+                       for o, v in pairs(os) do
+                               local val, str
+                               if (v == "") then
+                                       str = "-"
+                                       val = ""
+                               else
+                                       str = ""
+                                       val = "="..v
+                               end
+                               str = r.."."..s
+                               if o ~= ".type" then
+                                       str = str.."."..o
+                               end
+                               table.insert(ret, str..val)
+                       end
+               end
+       end
+       return table.concat(ret, "\n")
+end
+
+function action_changes()
+       local changes = convert_changes(luci.model.uci.changes())
+       luci.template.render("admin_uci/changes", {changes=changes})
+end
+
 function action_apply()
        local changes = luci.model.uci.changes()
        local output  = ""
@@ -18,29 +44,25 @@ function action_apply()
                local run = {}
                
                -- Collect files to be applied and commit changes
-               for i, line in ipairs(luci.util.split(changes)) do
-                       local r = line:match("^-?([^.]+)")
+               for r, tbl in pairs(changes) do
                        if r then
-                               com[r] = true
-                               
+                               luci.model.uci.load(r)
+                               luci.model.uci.commit(r)
+                               luci.model.uci.unload(r)
                                if luci.config.uci_oncommit and luci.config.uci_oncommit[r] then
                                        run[luci.config.uci_oncommit[r]] = true
                                end
                        end
                end
                
-               -- Apply
-               for config, i in pairs(com) do
-                       luci.model.uci.commit(config)
-               end 
-               
                -- Search for post-commit commands
                for cmd, i in pairs(run) do
                        output = output .. cmd .. ":" .. luci.sys.exec(cmd) .. "\n"
                end
        end
        
-       luci.template.render("admin_uci/apply", {changes=changes, output=output})
+       
+       luci.template.render("admin_uci/apply", {changes=convert_changes(changes), output=output})
 end
 
 
@@ -50,18 +72,12 @@ function action_revert()
                local revert = {}
                
                -- Collect files to be reverted
-               for i, line in ipairs(luci.util.split(changes)) do
-                       local r = line:match("^-?([^.]+)")
-                       if r then
-                               revert[r] = true
-                       end
-               end
-               
-               -- Revert them
-               for k, v in pairs(revert) do
-                       luci.model.uci.revert(k)
+               for r, tbl in pairs(changes) do
+                       luci.model.uci.load(r)
+                       luci.model.uci.revert(r)
+                       luci.model.uci.unload(r)
                end
        end
        
-       luci.template.render("admin_uci/revert", {changes=changes})
-end
\ No newline at end of file
+       luci.template.render("admin_uci/revert", {changes=convert_changes(changes)})
+end