From: Steven Barth Date: Sat, 22 Mar 2008 19:46:14 +0000 (+0000) Subject: * CBI updates X-Git-Tag: 0.8.0~1204 X-Git-Url: http://git.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=93c55f3c5d7d253423c9d5695b8d71388bd21988 * CBI updates * Made dispatching paths unambiguous --- diff --git a/src/ffluci/cbi.lua b/src/ffluci/cbi.lua index 5a20aadc53..85b9f49e9d 100644 --- a/src/ffluci/cbi.lua +++ b/src/ffluci/cbi.lua @@ -86,6 +86,12 @@ function Node.render(self) ffluci.template.render(self.template, {self=self}) end +function Node.render_children(self) + for k, node in ipairs(self.children) do + node:render() + end +end + --[[ Map - A map describing a configuration file @@ -175,6 +181,23 @@ function TypedSection.__init__(self, ...) self.valid = nil end +function TypedSection.render_children(self, section) + for k, node in ipairs(self.children) do + node.section = section + node:render() + end +end + +function TypedSection.ucisections(self) + local sections = {} + for k, v in pairs(self.map:read()) do + if v[".type"] == self.sectiontype then + sections[k] = v + end + end + return sections +end + --[[ AbstractValue - An abstract Value Type diff --git a/src/ffluci/dispatcher.lua b/src/ffluci/dispatcher.lua index 0f05c3d173..f3a62bb193 100644 --- a/src/ffluci/dispatcher.lua +++ b/src/ffluci/dispatcher.lua @@ -167,13 +167,15 @@ function cbi(request) local tmpl = require("ffluci.template") local cbi = require("ffluci.cbi") + local path = request.category.."_"..request.module.."/"..request.action + i18n.loadc(request.module) - stat, map = pcall(cbi.load, request.module.."/"..request.action) + stat, map = pcall(cbi.load, path) if stat then - tmpl.render("header") + tmpl.render("cbi/header") map:render() - tmpl.render("footer") + tmpl.render("cbi/footer") else disp.error404() end @@ -195,15 +197,16 @@ function dynamic(request) return end - if pcall(tmpl.render, request.module .. "/" .. request.action) then + local path = request.category.."_"..request.module.."/"..request.action + if pcall(tmpl.render, path) then return end - stat, map = pcall(cbi.load, request.module.."/"..request.action) + stat, map = pcall(cbi.load, path) if stat then - tmpl.render("header") + tmpl.render("cbi/header") map:render() - tmpl.render("footer") + tmpl.render("cbi/footer") return end @@ -217,8 +220,10 @@ function simpleview(request) local tmpl = require("ffluci.template") local disp = require("ffluci.dispatcher") + local path = request.category.."_"..request.module.."/"..request.action + i18n.loadc(request.module) - if not pcall(tmpl.render, request.module .. "/" .. request.action) then + if not pcall(tmpl.render, path) then disp.error404() end end \ No newline at end of file diff --git a/src/ffluci/view/cbi/footer.htm b/src/ffluci/view/cbi/footer.htm new file mode 100644 index 0000000000..e8ef8fef5e --- /dev/null +++ b/src/ffluci/view/cbi/footer.htm @@ -0,0 +1,2 @@ + +<%+footer%> \ No newline at end of file diff --git a/src/ffluci/view/cbi/header.htm b/src/ffluci/view/cbi/header.htm new file mode 100644 index 0000000000..bd3607f11e --- /dev/null +++ b/src/ffluci/view/cbi/header.htm @@ -0,0 +1,2 @@ +<%+header%> +
"> diff --git a/src/ffluci/view/cbi/map.htm b/src/ffluci/view/cbi/map.htm index b724ffccbb..e6884f1045 100644 --- a/src/ffluci/view/cbi/map.htm +++ b/src/ffluci/view/cbi/map.htm @@ -1,10 +1,8 @@ -
- "> +

<%=self.title%>

<%=self.description%>

-<% for k, node in ipairs(self.children) do node:render() end %> +<% self:render_children() %>
- -
+
diff --git a/src/ffluci/view/cbi/nsection.htm b/src/ffluci/view/cbi/nsection.htm index e002c68b09..84f893d2b8 100644 --- a/src/ffluci/view/cbi/nsection.htm +++ b/src/ffluci/view/cbi/nsection.htm @@ -2,6 +2,6 @@

<%=self.title%>

<%=self.description%>
-<% for k, node in ipairs(self.children) do node:render() end %> +<% self:render_children() %>
diff --git a/src/ffluci/view/cbi/tsection.htm b/src/ffluci/view/cbi/tsection.htm index b613f6271f..bd19ecf59a 100644 --- a/src/ffluci/view/cbi/tsection.htm +++ b/src/ffluci/view/cbi/tsection.htm @@ -1,21 +1,11 @@ -<% -local allsections = self.map:read() -local sections = {} -for k, v in pairs(allsections) do - if v[".type"] == self.sectiontype then - sections[k] = v - end -end -%>

<%=self.title%>

<%=self.description%>
-<% for k, v in pairs(sections) do %> -
-<% for i, node in ipairs(self.children) do - node.section = k - node:render() -end %> -
+<% for k, v in pairs(self:ucisections()) do%> +
+ <% if not self.anonymous then %><%=k%><% end %> +<% self:render_children(k) %> +
+
<% end %>
diff --git a/src/ffluci/view/header.htm b/src/ffluci/view/header.htm index cef95b36c2..2af577a078 100644 --- a/src/ffluci/view/header.htm +++ b/src/ffluci/view/header.htm @@ -10,6 +10,7 @@ require("ffluci.http").htmlheader() + FFLuCI <% if addheaders then write(addheaders) end %> @@ -56,4 +57,4 @@ require("ffluci.http").htmlheader()
Konfiguration
<% end %> -
+
\ No newline at end of file diff --git a/src/ffluci/view/index/index.htm b/src/ffluci/view/index/index.htm deleted file mode 100644 index a186132861..0000000000 --- a/src/ffluci/view/index/index.htm +++ /dev/null @@ -1,6 +0,0 @@ -<%+header%> -

<%:hello Hallo!%>

-

<%:welcome1 Dies ist der Funknetzknoten %> -<%=require("ffluci.sys").hostname()%>!

-

ToDo: Intelligenter Einleitungstext

-<%+footer%> \ No newline at end of file diff --git a/src/ffluci/view/public_index/index.htm b/src/ffluci/view/public_index/index.htm new file mode 100644 index 0000000000..a186132861 --- /dev/null +++ b/src/ffluci/view/public_index/index.htm @@ -0,0 +1,6 @@ +<%+header%> +

<%:hello Hallo!%>

+

<%:welcome1 Dies ist der Funknetzknoten %> +<%=require("ffluci.sys").hostname()%>!

+

ToDo: Intelligenter Einleitungstext

+<%+footer%> \ No newline at end of file