From: Steven Barth Date: Mon, 21 Apr 2008 21:27:53 +0000 (+0000) Subject: * CBI: Changed parser to list UCI sections in order of their appearance X-Git-Tag: 0.8.0~1118 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ede263b76901345d686eb1c1010d949a711df540;p=oweals%2Fluci.git * CBI: Changed parser to list UCI sections in order of their appearance --- diff --git a/core/src/ffluci/cbi.lua b/core/src/ffluci/cbi.lua index 7a5018999..435977a17 100644 --- a/core/src/ffluci/cbi.lua +++ b/core/src/ffluci/cbi.lua @@ -147,6 +147,7 @@ function Map.add(self, sectiontype) if name then self.ucidata[name] = {} self.ucidata[name][".type"] = sectiontype + table.insert(self.ucidata[".order"], name) end return name end @@ -163,6 +164,7 @@ function Map.set(self, section, option, value) self.ucidata[section] = {} end self.ucidata[section][".type"] = val + table.insert(self.ucidata[".order"], section) end end return stat @@ -360,10 +362,11 @@ end -- Return all matching UCI sections for this TypedSection function TypedSection.cfgsections(self) local sections = {} - for k, v in pairs(self.map:get()) do - if v[".type"] == self.sectiontype then + local map = self.map:get() + for i, k in pairs(map[".order"]) do + if map[k][".type"] == self.sectiontype then if self:checkscope(k) then - sections[k] = v + table.insert(sections, k) end end end @@ -435,7 +438,7 @@ function TypedSection.parse(self) end end - for k, v in pairs(self:cfgsections()) do + for i, k in ipairs(self:cfgsections()) do AbstractSection.parse_dynamic(self, k) if ffluci.http.formvalue("cbi.submit") then Node.parse(self, k) diff --git a/core/src/ffluci/model/uci.lua b/core/src/ffluci/model/uci.lua index 828659780..0e3a79fcb 100644 --- a/core/src/ffluci/model/uci.lua +++ b/core/src/ffluci/model/uci.lua @@ -161,23 +161,26 @@ function Session._uci3(self, cmd) return nil, res[1] end - table = {} + tbl = {} for k,line in pairs(res) do c, s, t = line:match("^([^.]-)%.([^.]-)=(.-)$") if c then - table[c] = table[c] or {} - table[c][s] = {} - table[c][s][".type"] = t + tbl[c] = tbl[c] or {} + tbl[c][".order"] = tbl[c][".order"] or {} + + tbl[c][s] = {} + table.insert(tbl[c][".order"], s) + tbl[c][s][".type"] = t end c, s, o, v = line:match("^([^.]-)%.([^.]-)%.([^.]-)=(.-)$") if c then - table[c][s][o] = v + tbl[c][s][o] = v end end - return table + return tbl end -- Build path (config.section.option=value) and prevent command injection diff --git a/core/src/ffluci/view/cbi/tsection.htm b/core/src/ffluci/view/cbi/tsection.htm index 8da0b4a1d..666c14b2e 100644 --- a/core/src/ffluci/view/cbi/tsection.htm +++ b/core/src/ffluci/view/cbi/tsection.htm @@ -1,7 +1,7 @@

<%=self.title%>

<%=self.description%>
-<% for k, v in pairs(self:cfgsections()) do%> +<% for i, k in ipairs(self:cfgsections()) do%> <% if self.addremove then %>
<% end %>