Commit graph

314 commits

Author SHA1 Message Date
Jo-Philipp Wich
894752610d luci-base: cbi.js: support plural translations and disambiguation contexts
- Implement `N_(count, "String singular", "String plural" [, "Context"])`
   plural translation function.

 - Extend `_()` to optionally accept a second disambiguation context
   argument.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-22 22:02:24 +01:00
Jo-Philipp Wich
136b965b25 luci-base: ui.js: UIFileUpload fixes
- Introduce a new option `initial_directory` which describes the initial
   directory to display when nothing is selected, default to the root
   directory

 - Prevent stray legacy cbi reloads when deselecting files

 - Fix within-root-directory-check for initial rendering

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-20 19:40:46 +01:00
Jo-Philipp Wich
601c4ee01e luci-base: form.js: add a new "contains" dependency mode
By tagging option dependencies with `!contains`, dependencies are
considered satisfied when the value is contained in the value of
a related field, instead of being equal to it.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-19 16:15:22 +01:00
Jo-Philipp Wich
4670099a20 luci-base: form.js: don't stringify node arguments in CBIValue.value()
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-19 16:15:22 +01:00
Jo-Philipp Wich
cc123a03ce luci-base: ui.js: support clearChoices()/addChoices() for DynLists
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-19 16:15:22 +01:00
Jo-Philipp Wich
9733a182e8 luci-base: ui.js: use placeholder as select placeholder in DynLists
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-19 16:15:22 +01:00
Jo-Philipp Wich
4c52718dea luci-base: ui.js: properly handle rich choices in Dropdowns, DynLists
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-19 16:15:22 +01:00
Jo-Philipp Wich
aca2c4ba4e luci-base: cbi.js: collapse whitespace before language string hashing
To mirror the behavior of the Lua runtime, we need to collapse whitepace
in translation source strings before doing the string table lookup.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-16 18:17:09 +01:00
Jo-Philipp Wich
b65588ebc6
Merge pull request #3511 from Ansuel/no-hard
luci-base: remove hardcoded cgi-bin path
2020-01-16 15:36:05 +01:00
Ansuel Smith
529bde4408
luci-base: make rpc webserver path configurable
Currently the ubus path that provide the webserver is hardcoded to be /ubus.
Change this to make it configurable from the luci config file.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
2020-01-16 15:16:09 +01:00
Ansuel Smith
5e6ec8562f
luci-base: remove hardcoded cgi-bin path
Currently LuCI can be loaded only when placed in the root of the server as the cgi-bin path are hardcoded. Change the index.html to load the cgi-bin path from the current level.
Also add a new entry in the env Object to make the cgi_base path easily accessible.
This variable will be based on the position of /cgi-bin/luci.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
2020-01-16 15:02:14 +01:00
Jo-Philipp Wich
77c2998f32 luci-base: form.js: fix immediate validation of activated options
When form options are activated because their dependencies are satisified,
ensure that an immediate validation is triggered to highlight potential
errors without having the user to activate another form control first.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-15 18:52:16 +01:00
Jo-Philipp Wich
9e25917432 luci-base: form.js: implement AbstractValue.getUIElement()
Introduce a new method `getUIElement()` which simplifies obtaining the
underlying per-section UI widget class instance for a from option object.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-12-30 14:51:40 +01:00
Jo-Philipp Wich
b0836b037e luci-base: ui.js: implement UIDropdown.{add,clear}Choices()
The new `addChoices()` and `clearChoices()` functions allow clearing and
adding new options to existing dropdown instances respectively.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-12-30 14:51:40 +01:00
Jo-Philipp Wich
0d0a3f4d0d luci-base: ui.js: expose UIElement class as AbstractElement
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-12-30 14:51:40 +01:00
Jo-Philipp Wich
e884b63916 luci-base: fs.js: properly escape arguments in exec_direct()
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-12-18 21:22:06 +01:00
Jo-Philipp Wich
f3724e46a5 luci-base: fs.js: add read_direct() and exec_direct() functions
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-12-18 21:10:15 +01:00
Balázs Úr
d0bc86bcc3 luci-base: fix typos
Signed-off-by: Balázs Úr <balazs@urbalazs.hu>
2019-12-17 11:41:00 +01:00
Jo-Philipp Wich
90a161018c luci-base: ui.js: allow custom validation in Dropdown and DynamicList
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-12-16 17:46:01 +01:00
Jo-Philipp Wich
71d370a964 luci-base: ui.js: ensure that select choice labels are properly escaped
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-12-04 18:06:58 +01:00
Jo-Philipp Wich
ee36066947 luci-base: ui.js: properly escape dynlist items for rendering
Ref: https://forum.openwrt.org/t/luci-theme-openwrt-reports-error/49736
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-12-04 16:09:23 +01:00
Jo-Philipp Wich
4a08fdd2d3 luci-base: luci.js: further nested Class.super() call fixes
Use stacks keyed by class id + symbol internally to not clobber the
prototype scope pointer when repeatedly calling super() in invoked
methods.

