* CBI updates
This commit is contained in:
parent
e2f117b870
commit
f989f6ee00
4 changed files with 68 additions and 19 deletions
|
@ -27,6 +27,7 @@ limitations under the License.
|
||||||
module("ffluci.cbi", package.seeall)
|
module("ffluci.cbi", package.seeall)
|
||||||
require("ffluci.template")
|
require("ffluci.template")
|
||||||
require("ffluci.util")
|
require("ffluci.util")
|
||||||
|
local Template = ffluci.template.Template
|
||||||
local class = ffluci.util.class
|
local class = ffluci.util.class
|
||||||
local instanceof = ffluci.util.instanceof
|
local instanceof = ffluci.util.instanceof
|
||||||
|
|
||||||
|
@ -45,6 +46,10 @@ function Node.append(self, obj)
|
||||||
table.insert(self.children, obj)
|
table.insert(self.children, obj)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Node.render(self)
|
||||||
|
ffluci.template.render(self.template, self)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Map - A map describing a configuration file
|
Map - A map describing a configuration file
|
||||||
|
@ -57,14 +62,10 @@ function Map.__init__(self, config, ...)
|
||||||
self.template = "cbi/map"
|
self.template = "cbi/map"
|
||||||
end
|
end
|
||||||
|
|
||||||
function Map.render(self)
|
|
||||||
ffluci.template.render(self.template)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Map.section(self, class, ...)
|
function Map.section(self, class, ...)
|
||||||
if instanceof(class, AbstractClass) then
|
if instanceof(class, AbstractSection) then
|
||||||
local obj = class(...)
|
local obj = class(...)
|
||||||
obj.map = self
|
obj.map = self.config
|
||||||
table.insert(self.children, obj)
|
table.insert(self.children, obj)
|
||||||
return obj
|
return obj
|
||||||
else
|
else
|
||||||
|
@ -78,14 +79,14 @@ AbstractSection
|
||||||
]]--
|
]]--
|
||||||
AbstractSection = class(Node)
|
AbstractSection = class(Node)
|
||||||
|
|
||||||
function AbstractSection.__init__(self, ...)
|
function AbstractSection.__init__(self, sectiontype, ...)
|
||||||
Node.__init__(self, ...)
|
Node.__init__(self, ...)
|
||||||
|
self.sectiontype = sectiontype
|
||||||
end
|
end
|
||||||
|
|
||||||
function AbstractSection.option(self, class, ...)
|
function AbstractSection.option(self, class, ...)
|
||||||
if instanceof(class, AbstractValue) then
|
if instanceof(class, AbstractValue) then
|
||||||
local obj = class(...)
|
local obj = class(...)
|
||||||
obj.section = self
|
|
||||||
obj.map = self.map
|
obj.map = self.map
|
||||||
table.insert(self.children, obj)
|
table.insert(self.children, obj)
|
||||||
return obj
|
return obj
|
||||||
|
@ -103,8 +104,15 @@ NamedSection = class(AbstractSection)
|
||||||
|
|
||||||
function NamedSection.__init__(self, section, ...)
|
function NamedSection.__init__(self, section, ...)
|
||||||
AbstractSection.__init__(self, ...)
|
AbstractSection.__init__(self, ...)
|
||||||
self.section = section
|
|
||||||
self.template = "cbi/nsection"
|
self.template = "cbi/nsection"
|
||||||
|
|
||||||
|
self.section = section
|
||||||
|
end
|
||||||
|
|
||||||
|
function NamedSection.option(self, ...)
|
||||||
|
local obj = AbstractSection.option(self, ...)
|
||||||
|
obj.section = self.section
|
||||||
|
return obj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,9 +124,8 @@ TypedSection - A (set of) configuration section(s) defined by the type
|
||||||
]]--
|
]]--
|
||||||
TypedSection = class(AbstractSection)
|
TypedSection = class(AbstractSection)
|
||||||
|
|
||||||
function TypedSection.__init__(self, sectiontype, ...)
|
function TypedSection.__init__(self, ...)
|
||||||
AbstractSection.__init__(self, ...)
|
AbstractSection.__init__(self, ...)
|
||||||
self.sectiontype = sectiontype
|
|
||||||
self.template = "cbi/tsection"
|
self.template = "cbi/tsection"
|
||||||
|
|
||||||
self.addremove = true
|
self.addremove = true
|
||||||
|
@ -130,8 +137,9 @@ end
|
||||||
--[[
|
--[[
|
||||||
AbstractValue - An abstract Value Type
|
AbstractValue - An abstract Value Type
|
||||||
null: Value can be empty
|
null: Value can be empty
|
||||||
valid: A table with valid names or a function returning nil if invalid
|
valid: A function returning nil if invalid
|
||||||
depends: A table of option => value pairs of which one must be true
|
depends: A table of option => value pairs of which one must be true
|
||||||
|
default: The default value
|
||||||
]]--
|
]]--
|
||||||
AbstractValue = class(Node)
|
AbstractValue = class(Node)
|
||||||
|
|
||||||
|
@ -139,9 +147,9 @@ function AbstractValue.__init__(self, option, ...)
|
||||||
Node.__init__(self, ...)
|
Node.__init__(self, ...)
|
||||||
self.option = option
|
self.option = option
|
||||||
|
|
||||||
self.null = true
|
|
||||||
self.valid = nil
|
self.valid = nil
|
||||||
self.depends = nil
|
self.depends = nil
|
||||||
|
self.default = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -164,11 +172,18 @@ end
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Boolean - A simple boolean value
|
ListValue - A one-line value predefined in a list
|
||||||
]]--
|
]]--
|
||||||
Boolean = class(AbstractValue)
|
ListValue = class(AbstractValue)
|
||||||
|
|
||||||
function Boolean.__init__(self, ...)
|
function ListValue.__init__(self, ...)
|
||||||
AbstractValue.__init__(self, ...)
|
AbstractValue.__init__(self, ...)
|
||||||
self.template = "cbi/boolean"
|
self.template = "cbi/value"
|
||||||
|
|
||||||
|
self.list = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function ListValue.addValue(self, key, val)
|
||||||
|
val = val or key
|
||||||
|
self.list[key] = val
|
||||||
end
|
end
|
7
src/ffluci/view/cbi/map.htm
Normal file
7
src/ffluci/view/cbi/map.htm
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<div class="cbi-map" id="cbi-<%=config%>">
|
||||||
|
<form method="post" action="<%=os.getenv("REQUEST_URI")%>">
|
||||||
|
<h1><%=title%></h1>
|
||||||
|
<div class="cbi-map-descr"><%=description%></div>
|
||||||
|
<% for k, node in ipairs(children) do node:render() end %>
|
||||||
|
</form>
|
||||||
|
</div>
|
5
src/ffluci/view/cbi/nsection.htm
Normal file
5
src/ffluci/view/cbi/nsection.htm
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<div class="cbi-nsection" id="cbi-<%=map.config%>-<%=sectiontype%>-<%=section%>">
|
||||||
|
<h2><%=title%></h2>
|
||||||
|
<div class="cbi-nsection-descr"><%=description%></div>
|
||||||
|
<% for k, node in ipairs(children) do node:render() end %>
|
||||||
|
</div>
|
22
src/ffluci/view/cbi/tsection.htm
Normal file
22
src/ffluci/view/cbi/tsection.htm
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<%
|
||||||
|
require("ffluci.model.uci")
|
||||||
|
local allsections = ffluci.model.uci.show(map)
|
||||||
|
local sections = {}
|
||||||
|
for k, v in pairs(allsections) do
|
||||||
|
if v[".type"] == sectiontype then
|
||||||
|
sections[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
<div class="cbi-tsection" id="cbi-<%=map%>-<%=sectiontype%>">
|
||||||
|
<h2><%=title%></h2>
|
||||||
|
<div class="cbi-tsection-descr"><%=description%></div>
|
||||||
|
<% for k, v in pairs(sections) do %>
|
||||||
|
<div class="cbi-tsection-node" id="cbi-<%=map%>-<%=k%>">
|
||||||
|
<% for k, node in ipairs(children) do
|
||||||
|
node.section = k
|
||||||
|
node:render(k)
|
||||||
|
end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
Loading…
Reference in a new issue