Commit Graph

28 Commits

Author SHA1 Message Date
Paul Donald a818ac89bb luci-base: correctness fixes
validation:

use correct argument position for apply

network:

spec.need_tag -> port.need_tag agrees with old lua compat

widgets:

rv.length is undefined, use firstChild

form:

Follow-up to 315dbfc749
checkDepends recursion fix and implement cache lookup

uci:

improve timeout and Promise handling

ui:

follow-up to 92381c3ca2
renderListing sort: put directories first
getActiveTabId: check isNaN for tab state
getScrollParent: fix evaluation logic
fadeOutNotification: implement immediate timeout
openDropdown: accelerate draw via getBoundingClientRect

form:
ensure FlagValue parse always resolves

fs:
parse all 'expect' keys in RpcReply

luci:

Use the same source of truth in both the check and the dispatch
for flushRequestQueue

string check for dom string additions

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2026-05-27 15:49:44 +03:00
Paul Donald 92e1012314 luci-base: fix front matter for luci-base classes
Linking the namespaces provides hierarchy which satisfies
various errors and warnings, but hides the front matter
for the classes for some reason.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2026-02-16 03:41:36 +01:00
Paul Donald 50a8d5325d luci-base: js linting fixes / ES6 treatment
prevent global variable bleed and reduce size somewhat

-cbi
-network
-protocol/static
-rpc
-tools/widgets
-tools/views
-uci

protocols

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2026-02-16 01:42:57 +01:00
Paul Donald 92381c3ca2 luci-base: jsdoc fixes
@name alone does not provide a linkable symbol.
@member and @memberof do.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2026-02-16 01:42:56 +01:00
Paul Donald b5cb136860 luci-base: fix null error
When working with JSONMap backed data sources in tables, sort
triggers a null error because this.state is not available.
Prevent the null error if it is unavailable.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2026-01-18 18:14:41 +01:00
Eric Fahlgren 9717162fd0 luci-base: improve docs for uci.get_bool
The get_bool function documentation was missing an option value, so
add it.  Provide a link into the developer's guide on how it's used
in scripts, for better background.

Signed-off-by: Eric Fahlgren <ericfahlgren@gmail.com>
2025-11-12 22:17:23 +01:00
Eric Fahlgren dea8d79888 luci-base: add uci.get_bool to allow cleanup of app code
Any number of apps read boolean values from configuration files, then use
various inconsistent means for checking truth values.  The get_bool function
allows app authors to fetch the value without regard for how it is represented
in the config file.

For example, this

    let enabled = uci.get('system', 'ntp', 'enable_server');
    if (enabled == '1') ...

could become the more natural

    let enabled = uci.get_bool('system', 'ntp', 'enable_server');
    if (enabled) ...

Signed-off-by: Eric Fahlgren <ericfahlgren@gmail.com>
2025-03-11 15:06:09 +01:00
Tianling Shen 2da1efba38 luci-base: follow-up fix for ES6 changes
follow-up for c2fc96cc4c

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
2024-12-25 15:41:42 +00:00
Paul Donald 8a422af6a0 luci-base: follow-up fix for ES6 changes
follow-up for c2fc96cc4c

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2024-12-21 13:26:42 +00:00
Paul Donald c2fc96cc4c luci-base: convert JavaScript code to ES6 style
Convert existing JavaScript code in LuCI base to utilize ES6 standard
features such as spread arguments, arrow functions, object method
declarations etc.

This makes the code somewhat easier to follow and slightly smaller.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-19 23:42:20 +00:00
Paul Donald e15c190508 luci-base: jsdoc grammar fix
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2024-12-12 15:56:44 +01:00
Paul Donald 7b2d7ba2a5 luci-base: uci: fixed reorder bug where missed deletes caused off-by-one
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2024-11-25 21:26:35 +01:00
Paul Donald 22cccf7b04 luci-base: add clone action for tables
This augments CBITableSection, affecting types which extend it, i.e.
CBIGridSection.

Setting a table 'cloneable' property to true reveals a column of clone
buttons who designate the current entry as a clone source. Clicking the
clone button duplicates the data of that section_id into a new entry,
while the new entry gets a new and unique SID. E.g.

	s = m.section(form.GridSection, 'foo', _('Bar'));
	...
	s.cloneable = true;

Clone and add actions differ: clone will not open a dialogue. That is a
user exercise.

One may set the put_next flag to false to put the new clone last, or
true to put it next (after the clone source).

This uses a new uci action which fulfills the behaviour: clone

It is possible for the uci clone action to be used independently.

See also:
https://forum.openwrt.org/t/add-clone-button-to-luci-configurations-esp-in-firewall/196232

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2024-11-24 15:55:24 +01:00
Hannu Nyman f2a49104c4 Revert "luci-base: force menu to regenerate after uci change"
This reverts commit 97ebdcbddb.

The commit seems to cause errors already before the login screen.
Discussion in https://github.com/openwrt/luci/commit/97ebdcbddb9cad76dc551086fcb887e55886a069#commitcomment-139871175

