lua to javascript migration questions
See original GitHub issueI’ll be working on migrating luci apps for https-dns-proxy, simple-adblock, vpn-policy-routing and vpnbypass.
Just for reference I’ll copy the link from a different migration issue: http://openwrt.github.io/luci/jsapi/index.html
I use the service enable/disable and start/stop/special action buttons for all my services (example: https://github.com/openwrt/luci/blob/master/applications/luci-app-https-dns-proxy/luasrc/view/https-dns-proxy/buttons.htm). My plan is to obtain the service enabled/disabled and running/stop status thru a luci rpcd script.
Questions:
- is the dependency on luci rpcd script (to obtain principal package status) necessary in this case or is there something esle I can do?
- is there anything openwrt-specific to include this buttons.js file from /htdocs/…/package-name.js?
- where do I place the actual buttons.js file, as well as required css and js files?
- where do I place the custom status and custom textarea status formatting files?
- the calls from the buttons are currently processed in the controller: https://github.com/openwrt/luci/blob/master/applications/luci-app-https-dns-proxy/luasrc/controller/https-dns-proxy.lua#L9-L27 what would be the correct way of migrating this?
Generic migration questions:
- both in model/cbi files and controllers I have calls to enable/disable and start/stop/restart services (both for my packages and sometimes dnsmasq/others) – is there a way to initiate those from javascript or should I do that from the luci rpcd script?
- follow-up to the question above, how do I implement something to work on
on_after_commit
with javascript? I’ve searched within repo but only found examples inside the lua files. - in https-dns-proxy I have a directory with files for supported providers, in Lua it was easy to have a resource in those translatable, how do I achieve the same with the json file?
- where is the description and what else is available for tools.widgets (as seen in luci-app-adblock):
'require tools.widgets as widgets';
As suggested by @aparcar I’m tagging @PolynomialDivision and @JonnyTischbein but also @dibdot and @Ansuel who have migrated other packages already. 😉
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Create a Lua like JavaScript I18n internationalization
Here's a dirty but verbose way of accomplishing it. Is this what you're looking for?
Read more >Lua & Javascript documentation generation
Are there any tools which can generate documentation for both Lua and Javascript? And as a bonus: we are hosting our project on...
Read more >Why I switched from Lua to Javascript - Reddit
First, it is very simple and aside from the whole indexing-from-one thing, it has fewer surprising quirks than javascript. Tail call optimization (do...
Read more >How to migrate 'run_on_first' in plugin's schema.lua - Questions
During the migration to Kong 2.0 from 1.4 our plugin stopped working as the run_on_first is no longer in kong.db.schema.typedefs.
Read more >Lua Programming Language - Game development with Lua
Latest Posts. How To Learn JavaScript In 1 Hour · ARCHITECTURE OF GOOGLE CLOUD PLATFORM · AWS Certification FAQ · AWS Cloud Migration...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There’s ubus APIs available for that.
To query enabled/disabled, use the
luci / getInitList
procedure, passing the init script asname
parameter. CLI:JS:
To execute init actions, use the
luci / setInitAction
procedure.CLI:
JS:
If with “luci rpcd script” you mean a custom script in
/usr/libexec/rpcd/...
then no, it is not strictly necessary. It usually is only required if you need to expose information or actions via ubus which are not available through other methods already.If you want to move common functionality into a helper library/module, you can use the LuCI specific
'require xxx';
statements in your view class. E.g. a'require https_dns_proxy.utils as utils';
statement would fetch/www/luci-static/ressources/https_dns_proxy/utils.js
and make it available asutils
variable in your view class. See https://github.com/openwrt/luci/blob/master/applications/luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js for an example utility class and https://github.com/openwrt/luci/blob/master/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/rules.js#L8 for a matching require statement.For
.js
files, see above. You’d typically place them in a subdirectory of/www/luci-static/ressources
, e.g./www/luci-static/ressources/https_dns_proxy/utils.js
.CSS files can be placed anywhere where you can access them externally, but a good convention is putting them into a subfolder of
/www/luci-static/resources/css/
, e.g./www/luci-static/resources/css/https_dns_proxy/style.css
. You can then import them by making sure your view renders a<link>
tag, e.g.return E('link', { rel: 'stylesheet', href: L.ressource('css/https_dns_proxy/style.css') });
.Client side JS does not use any kind of templating atm, in your view class you need to render the markup using
E()
calls at the appropriate place, e.g.If you want to modify the behaviour our appearance of a standard CBI widget, you need to first extend it and then use it in your map.
A simple example would be:
In client side views you’d typically initiate server side actions right from the button click handler in an asynchronous manner, e.g.:
Yes, see first reply.
Depends on what you want to do exactly. Right now, a
uci-applied
event is broadcasted to the document whenever a uci apply operation completed, so you could do something likeThat might require changes to the translation infrastructure. For menu JSON files I added a special case to treat the “title” field as translation source. The same can be done for your packages, or even better we add a new file extension, like
.json.intl
which is then automatically preprocessed.The
tools.widgets
class implements a few special widgets that require extra logic. The base widgets are documented in http://openwrt.github.io/luci/jsapi/LuCI.ui.html and their CBI wrappers in http://openwrt.github.io/luci/jsapi/LuCI.form.htmlRegarding widgets look at the exposed functions in widgets.js … I’m not aware of further docs. https://github.com/openwrt/luci/blob/5c5b1340e5541d6283b825f7756812fc1784756f/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js#L618-L624