Quellcode durchsuchen

gluon-luci-autoupdater: avoid use of CBI Maps

As convenient as the Map is, the underlying code is very complex and will
be removed.
Matthias Schiffer vor 7 Jahren
Ursprung
Commit
78d8645e19

+ 32 - 15
package/gluon-luci-autoupdater/luasrc/usr/lib/lua/luci/model/cbi/admin/autoupdater.lua

@@ -12,18 +12,35 @@ You may obtain a copy of the License at
 $Id$
 ]]--
 
-m = Map("autoupdater", translate("Automatic updates"))
-m.pageaction = false
-m.template = "cbi/simpleform"
-
-s = m:section(TypedSection, "autoupdater", nil)
-s.addremove = false
-s.anonymous = true
-
-s:option(Flag, "enabled", translate("Enable"))
-f = s:option(ListValue, "branch", translate("Branch"))
-
-uci.cursor():foreach("autoupdater", "branch", function (section) f:value(section[".name"]) end)
-
-return m
-
+local uci = require("simple-uci").cursor()
+local autoupdater = uci:get_first("autoupdater", "autoupdater")
+
+local f = SimpleForm("autoupdater", translate("Automatic updates"))
+local s = f:section(SimpleSection, nil, nil)
+local o
+
+o = s:option(Flag, "enabled", translate("Enable"))
+o.default = uci:get_bool("autoupdater", autoupdater, "enabled") and o.enabled or o.disabled
+o.rmempty = false
+
+o = s:option(ListValue, "branch", translate("Branch"))
+uci:foreach("autoupdater", "branch",
+	function (section)
+		o:value(section[".name"])
+	end
+)
+o.default = uci:get("autoupdater", autoupdater, "branch")
+
+function f.handle(self, state, data)
+	if state ~= FORM_VALID then
+		return
+	end
+
+	uci:set("autoupdater", autoupdater, "enabled", data.enabled)
+	uci:set("autoupdater", autoupdater, "branch", data.branch)
+
+	uci:save("autoupdater")
+	uci:commit("autoupdater")
+end
+
+return f