Errors like:

 In error(), file [C]
 called from function [anonymous function] (/usr/lib/lua/luci/ucodebridge.lua:23)
 called from function ((tail call))
 In [anonymous function](), file /usr/share/ucode/luci/runtime.uc, line 148, byte 45:
   called from function build_pagetree (/usr/share/ucode/luci/dispatcher.uc:382:73)
   called from function menu_json (/usr/share/ucode/luci/dispatcher.uc:439:26)
   called from function [anonymous function] (/usr/share/ucode/luci/dispatcher.uc:898:24)
   called from anonymous function (/www/cgi-bin/luci:39:13)

  `        return lcall.call(modname, method, ...args);`
   Near here ----------------------------------------^

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
2024-03-17 09:17:20 +02:00
James Haggerty 97ebdcbddb luci-base: force menu to regenerate after uci change
Because the menu JSON can have 'depends' in them, uci changes
should force the menu to regenerate.

Closes #6423

Signed-off-by: James Haggerty <james.haggerty@morsemicro.com>
Signed-off-by: Paul Donald <newtwen@gmail.com>
2024-03-17 00:23:45 +01:00
Sergey Ponomarev 7744ad0075 luci-base: Fix typos in JsDocs
In some places argument name was renamed but in the JsDoc it's remain old.

Added more typing for string enum fields like:

 @param {string} [type=text]

replaced with:

 @param {"blob"|"text"|"blob"} [type=text]

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
2023-09-23 10:39:34 +03:00
Jo-Philipp Wich 25dcd0b77c luci-base: uci.js: prevent sending empty uci set operations
Under certain circumstances, a staged uci option value might get unset
again before saving the config, leaving an empty section change set
behind, causing the save call to send an empty uci set request via rpc,
triggering an ubus code 4 (Resource not found) error.

In particular this prevented bridge VLANs from getting saved properly.

Fixes: #5876
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-07-23 00:10:17 +02:00
Jo-Philipp Wich ba4e214160 luci-base: uci.js: merge changes when retrieving entire sections
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-29 22:35:50 +02:00
Jo-Philipp Wich bd5e2edb46 luci-base: uci.js: fix option deletion quirks
Since option deletions are sent first, followed by ubus set commands,
a call sequence like:

    uci.set('config', 'section', 'option', ['foo', 'bar'])
    uci.set('config', 'section', 'option', ['foo'])
    uci.unset('config', 'section', 'option')

... would result in the option retainining `foo` as value, instead of it
getting removed as one would expect.

Fix this issue by reverting the internal change state of the option before
storing the deletion.

While we're at it, also rework the internal tracking of deleted options to
not result in duplicate removal requests when the same option is unset
several times.

Finally change all `undefined` returns to `null` in order to comply with
the function documentation.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-04 18:55:21 +02:00
Jo-Philipp Wich 49c6a810e9 luci-base: uci.js: fix section deletion logic
- Process deletions before additions or changes, allowing user code to
   remove and recreate a section with the same name.

 - Only record section deletions when the section to be removed actually
   existed in the original config or when it was staged for creation
   earlier. This avoids stray ubus not found exception when saving.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-26 18:45:58 +02:00
Jo-Philipp Wich 6ae1cd8fdb luci-base: uci.js: do not issue malformed uci/delete requests
Fixes: #3912
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit ec3a202b69b5bf5785c0785b2ac39efbe5cae2b7)
2020-04-14 17:03:43 +02:00
Jo-Philipp Wich 55cb5a753b luci-base: uci.js: fix variable clash
Don't overwrite the `r` variable which is supposed to refer to the reordered
uci sections with temporary data for collecting uci add parameters.

Fixes stray uci/get permission errors caused by an attempt to load
nonsensical uci package names.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-13 12:22:13 +02:00
Jo-Philipp Wich 65d28a4ac9 luci-base: uci.js: let internal RPC functions reject on errors
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-10 22:52:52 +02:00
Jo-Philipp Wich 711f759278 luci-base: harmonize JS class naming and requesting
- Make builtin classes available via `require` to allow view code to
   request external and internal classes in a consistent manner without
   having to know which classes are builtin and which not

 - Make base classes request any used class explicitely instead of
   relying on implicitly set up L.{dom,view,Poll,Request,Class} aliases

 - Consistently convert class names to lower case in JSdoc to match
   the names used in `require` statements

 - Deprecate L.{dom,view,Poll,Request,Class} aliases

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-02 21:51:20 +02:00
Jo-Philipp Wich b2809cebd8 luci-base: luci.js, rpc.js, uci.js, network.js: add JSDoc annotations
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-02 08:59:41 +02:00
Jo-Philipp Wich e13822e709 luci-base: uci.js: track packages affected by reorder operations
This is required to properly reload the configurations after applying uci
changes that solely consist of uci section ordering operations.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-07-07 15:36:26 +02:00
Jo-Philipp Wich 0560858380 luci-base: uci.js: add extended section syntax support, improve loading
Add support for extended section syntax notation in @type[#] format and
refactor the package loading function to not load configurations twice
when a package load operation is already pending and another load request
is made for the same package.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-07-07 15:36:26 +02:00
Jo-Philipp Wich 1dd910148e luci-base: add uci.js and rpc.js classes
Add a new rpc.js class which provides low level facilities to exchanges
messages with the ubus rpc endpoint.

Also introduce a new uci.js class which provides client side uci
manipulation routines.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-07-07 15:25:49 +02:00