* CBI: Changed parser to list UCI sections in order of their appearance

This commit is contained in:
Steven Barth 2008-04-21 21:27:53 +00:00
parent 4963efa852
commit ede263b769
3 changed files with 17 additions and 11 deletions

View file

@ -147,6 +147,7 @@ function Map.add(self, sectiontype)
if name then if name then
self.ucidata[name] = {} self.ucidata[name] = {}
self.ucidata[name][".type"] = sectiontype self.ucidata[name][".type"] = sectiontype
table.insert(self.ucidata[".order"], name)
end end
return name return name
end end
@ -163,6 +164,7 @@ function Map.set(self, section, option, value)
self.ucidata[section] = {} self.ucidata[section] = {}
end end
self.ucidata[section][".type"] = val self.ucidata[section][".type"] = val
table.insert(self.ucidata[".order"], section)
end end
end end
return stat return stat
@ -360,10 +362,11 @@ end
-- Return all matching UCI sections for this TypedSection -- Return all matching UCI sections for this TypedSection
function TypedSection.cfgsections(self) function TypedSection.cfgsections(self)
local sections = {} local sections = {}
for k, v in pairs(self.map:get()) do local map = self.map:get()
if v[".type"] == self.sectiontype then for i, k in pairs(map[".order"]) do
if map[k][".type"] == self.sectiontype then
if self:checkscope(k) then if self:checkscope(k) then
sections[k] = v table.insert(sections, k)
end end
end end
end end
@ -435,7 +438,7 @@ function TypedSection.parse(self)
end end
end end
for k, v in pairs(self:cfgsections()) do for i, k in ipairs(self:cfgsections()) do
AbstractSection.parse_dynamic(self, k) AbstractSection.parse_dynamic(self, k)
if ffluci.http.formvalue("cbi.submit") then if ffluci.http.formvalue("cbi.submit") then
Node.parse(self, k) Node.parse(self, k)

View file

@ -161,23 +161,26 @@ function Session._uci3(self, cmd)
return nil, res[1] return nil, res[1]
end end
table = {} tbl = {}
for k,line in pairs(res) do for k,line in pairs(res) do
c, s, t = line:match("^([^.]-)%.([^.]-)=(.-)$") c, s, t = line:match("^([^.]-)%.([^.]-)=(.-)$")
if c then if c then
table[c] = table[c] or {} tbl[c] = tbl[c] or {}
table[c][s] = {} tbl[c][".order"] = tbl[c][".order"] or {}
table[c][s][".type"] = t
tbl[c][s] = {}
table.insert(tbl[c][".order"], s)
tbl[c][s][".type"] = t
end end
c, s, o, v = line:match("^([^.]-)%.([^.]-)%.([^.]-)=(.-)$") c, s, o, v = line:match("^([^.]-)%.([^.]-)%.([^.]-)=(.-)$")
if c then if c then
table[c][s][o] = v tbl[c][s][o] = v
end end
end end
return table return tbl
end end
-- Build path (config.section.option=value) and prevent command injection -- Build path (config.section.option=value) and prevent command injection

View file

@ -1,7 +1,7 @@
<div class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>"> <div class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
<h2><%=self.title%></h2> <h2><%=self.title%></h2>
<div class="cbi-section-descr"><%=self.description%></div> <div class="cbi-section-descr"><%=self.description%></div>
<% for k, v in pairs(self:cfgsections()) do%> <% for i, k in ipairs(self:cfgsections()) do%>
<% if self.addremove then %><div class="cbi-section-remove right"> <% if self.addremove then %><div class="cbi-section-remove right">
<input type="submit" name="cbi.rts.<%=self.config%>.<%=k%>" value="<%:cbi_del Eintrag entfernen%>" /> <input type="submit" name="cbi.rts.<%=self.config%>.<%=k%>" value="<%:cbi_del Eintrag entfernen%>" />
</div><% end %> </div><% end %>