Ref: https://github.com/openwrt/luci/issues/3316#issuecomment-558531111
Fixes: 374c23cda ("luci-base: luci.js: properly handle nested Class.super() calls")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-26 11:39:14 +01:00
Jo-Philipp Wich
374c23cdab luci-base: luci.js: properly handle nested Class.super() calls
Introduce a unique __id__ attribute per class and use that, together with
the symbol name being looked up to, to form a unique key which is used to
store the prototype scope pointer.

This fixes cases where a call to super() invokes a procedure which is
calling super() as well on a different class or symbol.

Fixes: #3316
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-26 09:37:27 +01:00
Jo-Philipp Wich
4f0d67a289 luci-base: validation.js: fix "unique" validator
Previous refactoring renamed the "data-type" attribute of widget markup
containers to "data-widget", breaking the "unique" validator as it relies
on it to lookup options.

Fixes: #3341
Fixes: 13e9e3e9e ("treewide: fix "Unhandled token" errors with Lua CBI maps")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-22 08:42:58 +01:00
Jo-Philipp Wich
13e9e3e9e8 treewide: fix "Unhandled token" errors with Lua CBI maps
The `data-type` attribute is used to bind datatype validators to a widget
while some templates used the same attribute to denote the name of the
underlying widget.

Change the `data-type` attributes referring to the widget name to
`data-widget` in order to stop the JS token error spam.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-16 18:25:52 +01:00
Kevin Darbyshire-Bryant
9b266d11c6 luci-base: Improve change application message
As a native English speaker the luci message displayed when clicking
'Save & Apply' has a somewhat uncomfortable English phrasing of "Waiting
for configuration to get applied".  It could be improved by replacing
'get' with 'be' but once you've got that far you might as well replace
this with the shorter & simpler "Applying configuration changes".  This
is also technically more correct since luci/openwrt should only be
updating/restarting processes that are related to the changed areas, not
changing the entire configuration.

As a result of that, change both the 'success' and 'rolled back'
messages to "Configuration changes have been applied" & "Configuration
changes have been rolled back"

Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
2019-11-15 14:29:57 +00:00
Jo-Philipp Wich
304dd37e3f luci-base: network.js: fix getDevices()
- Don't filter virtual interfaces
 - Skip duplicate wireless devices

