[luci] Customizing menus

chris at martin.cc chris at martin.cc
Wed Nov 16 04:34:29 CET 2011


On 16 November 2011 07:15, Frank Parker <mr.frank.parker at gmail.com> wrote:

> Thanks for the quick reply.  Let me back up a bit and make sure I have
> a basic understanding.
>
> I want to create a page in the OpenWRT webUI that allows a user to
> edit a value in /etc/config/myapp.  This value will be read by some
> other daemon on the system.
>
> I created /etc/config/myapp like this:
> -------------------------
> config 'myapp' 'device'
>        option 'key' '1234567890eeefff'
> config 'myapp' 'masterswitch'
>        option 'state' 'on'
> -------------------------
> Not sure that is the right format, but that's where I started.
>
> Next I made /usr/lib/lua/luci/model/cbi/mini/myapp.lua like this:
>
> m = Map("myapp", "MyApp")
> s = m:section(TypedSection, "myapp", "")
> s:option(Value, "key", "Key", "See admin for your key")
> return m
>
> Then I created /usr/lib/lua/luci/controller/mini/myapp.lua like this:
>
> module("luci.controller.mini.myapp", package.seeall)
>
> function index()
>        luci.i18n.loadc("admin-core")
>        local i18n = luci.i18n.translate
>
>        entry({"mini", "myapp"}, alias("mini", "myapp", "index"),
> i18n("myapp"), 12).index = true
>        entry({"mini", "myapp", "myapp"}, cbi("mini/myapp"),
> "Settings", 30).dependent=false
> end
>
> So if I understand this correctly:
> controller/mini/myapp.lua determines what the menu looks like
> model/cbi/mini/myapp.lua determines what the webpage looks like
> model/cbi/mini/myapp.lua also handles the magic of reading/writing the
> /etc/config/myapp file
>
> Am I correct so far?
>
> Questions:
>
> 1. Can I see the changes I make without rebooting the router each time???
>
> 2. Looking at the /etc/config/myapp file, How can I display
> myapp.device.key as a TypedSection (i think that means a textbox) and
> display myapp.masterswitch.state as a Flag (i think that means a
> boolean checkbox)?
>
> Currently, both show up as text boxes.
>
> Thanks,
> -parker


You are nearly there.
A typed section is not a test box.
The value option in the text box

The typed section is the definition of a configuration set that matches a
"type" in this case you have defined a config type called "myapp".  By
using a typed section you will iterate over, and display the "key" option
for each config set.
However the second config set of type=myapp named "masterswicth" does not
have a key value, so this will be empty until you save a value

What you really want is

/etc/config/myapp like this:
-------------------------
config 'myapp' 'device'
       option 'key' '1234567890eeefff'
       option 'enable'   '1'
 -------------------------

/usr/lib/lua/luci/model/cbi/mini/myapp.lua like this:
-------------------------
m = Map("myapp", "MyApp")
s = m:section(NamedSection, "device", "myapp")
s:option(Value, "key", "Key", "See admin for your key")
s"option(Flag, "enable", "Enable")
return m
 -------------------------

Also you can make the changes take effect on save using the file
/etc/config/ucitrack
here you list your config file, and which applications it effects, and
which init script needs to be run to reload the configuration


----------------------------------------------------------
Chris Martin
m: +61 419 812 371
----------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsignal.org/pipermail/luci/attachments/20111116/31520959/attachment.html>


More information about the luci mailing list