[luci] Customizing menus

Frank Parker mr.frank.parker at gmail.com
Tue Nov 15 21:15:53 CET 2011


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





On Tue, Nov 15, 2011 at 11:28 AM, Manuel Munz <freifunk at somakoma.de> wrote:
> On 15.11.2011 20:13, Frank Parker wrote:
>> Hi LuCI Community!
>> I'm new to LuCI.  Would it be appropriate to ask some questions on
>> this list regarding customizing the LuCI interface on my OpenWRT
>> router?  I have read the docs at http://luci.subsignal.org/trac/wiki
>> and I have a basic module working.  I'm close to figuring out how to
>> make it appear correctly in the web interface.  Just need some
>> pointers.
>>
>> Thanks,
>>
>> -parker
>
> Hi,
>
> you need to create a controller for it, for an example see:
>
> http://luci.subsignal.org/trac/browser/luci/trunk/applications/luci-p910nd/luasrc/controller/p910nd.lua
> or in any other module/application.
>
> Note the module line. this has to correspond to where your controller
> can be found.
>
> regards, soma
>
>
> _______________________________________________
> luci mailing list
> luci at lists.subsignal.org
> https://lists.subsignal.org/mailman/listinfo/luci
>
>


More information about the luci mailing list