Fixes: #3304
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-13 18:36:15 +01:00
Jo-Philipp Wich
4cc7772ed5 luci-base: ui.js: show filename after selecting upload file
Fixes: #3286
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-10 19:45:58 +01:00
Jo-Philipp Wich
3b3a1d9cc9 luci-base: luci.js: add optional apply unchecked action
Turn the "Save & Apply" button into a combo button which allows to
toggle between apply with rollback and unchecked apply modes.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-10 18:21:09 +01:00
Jo-Philipp Wich
97a3bef84b luci-base: ui.js: add ComboButton widget
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-10 18:20:39 +01:00
Jo-Philipp Wich
a2dc6c8216 luci-base: network.js: introduce further API functions
- Add Network.getWifiNetworks() to simplify fetching *all* networks
   instead of building a list by iterating each radio first

 - Add Network.WifiNetwork.isClientDisconnectSupported() to check whether
   a wireless network supports client disconnections

 - Add Network.WifiNetwork.disconnectClient() to trigger client
   disconnections via hostapd

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-07 12:08:15 +01:00
Jo-Philipp Wich
a8a7697829 luci-base: network.js: prevent duplicate wan interface reporting
Fixes: #3269
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-06 13:22:10 +01:00
Richard Yu
fa15370f0e
luci-base: form.js: fix GridSection not using user-input name when add
Signed-off-by: Richard Yu <yurichard3839@gmail.com>
2019-11-04 00:19:33 +08:00
Jo-Philipp Wich
33346dadf4 luci-base, luci-mod-system: move file upload handling to ui.js
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-01 12:03:33 +01:00
Jo-Philipp Wich
6e633b3ed2 luci-base: consolidate network.js data acquisition
The new luci-rpc/getNetworkDevices procedure offers netdev enumeration
with included IPv4 and IPv6 address information as well as 64bit traffic
counters, so we can remove the calls to network.device/status and
luci/getIfaddrs now as we're able to obtain all info from a single source.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-01 12:03:33 +01:00
Jo-Philipp Wich
cc1cbdaf32 luci-base: migrate luci/getNetworkDevices to C plugin
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-01 12:03:33 +01:00
Jo-Philipp Wich
a96e7a664f luci-base: migrate luci/getWirelessDevices to C plugin
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-01 12:03:33 +01:00
Jo-Philipp Wich
37b6092aef luci-base, luci-mod-network, luci-app-firewall: migrate luci/getHostHints
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-01 12:03:33 +01:00
Jo-Philipp Wich
d21ebcfbbc luci-base: migrate luci/getBoardJSON to C plugin
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-01 12:03:33 +01:00
Jo-Philipp Wich
199428a9c3 luci-base: network.js: implement Protocol.getGateway6Addr()
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-22 22:38:29 +02:00
Jo-Philipp Wich
2b7ca79118 luci-base: ui.js: prevent race condition in tab initialization
Fixes: #3150
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-22 15:51:51 +02:00
Jo-Philipp Wich
77a89299f4 luci.base: fs.js: expose mode param in fs.write()
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-21 08:42:41 +02:00
Jo-Philipp Wich
d5ffab23b6 luci-base: network.js: simplify rpc error handling
Use L.resolveDefault() catch unexpected RPC replies and rename declared
rpc functions in a consistent manner.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-18 11:49:13 +02:00
Jo-Philipp Wich
51b519e55e luci-base: network.js: prefer netifd traffic stats over getifaddrs() ones
Overwrite the traffic statistics reported by getifaddrs() with the ones
reported by the network.device/status procedure if available as the
getifaddr() stats are limited to 32bit counters.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-17 09:21:04 +02:00
Jo-Philipp Wich
120ece921d luci-base: static.js: make IPv6 assignment hint optional
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-15 09:14:56 +02:00
Richard Yu
02a0291d14
luci-base: widgets.js: add user and group select
Signed-off-by: Richard Yu <yurichard3839@gmail.com>
2019-10-11 01:05:08 +08:00
Jo-Philipp Wich
e7ca163d7c luci-base: form.js: fix anonymous section table titles
When no section title is defined, the table renderer is supposed to use
the uci section id as fallback when the table section is not declared
to be anonymous.

Fixes: #3147
Fixes: a90bf384b ("luci-base: form.js: harmonize title property handling")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-07 19:49:58 +02:00
Jo-Philipp Wich
5cfad8d65b luci-base: form.js: treat inactive options as optional
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-07 19:44:22 +02:00
Jo-Philipp Wich
f3ef2ca2eb luci-base: ui.js: add pingDevice() and awaitReconnect() functions
Import these functions from the flash.js for use with other views that
might trigger a device reboot.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-07 11:53:39 +02:00
Jo-Philipp Wich
df8078d542 luci-base: ui.js: use common fs.js class for filebrowser operations
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-07 11:53:39 +02:00