@yuneta/gobj-ui 7.31.8 → 7.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -4
- package/dist/gobj-ui.cjs.js +21 -34
- package/dist/gobj-ui.es.js +21 -34
- package/package.json +1 -1
- package/src/c_yui_treedb_topic_with_form.css +16 -51
- package/src/c_yui_treedb_topic_with_form.js +20 -70
- package/src/c_yui_treedb_topics.js +16 -2
- package/src/treedb_topics_transport.wiring.test.js +55 -2
- package/src/yui_table_standard.js +214 -0
- package/src/yui_table_standard.test.js +164 -0
- package/src/yui_tabulator_i18n.js +7 -1
package/README.md
CHANGED
|
@@ -1037,8 +1037,8 @@ instead of the host pushing the whole topic down. It needs the SDK's `nodes`
|
|
|
1037
1037
|
with `from` / `limit` (see `YUNO_TREEDB.md` §5.3).
|
|
1038
1038
|
|
|
1039
1039
|
**The page size is generous on purpose** (`page_size`, 200 when paging). A
|
|
1040
|
-
treedb
|
|
1041
|
-
|
|
1040
|
+
treedb small enough for one page behaves exactly as it did: every filter
|
|
1041
|
+
sees every row. Only a topic that does NOT fit pays for paging,
|
|
1042
1042
|
and for that one loading it whole was never an option.
|
|
1043
1043
|
|
|
1044
1044
|
**Safe against a backend that cannot page:** it answers the whole list, which
|
|
@@ -2689,8 +2689,9 @@ like this:
|
|
|
2689
2689
|
|
|
2690
2690
|
and its card draws the row `version (2)`. An empty `tkey` marks no field.
|
|
2691
2691
|
|
|
2692
|
-
The topic cards (`C_YUI_TREEDB_TOPICS`)
|
|
2693
|
-
|
|
2692
|
+
The topic cards (`C_YUI_TREEDB_TOPICS`) are in alphabetical order, and so
|
|
2693
|
+
are its tabs (7.32.0+). The system topics (`__*__`) come first. The topic
|
|
2694
|
+
cards and the topic-info panel say the same keys. A card of a topic with `pkey2s` has a `pkey2s` line under its version and
|
|
2694
2695
|
column count. The info panel always has a `tkey` row, which says *append time*
|
|
2695
2696
|
when the topic has none, a `pkey2s` row when the topic has secondary keys, and
|
|
2696
2697
|
`system` by the flag names (`sf_string_key`), not by the number. In its column
|
|
@@ -4350,6 +4351,73 @@ The app must define the i18n key **`"clear"`**. Three decisions are baked in:
|
|
|
4350
4351
|
they change. The walk is idempotent and gated by a single `querySelector`, so
|
|
4351
4352
|
repeating it on every render costs nothing.
|
|
4352
4353
|
|
|
4354
|
+
### The standard table: `yui_table_standard.js`
|
|
4355
|
+
|
|
4356
|
+
Three calls give a Tabulator table the table half of the table rule (see
|
|
4357
|
+
[the rule](#a-table-a-filter-on-every-column-the-paginator-always-the-toolbar-in-one-row)
|
|
4358
|
+
under "Conventions"). The toolbar half is `yui_toolbar()`.
|
|
4359
|
+
|
|
4360
|
+
```js
|
|
4361
|
+
import {yui_tabulator_lang} from "@yuneta/gobj-ui/src/yui_tabulator_i18n.js";
|
|
4362
|
+
import {
|
|
4363
|
+
yui_table_paging,
|
|
4364
|
+
yui_table_filters,
|
|
4365
|
+
yui_table_wire,
|
|
4366
|
+
} from "@yuneta/gobj-ui/src/yui_table_standard.js";
|
|
4367
|
+
|
|
4368
|
+
let table = new Tabulator($div, {
|
|
4369
|
+
...yui_tabulator_lang(t),
|
|
4370
|
+
...yui_table_paging(),
|
|
4371
|
+
data: rows, /* every row */
|
|
4372
|
+
columns: yui_table_filters([
|
|
4373
|
+
{title: t("email"), field: "username"},
|
|
4374
|
+
{title: t("enabled"), field: "enabled", formatter: "tickCross"},
|
|
4375
|
+
{title: t("actions"), field: "user_id", headerFilter: false,
|
|
4376
|
+
formatter: actions_formatter},
|
|
4377
|
+
]),
|
|
4378
|
+
});
|
|
4379
|
+
yui_table_wire(table, t);
|
|
4380
|
+
```
|
|
4381
|
+
|
|
4382
|
+
`yui_table_paging(opts)` gives the pagination settings: local pagination,
|
|
4383
|
+
25 rows to a page, and the sizes 25, 50, 100 and All. `opts.size` and
|
|
4384
|
+
`opts.sizes` change them. A size that the sizes do not hold goes first in
|
|
4385
|
+
the selector. The host gives the table every row. The footer shows the
|
|
4386
|
+
paginator and the row count. The count is the number of rows that the
|
|
4387
|
+
filters leave, on all pages together. The table locale gives its word, so
|
|
4388
|
+
the word changes language with `yui_tabulator_relocalize()`.
|
|
4389
|
+
|
|
4390
|
+
`yui_table_filters(columns)` gives a copy of the columns, each with its
|
|
4391
|
+
header filter:
|
|
4392
|
+
|
|
4393
|
+
- A column with a `field` and no `headerFilter` gets a text box. The box
|
|
4394
|
+
finds a part of the value, in any case. The column also gets
|
|
4395
|
+
`minWidth: 150`, which is the width of the placeholder in the longest
|
|
4396
|
+
locale, unless it sets `width` or `minWidth` itself.
|
|
4397
|
+
- A column with `formatter: "tickCross"` gets a three-state tick: any, yes,
|
|
4398
|
+
no.
|
|
4399
|
+
- A column with its own `headerFilter` keeps it. Give `headerFilter: false`
|
|
4400
|
+
to a column whose cell is a control, for example a row of action buttons.
|
|
4401
|
+
- A column with no `field`, or with a control formatter (`rowSelection`),
|
|
4402
|
+
gets no filter. Column groups are walked.
|
|
4403
|
+
|
|
4404
|
+
`yui_table_wire(table, t)` names each filter box ("filter by column") and
|
|
4405
|
+
adds its ✕ (`yui_table_filter_clear()`). It does this when the table is
|
|
4406
|
+
built and again each time Tabulator builds the columns again. Call it right
|
|
4407
|
+
after `new Tabulator(...)`.
|
|
4408
|
+
|
|
4409
|
+
The app must define the keys `"rows"`, `"filter by column"` and `"clear"`,
|
|
4410
|
+
and the paginator keys of `yui_tabulator_lang()`.
|
|
4411
|
+
|
|
4412
|
+
Two things to look at when you apply it:
|
|
4413
|
+
|
|
4414
|
+
- A text filter compares the value of the row, not what the formatter
|
|
4415
|
+
shows. If a column shows a boolean as "Yes" or "No", give it a tick
|
|
4416
|
+
(`headerFilter: "tickCross"`, `headerFilterParams: {tristate: true}`) or
|
|
4417
|
+
a list.
|
|
4418
|
+
- A column with a fixed `width` under 150 px cuts the placeholder of its
|
|
4419
|
+
filter. Give it 150.
|
|
4420
|
+
|
|
4353
4421
|
### Searching a row that is not flat — `yui_row_search.js`
|
|
4354
4422
|
|
|
4355
4423
|
`row_matches(row, term)` is what the treedb topic table's search box uses, and
|
|
@@ -4476,6 +4544,63 @@ text is in the yunetas `CLAUDE.md` ("JS GUI conventions"); in short:
|
|
|
4476
4544
|
let $a = $c.querySelector(`a[data-route="${css_string(route)}"]`);
|
|
4477
4545
|
```
|
|
4478
4546
|
|
|
4547
|
+
### A table: a filter on every column, the paginator always, the toolbar in one row
|
|
4548
|
+
|
|
4549
|
+
Every table of an admin view obeys this rule. The admin views are the
|
|
4550
|
+
treedb editor of each app (`C_YUI_TREEDB_TOPICS`), the accounts views, and
|
|
4551
|
+
the tables of `gui_treedb` and `gui_agent`. Other tables can obey it too.
|
|
4552
|
+
|
|
4553
|
+
1. Each column that holds data has a header filter. A column whose cell is
|
|
4554
|
+
a control has none, for example the action buttons or the selection
|
|
4555
|
+
checkbox.
|
|
4556
|
+
2. The footer shows the paginator at all times, also when all the rows fit
|
|
4557
|
+
in one page.
|
|
4558
|
+
3. The table holds all its rows in the browser and pages them there. This
|
|
4559
|
+
is local pagination.
|
|
4560
|
+
4. Each toolbar above the table takes one row. When the row does not fit,
|
|
4561
|
+
it scrolls sideways with its arrows (`yui_toolbar()`). It never wraps into
|
|
4562
|
+
a second row.
|
|
4563
|
+
|
|
4564
|
+
There is one exception. The records of a timeranger2 topic do not obey
|
|
4565
|
+
point 3, because a topic can hold millions of records. Those tables page
|
|
4566
|
+
from the backend (remote pagination). They obey points 1, 2 and 4.
|
|
4567
|
+
|
|
4568
|
+
How to write it: the table with `yui_table_standard.js` (see
|
|
4569
|
+
[The standard table](#the-standard-table-yui_table_standardjs)), the
|
|
4570
|
+
toolbar with `yui_toolbar()`, each group of controls in a
|
|
4571
|
+
`yui-horizontal-toolbar-section`:
|
|
4572
|
+
|
|
4573
|
+
```js
|
|
4574
|
+
import {yui_toolbar} from "@yuneta/gobj-ui/src/yui_toolbar.js";
|
|
4575
|
+
|
|
4576
|
+
let $toolbar = yui_toolbar({class: "ACCOUNTS_TOOLBAR"}, [
|
|
4577
|
+
["div", {class: "ACCOUNTS_ACTIONS yui-horizontal-toolbar-section"}, [$new]],
|
|
4578
|
+
["div", {class: "ACCOUNTS_TOOLS yui-horizontal-toolbar-section"}, [$search, $refresh]],
|
|
4579
|
+
]);
|
|
4580
|
+
```
|
|
4581
|
+
|
|
4582
|
+
`C_YUI_TREEDB_TOPIC_WITH_FORM` obeys the rule with no work from its host
|
|
4583
|
+
since 7.32.1. Up to 7.32.0 it hid the paginator when all the rows fit, and
|
|
4584
|
+
its toolbar wrapped into two rows on a phone.
|
|
4585
|
+
|
|
4586
|
+
How to make sure that a table obeys it: open the DEPLOYED page at 390 px.
|
|
4587
|
+
Each control of the toolbar is on one line, the paginator
|
|
4588
|
+
(`.tabulator-paginator`) has a width with one page of rows, and each column
|
|
4589
|
+
of data has a filter box.
|
|
4590
|
+
|
|
4591
|
+
Why each point:
|
|
4592
|
+
|
|
4593
|
+
- The footer is where a reader looks for the row count and the page size.
|
|
4594
|
+
A control that comes and goes with the number of rows is a control that
|
|
4595
|
+
the reader must look for. The same footer in each table also tells the
|
|
4596
|
+
reader that it is the same kind of table.
|
|
4597
|
+
- A filter and a sort work on the rows that the browser holds. With remote
|
|
4598
|
+
pages, a filter searches one page, and "nothing found" can be false. A
|
|
4599
|
+
treedb is a memory database, so the backend holds the whole topic anyway.
|
|
4600
|
+
- A toolbar that wraps takes a row from the table on a phone. It also puts
|
|
4601
|
+
the same button in a different place on each screen width. A row that
|
|
4602
|
+
scrolls keeps each button in its place.
|
|
4603
|
+
|
|
4479
4604
|
### `index.html`: title, metadata and the Content-Security-Policy
|
|
4480
4605
|
|
|
4481
4606
|
The vite plugin `yunetaHtmlPlugin` (`vite-plugin-yuneta-html.js`) fills
|
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -8897,7 +8897,8 @@ function tabulator_strings(t) {
|
|
|
8897
8897
|
prev_title: tr("prev page", "Prev Page"),
|
|
8898
8898
|
next: tr("next", "Next"),
|
|
8899
8899
|
next_title: tr("next page", "Next Page"),
|
|
8900
|
-
all: tr("all", "All")
|
|
8900
|
+
all: tr("all", "All"),
|
|
8901
|
+
counter: { rows: tr("rows", "rows") }
|
|
8901
8902
|
},
|
|
8902
8903
|
headerFilters: { default: tr("filter column", "filter column...") }
|
|
8903
8904
|
};
|
|
@@ -59004,6 +59005,17 @@ function topic_is_shown(topic_name) {
|
|
|
59004
59005
|
return topic_name.substring(0, 2) !== "__" || topic_name === "__icons__";
|
|
59005
59006
|
}
|
|
59006
59007
|
/************************************************************
|
|
59008
|
+
* The topics in ALPHABETICAL order, for the cards, the tabs
|
|
59009
|
+
* and the site map: the backend's order is not the same from
|
|
59010
|
+
* one load to the next, and a reader finds a topic by its
|
|
59011
|
+
* place. The system topics (__*__) sort first.
|
|
59012
|
+
************************************************************/
|
|
59013
|
+
function sorted_topic_names(descs) {
|
|
59014
|
+
return Object.keys(descs).sort((a, b) => {
|
|
59015
|
+
return a.localeCompare(b);
|
|
59016
|
+
});
|
|
59017
|
+
}
|
|
59018
|
+
/************************************************************
|
|
59007
59019
|
* The nodes of __icons__ are the user icons of the app: each
|
|
59008
59020
|
* load and each write of them goes to the icon registry
|
|
59009
59021
|
* (lib_icons.js), and the shell tells the views that decided
|
|
@@ -59039,7 +59051,8 @@ function process_treedb_descs$1(gobj) {
|
|
|
59039
59051
|
let system = (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "system");
|
|
59040
59052
|
let treedb_name = (0, _yuneta_gobj_js.gobj_read_str_attr)(gobj, "treedb_name");
|
|
59041
59053
|
let readonly = (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "readonly");
|
|
59042
|
-
for (const
|
|
59054
|
+
for (const key of sorted_topic_names(descs)) {
|
|
59055
|
+
let desc = descs[key];
|
|
59043
59056
|
if (!system && !topic_is_shown(key)) continue;
|
|
59044
59057
|
let kw_topic_form = {
|
|
59045
59058
|
subscriber: gobj,
|
|
@@ -59100,7 +59113,7 @@ function register_sub_routes$1(gobj) {
|
|
|
59100
59113
|
icon: "yi-compass-drafting",
|
|
59101
59114
|
gclass: "C_YUI_TREEDB_SCHEMA"
|
|
59102
59115
|
});
|
|
59103
|
-
if ((0, _yuneta_gobj_js.is_object)(descs)) for (let topic of
|
|
59116
|
+
if ((0, _yuneta_gobj_js.is_object)(descs)) for (let topic of sorted_topic_names(descs)) {
|
|
59104
59117
|
if (!system && !topic_is_shown(topic)) continue;
|
|
59105
59118
|
nodes.push({
|
|
59106
59119
|
route: base + "/" + topic,
|
|
@@ -61926,7 +61939,7 @@ function build_ui$5(gobj) {
|
|
|
61926
61939
|
},
|
|
61927
61940
|
[["div", {
|
|
61928
61941
|
class: "TREEDB_TABLE_TOOLBAR toolbar_tabulator_table m-1",
|
|
61929
|
-
style: "flex:none;
|
|
61942
|
+
style: "flex:none; min-width:0;"
|
|
61930
61943
|
}], ["div", {
|
|
61931
61944
|
id: `${table_id}`,
|
|
61932
61945
|
style: "margin-top:0px !important; flex:1 1 auto; min-height:0;"
|
|
@@ -61987,9 +62000,10 @@ function build_ui$5(gobj) {
|
|
|
61987
62000
|
gobj.priv.$parent_filter = $parent_filter;
|
|
61988
62001
|
$container.insertBefore($parent_filter, find_by_id($container, table_id));
|
|
61989
62002
|
let $toolbar_slot = $container.querySelector(".toolbar_tabulator_table");
|
|
61990
|
-
|
|
61991
|
-
|
|
61992
|
-
$
|
|
62003
|
+
let $actions = $table_toolbar instanceof Element ? $table_toolbar : (0, _yuneta_gobj_js.createElement2)(["div", {}]);
|
|
62004
|
+
$actions.classList.add("yui-horizontal-toolbar-section");
|
|
62005
|
+
$view_toolbar.classList.add("yui-horizontal-toolbar-section");
|
|
62006
|
+
$toolbar_slot.appendChild(yui_toolbar({ class: "TREEDB_TABLE_BAR" }, [$actions, $view_toolbar]));
|
|
61993
62007
|
(0, _yuneta_gobj_js.gobj_write_attr)(gobj, "$container", $container);
|
|
61994
62008
|
(0, _yuneta_gobj_js.refresh_language)($container, i18next.t);
|
|
61995
62009
|
}
|
|
@@ -62456,33 +62470,6 @@ function create_tabulator(gobj) {
|
|
|
62456
62470
|
let total = gobj.priv._page_total;
|
|
62457
62471
|
if (paged && typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${(0, i18next.t)("rows")}`;
|
|
62458
62472
|
else $rc.textContent = `${n} ${(0, i18next.t)("rows")}`;
|
|
62459
|
-
let single_page = true;
|
|
62460
|
-
try {
|
|
62461
|
-
if (paged) {
|
|
62462
|
-
let max = tabulator.getPageMax();
|
|
62463
|
-
single_page = max === false || max <= 1;
|
|
62464
|
-
} else {
|
|
62465
|
-
let size = tabulator.getPageSize();
|
|
62466
|
-
single_page = size === true || !size || n <= size;
|
|
62467
|
-
}
|
|
62468
|
-
} catch (e) {
|
|
62469
|
-
single_page = true;
|
|
62470
|
-
}
|
|
62471
|
-
let total_rows;
|
|
62472
|
-
if (paged) total_rows = total;
|
|
62473
|
-
else try {
|
|
62474
|
-
total_rows = tabulator.getDataCount();
|
|
62475
|
-
} catch (e) {
|
|
62476
|
-
total_rows = n;
|
|
62477
|
-
}
|
|
62478
|
-
let min_size = 0;
|
|
62479
|
-
let sizes = tabulator.options ? tabulator.options.paginationSizeSelector : null;
|
|
62480
|
-
if (Array.isArray(sizes)) sizes.forEach(function(size) {
|
|
62481
|
-
if (typeof size === "number" && (!min_size || size < min_size)) min_size = size;
|
|
62482
|
-
});
|
|
62483
|
-
let no_paginator = single_page && (!min_size || typeof total_rows !== "number" || total_rows <= min_size);
|
|
62484
|
-
tabulator.element.classList.toggle("yui-single-page", single_page);
|
|
62485
|
-
tabulator.element.classList.toggle("yui-no-paginator", no_paginator);
|
|
62486
62473
|
}
|
|
62487
62474
|
tabulator.on("columnsLoaded", function() {
|
|
62488
62475
|
yui_tabulator_name_filters(tabulator, i18next.t);
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -8892,7 +8892,8 @@ function tabulator_strings(t) {
|
|
|
8892
8892
|
prev_title: tr("prev page", "Prev Page"),
|
|
8893
8893
|
next: tr("next", "Next"),
|
|
8894
8894
|
next_title: tr("next page", "Next Page"),
|
|
8895
|
-
all: tr("all", "All")
|
|
8895
|
+
all: tr("all", "All"),
|
|
8896
|
+
counter: { rows: tr("rows", "rows") }
|
|
8896
8897
|
},
|
|
8897
8898
|
headerFilters: { default: tr("filter column", "filter column...") }
|
|
8898
8899
|
};
|
|
@@ -58999,6 +59000,17 @@ function topic_is_shown(topic_name) {
|
|
|
58999
59000
|
return topic_name.substring(0, 2) !== "__" || topic_name === "__icons__";
|
|
59000
59001
|
}
|
|
59001
59002
|
/************************************************************
|
|
59003
|
+
* The topics in ALPHABETICAL order, for the cards, the tabs
|
|
59004
|
+
* and the site map: the backend's order is not the same from
|
|
59005
|
+
* one load to the next, and a reader finds a topic by its
|
|
59006
|
+
* place. The system topics (__*__) sort first.
|
|
59007
|
+
************************************************************/
|
|
59008
|
+
function sorted_topic_names(descs) {
|
|
59009
|
+
return Object.keys(descs).sort((a, b) => {
|
|
59010
|
+
return a.localeCompare(b);
|
|
59011
|
+
});
|
|
59012
|
+
}
|
|
59013
|
+
/************************************************************
|
|
59002
59014
|
* The nodes of __icons__ are the user icons of the app: each
|
|
59003
59015
|
* load and each write of them goes to the icon registry
|
|
59004
59016
|
* (lib_icons.js), and the shell tells the views that decided
|
|
@@ -59034,7 +59046,8 @@ function process_treedb_descs$1(gobj) {
|
|
|
59034
59046
|
let system = gobj_read_bool_attr(gobj, "system");
|
|
59035
59047
|
let treedb_name = gobj_read_str_attr(gobj, "treedb_name");
|
|
59036
59048
|
let readonly = gobj_read_bool_attr(gobj, "readonly");
|
|
59037
|
-
for (const
|
|
59049
|
+
for (const key of sorted_topic_names(descs)) {
|
|
59050
|
+
let desc = descs[key];
|
|
59038
59051
|
if (!system && !topic_is_shown(key)) continue;
|
|
59039
59052
|
let kw_topic_form = {
|
|
59040
59053
|
subscriber: gobj,
|
|
@@ -59095,7 +59108,7 @@ function register_sub_routes$1(gobj) {
|
|
|
59095
59108
|
icon: "yi-compass-drafting",
|
|
59096
59109
|
gclass: "C_YUI_TREEDB_SCHEMA"
|
|
59097
59110
|
});
|
|
59098
|
-
if (is_object(descs)) for (let topic of
|
|
59111
|
+
if (is_object(descs)) for (let topic of sorted_topic_names(descs)) {
|
|
59099
59112
|
if (!system && !topic_is_shown(topic)) continue;
|
|
59100
59113
|
nodes.push({
|
|
59101
59114
|
route: base + "/" + topic,
|
|
@@ -61921,7 +61934,7 @@ function build_ui$5(gobj) {
|
|
|
61921
61934
|
},
|
|
61922
61935
|
[["div", {
|
|
61923
61936
|
class: "TREEDB_TABLE_TOOLBAR toolbar_tabulator_table m-1",
|
|
61924
|
-
style: "flex:none;
|
|
61937
|
+
style: "flex:none; min-width:0;"
|
|
61925
61938
|
}], ["div", {
|
|
61926
61939
|
id: `${table_id}`,
|
|
61927
61940
|
style: "margin-top:0px !important; flex:1 1 auto; min-height:0;"
|
|
@@ -61982,9 +61995,10 @@ function build_ui$5(gobj) {
|
|
|
61982
61995
|
gobj.priv.$parent_filter = $parent_filter;
|
|
61983
61996
|
$container.insertBefore($parent_filter, find_by_id($container, table_id));
|
|
61984
61997
|
let $toolbar_slot = $container.querySelector(".toolbar_tabulator_table");
|
|
61985
|
-
|
|
61986
|
-
|
|
61987
|
-
$
|
|
61998
|
+
let $actions = $table_toolbar instanceof Element ? $table_toolbar : createElement2(["div", {}]);
|
|
61999
|
+
$actions.classList.add("yui-horizontal-toolbar-section");
|
|
62000
|
+
$view_toolbar.classList.add("yui-horizontal-toolbar-section");
|
|
62001
|
+
$toolbar_slot.appendChild(yui_toolbar({ class: "TREEDB_TABLE_BAR" }, [$actions, $view_toolbar]));
|
|
61988
62002
|
gobj_write_attr(gobj, "$container", $container);
|
|
61989
62003
|
refresh_language($container, t);
|
|
61990
62004
|
}
|
|
@@ -62451,33 +62465,6 @@ function create_tabulator(gobj) {
|
|
|
62451
62465
|
let total = gobj.priv._page_total;
|
|
62452
62466
|
if (paged && typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${t("rows")}`;
|
|
62453
62467
|
else $rc.textContent = `${n} ${t("rows")}`;
|
|
62454
|
-
let single_page = true;
|
|
62455
|
-
try {
|
|
62456
|
-
if (paged) {
|
|
62457
|
-
let max = tabulator.getPageMax();
|
|
62458
|
-
single_page = max === false || max <= 1;
|
|
62459
|
-
} else {
|
|
62460
|
-
let size = tabulator.getPageSize();
|
|
62461
|
-
single_page = size === true || !size || n <= size;
|
|
62462
|
-
}
|
|
62463
|
-
} catch (e) {
|
|
62464
|
-
single_page = true;
|
|
62465
|
-
}
|
|
62466
|
-
let total_rows;
|
|
62467
|
-
if (paged) total_rows = total;
|
|
62468
|
-
else try {
|
|
62469
|
-
total_rows = tabulator.getDataCount();
|
|
62470
|
-
} catch (e) {
|
|
62471
|
-
total_rows = n;
|
|
62472
|
-
}
|
|
62473
|
-
let min_size = 0;
|
|
62474
|
-
let sizes = tabulator.options ? tabulator.options.paginationSizeSelector : null;
|
|
62475
|
-
if (Array.isArray(sizes)) sizes.forEach(function(size) {
|
|
62476
|
-
if (typeof size === "number" && (!min_size || size < min_size)) min_size = size;
|
|
62477
|
-
});
|
|
62478
|
-
let no_paginator = single_page && (!min_size || typeof total_rows !== "number" || total_rows <= min_size);
|
|
62479
|
-
tabulator.element.classList.toggle("yui-single-page", single_page);
|
|
62480
|
-
tabulator.element.classList.toggle("yui-no-paginator", no_paginator);
|
|
62481
62468
|
}
|
|
62482
62469
|
tabulator.on("columnsLoaded", function() {
|
|
62483
62470
|
yui_tabulator_name_filters(tabulator, t);
|
package/package.json
CHANGED
|
@@ -23,62 +23,27 @@
|
|
|
23
23
|
line-height: 1.5;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/* No choice in the selector would change anything either — the topic is
|
|
37
|
-
* smaller than the smallest page size it offers — so the whole strip,
|
|
38
|
-
* label and select included, is noise. */
|
|
39
|
-
.tabulator.yui-no-paginator .tabulator-footer .tabulator-paginator {
|
|
40
|
-
display: none;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/* Toolbar wrapping discipline (mobile): the record-buttons group
|
|
44
|
-
* must never split across lines — Bulma .buttons wraps internally,
|
|
45
|
-
* which stacked the toolbar into 3 rows on narrow phones. Keep the
|
|
46
|
-
* group on one line and scroll it horizontally if it overflows
|
|
47
|
-
* (same distribute-or-scroll pattern as the nav icon-bar); the
|
|
48
|
-
* search+refresh block then wraps as a whole, so the toolbar is
|
|
49
|
-
* 1 row when it fits and exactly 2 when it doesn't. */
|
|
26
|
+
/* The toolbar is ONE row: a `yui_toolbar()` that scrolls sideways when
|
|
27
|
+
* it does not fit, with its arrows (README, "Conventions" -> "A table: a
|
|
28
|
+
* filter on every column, the paginator always, the toolbar in one
|
|
29
|
+
* row"). Up to 7.32.0 it wrapped: the record buttons on one row and the
|
|
30
|
+
* search with the tools on a second one, which on a phone left one row
|
|
31
|
+
* of the table less.
|
|
32
|
+
*
|
|
33
|
+
* The two groups (record actions, tools) are sections of the toolbar
|
|
34
|
+
* (`yui-horizontal-toolbar-section`: no shrink, no wrap). Bulma's
|
|
35
|
+
* `.buttons` wraps its buttons by itself, so that is undone here. */
|
|
50
36
|
.toolbar_tabulator_table .buttons {
|
|
51
37
|
flex-wrap: nowrap;
|
|
52
|
-
overflow-x: auto;
|
|
53
|
-
scrollbar-width: thin;
|
|
54
|
-
}
|
|
55
|
-
.toolbar_tabulator_table .control.has-icons-left {
|
|
56
|
-
min-width: 0;
|
|
57
38
|
}
|
|
58
39
|
|
|
59
|
-
/*
|
|
60
|
-
*
|
|
61
|
-
.TREEDB_TABLE_TOOLS .TREEDB_TABLE_SEARCH
|
|
62
|
-
|
|
40
|
+
/* The search keeps a fixed width in the row: in a row that scrolls, a
|
|
41
|
+
* box that stretches has nothing to stretch to. */
|
|
42
|
+
.TREEDB_TABLE_TOOLS .TREEDB_TABLE_SEARCH {
|
|
43
|
+
flex: none;
|
|
63
44
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* own, with the search stretched across it and the refresh pinned at
|
|
67
|
-
* the end. Without this the group keeps its natural width and leaves
|
|
68
|
-
* dead space, while the search -- the most used control of the two --
|
|
69
|
-
* stays the narrowest thing on screen. The refresh label is already
|
|
70
|
-
* dropped by is-hidden-mobile, decided in the markup: measuring at
|
|
71
|
-
* runtime would change the shape of the bar on a language switch. */
|
|
72
|
-
@media screen and (max-width: 768px) {
|
|
73
|
-
.TREEDB_TABLE_TOOLS {
|
|
74
|
-
width: 100%;
|
|
75
|
-
}
|
|
76
|
-
.TREEDB_TABLE_TOOLS .TREEDB_TABLE_SEARCH {
|
|
77
|
-
flex: 1 1 auto;
|
|
78
|
-
}
|
|
79
|
-
.TREEDB_TABLE_TOOLS .TREEDB_TABLE_SEARCH .input {
|
|
80
|
-
max-width: none;
|
|
81
|
-
}
|
|
45
|
+
.TREEDB_TABLE_TOOLS .TREEDB_TABLE_SEARCH .input {
|
|
46
|
+
width: 12rem;
|
|
82
47
|
}
|
|
83
48
|
|
|
84
49
|
/* The edit/create form runs in the shell's standardized adaptive dialog
|
|
@@ -102,7 +102,7 @@ import {row_matches} from "./yui_row_search.js";
|
|
|
102
102
|
import i18next, {t} from "i18next";
|
|
103
103
|
import {safe_locale} from "./yui_date_text.js";
|
|
104
104
|
|
|
105
|
-
import {yui_toolbar_icon} from "./yui_toolbar.js";
|
|
105
|
+
import {yui_toolbar, yui_toolbar_icon} from "./yui_toolbar.js";
|
|
106
106
|
|
|
107
107
|
import {
|
|
108
108
|
plan_treedb_writes, READONLY_FORM_TOOLBAR, col_goes_back_to_treedb,
|
|
@@ -960,8 +960,7 @@ function build_ui(gobj)
|
|
|
960
960
|
['div', {class: 'C_YUI_TREEDB_TOPIC_WITH_FORM',
|
|
961
961
|
style: 'height:100%; min-height:0; display:flex; flex-direction:column;'}, [
|
|
962
962
|
['div', {class: 'TREEDB_TABLE_TOOLBAR toolbar_tabulator_table m-1',
|
|
963
|
-
style: 'flex:none;
|
|
964
|
-
'align-items:center; flex-wrap:wrap;'}],
|
|
963
|
+
style: 'flex:none; min-width:0;'}],
|
|
965
964
|
['div',
|
|
966
965
|
{
|
|
967
966
|
id: `${table_id}`,
|
|
@@ -1012,13 +1011,18 @@ function build_ui(gobj)
|
|
|
1012
1011
|
gobj.priv.$parent_filter = $parent_filter;
|
|
1013
1012
|
$container.insertBefore($parent_filter, find_by_id($container, table_id));
|
|
1014
1013
|
|
|
1014
|
+
/* ONE row, the record actions on the left and the tools on the
|
|
1015
|
+
* right, scrolled sideways when it does not fit -- never wrapped
|
|
1016
|
+
* into two (see the css). The two groups are sections of the
|
|
1017
|
+
* toolbar: they do not shrink and do not wrap. */
|
|
1015
1018
|
let $toolbar_slot = $container.querySelector('.toolbar_tabulator_table');
|
|
1016
|
-
|
|
1017
|
-
$
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1019
|
+
let $actions = ($table_toolbar instanceof Element)?
|
|
1020
|
+
$table_toolbar : createElement2(['div', {}]);
|
|
1021
|
+
$actions.classList.add('yui-horizontal-toolbar-section');
|
|
1022
|
+
$view_toolbar.classList.add('yui-horizontal-toolbar-section');
|
|
1023
|
+
$toolbar_slot.appendChild(
|
|
1024
|
+
yui_toolbar({class: 'TREEDB_TABLE_BAR'}, [$actions, $view_toolbar])
|
|
1025
|
+
);
|
|
1022
1026
|
|
|
1023
1027
|
gobj_write_attr(gobj, "$container", $container);
|
|
1024
1028
|
refresh_language($container, t);
|
|
@@ -1801,9 +1805,13 @@ function create_tabulator(gobj)
|
|
|
1801
1805
|
$table_el.classList.add("yui-no-row-hover");
|
|
1802
1806
|
}
|
|
1803
1807
|
|
|
1804
|
-
/* Keep the footer in sync with the visible (active) row count
|
|
1805
|
-
*
|
|
1806
|
-
*
|
|
1808
|
+
/* Keep the footer in sync with the visible (active) row count.
|
|
1809
|
+
* The paginator is NOT hidden when everything fits in one page:
|
|
1810
|
+
* a standard table shows it always (README, "Conventions" -> "A
|
|
1811
|
+
* table: a filter on every column, the paginator always, the
|
|
1812
|
+
* toolbar in one row"). Up to 7.32.0 it was hidden then, and the
|
|
1813
|
+
* footer of a small topic did not look like the footer of a big
|
|
1814
|
+
* one. */
|
|
1807
1815
|
/* `explicit_count` is for the ONE caller that cannot ask the table:
|
|
1808
1816
|
* `dataFiltered` is dispatched from INSIDE Tabulator's filter(), which
|
|
1809
1817
|
* only RETURNS the surviving rows to the pipeline afterwards — so
|
|
@@ -1839,64 +1847,6 @@ function create_tabulator(gobj)
|
|
|
1839
1847
|
} else {
|
|
1840
1848
|
$rc.textContent = `${n} ${t("rows")}`;
|
|
1841
1849
|
}
|
|
1842
|
-
|
|
1843
|
-
let single_page = true;
|
|
1844
|
-
try {
|
|
1845
|
-
if(paged) {
|
|
1846
|
-
/* Tabulator knows the last page from the answer's
|
|
1847
|
-
* `last_page`, and that is the only thing that says whether
|
|
1848
|
-
* there is more. Deriving it from the row count instead —
|
|
1849
|
-
* which is what the local path does — hid the paginator on
|
|
1850
|
-
* every FULL page: 50 rows of a 50-row page reads as "it all
|
|
1851
|
-
* fits" and it does not. */
|
|
1852
|
-
let max = tabulator.getPageMax();
|
|
1853
|
-
single_page = (max === false) || max <= 1;
|
|
1854
|
-
} else {
|
|
1855
|
-
/* Derived from the count and the page size rather than read
|
|
1856
|
-
* from getPageMax(), which is stale in the filter path.
|
|
1857
|
-
* `true` is Tabulator's "All" and it is the SIZE itself, so
|
|
1858
|
-
* it has to be read as a word: compared as a number it is 1,
|
|
1859
|
-
* and a table showing every one of its 300 rows in a single
|
|
1860
|
-
* page answered that it needed 300 pages. */
|
|
1861
|
-
let size = tabulator.getPageSize();
|
|
1862
|
-
single_page = (size === true) || !size || n <= size;
|
|
1863
|
-
}
|
|
1864
|
-
} catch(e) {
|
|
1865
|
-
single_page = true;
|
|
1866
|
-
}
|
|
1867
|
-
/* The page-size selector lives INSIDE the paginator, so hiding the
|
|
1868
|
-
* whole strip when everything fits took away the very control that
|
|
1869
|
-
* got the reader there: pick "All" on a topic of 300 rows and the
|
|
1870
|
-
* table becomes one page, the paginator goes, and 50 is
|
|
1871
|
-
* unreachable. The selector is noise only when no choice in it
|
|
1872
|
-
* would change anything -- when the topic is smaller than the
|
|
1873
|
-
* smallest size it offers. Measure that on the WHOLE topic, never
|
|
1874
|
-
* on the filtered count, or typing a filter that leaves 3 rows
|
|
1875
|
-
* takes the selector away too. */
|
|
1876
|
-
let total_rows;
|
|
1877
|
-
if(paged) {
|
|
1878
|
-
total_rows = total;
|
|
1879
|
-
} else {
|
|
1880
|
-
try {
|
|
1881
|
-
total_rows = tabulator.getDataCount();
|
|
1882
|
-
} catch(e) {
|
|
1883
|
-
total_rows = n;
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
let min_size = 0;
|
|
1887
|
-
let sizes = tabulator.options? tabulator.options.paginationSizeSelector : null;
|
|
1888
|
-
if(Array.isArray(sizes)) {
|
|
1889
|
-
sizes.forEach(function(size) {
|
|
1890
|
-
if(typeof size === "number" && (!min_size || size < min_size)) {
|
|
1891
|
-
min_size = size;
|
|
1892
|
-
}
|
|
1893
|
-
});
|
|
1894
|
-
}
|
|
1895
|
-
let no_paginator = single_page &&
|
|
1896
|
-
(!min_size || typeof total_rows !== "number" || total_rows <= min_size);
|
|
1897
|
-
|
|
1898
|
-
tabulator.element.classList.toggle("yui-single-page", single_page);
|
|
1899
|
-
tabulator.element.classList.toggle("yui-no-paginator", no_paginator);
|
|
1900
1850
|
}
|
|
1901
1851
|
|
|
1902
1852
|
/* `columnsLoaded` and not only `tableBuilt`: EVERY rebuild of the
|
|
@@ -1269,6 +1269,19 @@ function topic_is_shown(topic_name)
|
|
|
1269
1269
|
return topic_name.substring(0, 2) !== "__" || topic_name === ICONS_TOPIC;
|
|
1270
1270
|
}
|
|
1271
1271
|
|
|
1272
|
+
/************************************************************
|
|
1273
|
+
* The topics in ALPHABETICAL order, for the cards, the tabs
|
|
1274
|
+
* and the site map: the backend's order is not the same from
|
|
1275
|
+
* one load to the next, and a reader finds a topic by its
|
|
1276
|
+
* place. The system topics (__*__) sort first.
|
|
1277
|
+
************************************************************/
|
|
1278
|
+
function sorted_topic_names(descs)
|
|
1279
|
+
{
|
|
1280
|
+
return Object.keys(descs).sort((a, b) => {
|
|
1281
|
+
return a.localeCompare(b);
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1272
1285
|
/************************************************************
|
|
1273
1286
|
* The nodes of __icons__ are the user icons of the app: each
|
|
1274
1287
|
* load and each write of them goes to the icon registry
|
|
@@ -1322,7 +1335,8 @@ function process_treedb_descs(gobj)
|
|
|
1322
1335
|
let system = gobj_read_bool_attr(gobj, "system");
|
|
1323
1336
|
let treedb_name = gobj_read_str_attr(gobj, "treedb_name");
|
|
1324
1337
|
let readonly = gobj_read_bool_attr(gobj, "readonly");
|
|
1325
|
-
for(const
|
|
1338
|
+
for(const key of sorted_topic_names(descs)) {
|
|
1339
|
+
let desc = descs[key];
|
|
1326
1340
|
if(!system && !topic_is_shown(key)) {
|
|
1327
1341
|
continue;
|
|
1328
1342
|
}
|
|
@@ -1454,7 +1468,7 @@ function register_sub_routes(gobj)
|
|
|
1454
1468
|
icon: "yi-compass-drafting", gclass: "C_YUI_TREEDB_SCHEMA"});
|
|
1455
1469
|
}
|
|
1456
1470
|
if(is_object(descs)) {
|
|
1457
|
-
for(let topic of
|
|
1471
|
+
for(let topic of sorted_topic_names(descs)) {
|
|
1458
1472
|
if(!system && !topic_is_shown(topic)) {
|
|
1459
1473
|
continue;
|
|
1460
1474
|
}
|
|
@@ -34,7 +34,7 @@ const {
|
|
|
34
34
|
SDATA, SDATA_END, data_type_t, event_flag_t,
|
|
35
35
|
gclass_create,
|
|
36
36
|
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
|
|
37
|
-
gobj_start, gobj_send_event,
|
|
37
|
+
gobj_start, gobj_send_event, gobj_write_attr,
|
|
38
38
|
gobj_change_state, gobj_current_state,
|
|
39
39
|
set_log_callback,
|
|
40
40
|
} = gobj_js;
|
|
@@ -113,10 +113,16 @@ beforeAll(() => {
|
|
|
113
113
|
["EV_LOAD_NODES", ac_form_load, null],
|
|
114
114
|
["EV_LOAD_NODE_UPDATED", ac_form_update, null]
|
|
115
115
|
]]],
|
|
116
|
-
{
|
|
116
|
+
{
|
|
117
|
+
/* What the view mounts as the topic's tab. */
|
|
118
|
+
mt_create: (gobj) => {
|
|
119
|
+
gobj_write_attr(gobj, "$container", document.createElement("div"));
|
|
120
|
+
}
|
|
121
|
+
},
|
|
117
122
|
0,
|
|
118
123
|
[
|
|
119
124
|
SDATA(data_type_t.DTP_STRING, "topic_name", 0, "", "topic"),
|
|
125
|
+
SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "the tab's content"),
|
|
120
126
|
SDATA(data_type_t.DTP_BOOLEAN, "with_remote_paging", 0, false, "pulls its pages"),
|
|
121
127
|
SDATA(data_type_t.DTP_POINTER, "tabulator", 0, null, "the table: only getRow() is read"),
|
|
122
128
|
SDATA_END()
|
|
@@ -833,3 +839,50 @@ describe("a link told as EV_TREEDB_NODE_LINKED / UNLINKED", () => {
|
|
|
833
839
|
expect(shown).toEqual([]);
|
|
834
840
|
});
|
|
835
841
|
});
|
|
842
|
+
|
|
843
|
+
/*
|
|
844
|
+
* The topics are shown in ALPHABETICAL order, whatever order the
|
|
845
|
+
* backend's `descs` comes in: the backend's order is not the same from
|
|
846
|
+
* one load to the next. The view loads its topics in the order it shows
|
|
847
|
+
* them, so the `nodes` requests tell that order.
|
|
848
|
+
*/
|
|
849
|
+
describe("the topics in alphabetical order", () => {
|
|
850
|
+
|
|
851
|
+
function load_descs(name, system)
|
|
852
|
+
{
|
|
853
|
+
const host = gobj_create(`${name}_host`, "C_TEST_VIEW_HOST", {}, yuno);
|
|
854
|
+
const topics = gobj_create_service(`${name}_topics`, "C_YUI_TREEDB_TOPICS", {
|
|
855
|
+
treedb_name: "treedb_test",
|
|
856
|
+
gobj_remote_yuno: remote,
|
|
857
|
+
system: system
|
|
858
|
+
}, host);
|
|
859
|
+
gobj_start(topics);
|
|
860
|
+
commands.length = 0;
|
|
861
|
+
const descs = {};
|
|
862
|
+
for(const topic of ["users", "__snaps__", "places", "__icons__",
|
|
863
|
+
"controllers", "__assets__", "device_types"]) {
|
|
864
|
+
descs[topic] = {topic_name: topic, cols: {}};
|
|
865
|
+
}
|
|
866
|
+
gobj_send_event(topics, "EV_MT_COMMAND_ANSWER", {
|
|
867
|
+
result: 0, comment: "", data: descs, __md_iev__: {
|
|
868
|
+
command_stack: [{command: "descs", kw: {}}]
|
|
869
|
+
}
|
|
870
|
+
}, remote);
|
|
871
|
+
return commands.filter((c) => c.command === "nodes")
|
|
872
|
+
.map((c) => c.kw.topic_name);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
test("every topic, the system ones first, when system is true", () => {
|
|
876
|
+
build("to0");
|
|
877
|
+
expect(load_descs("to1", true)).toEqual([
|
|
878
|
+
"__assets__", "__icons__", "__snaps__",
|
|
879
|
+
"controllers", "device_types", "places", "users"
|
|
880
|
+
]);
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
test("the user topics and __icons__, when system is false", () => {
|
|
884
|
+
expect(load_descs("to2", false)).toEqual([
|
|
885
|
+
"__icons__", "controllers", "device_types", "places", "users"
|
|
886
|
+
]);
|
|
887
|
+
});
|
|
888
|
+
});
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_table_standard.js
|
|
3
|
+
*
|
|
4
|
+
* THE STANDARD TABLE: what every table of an admin view has.
|
|
5
|
+
*
|
|
6
|
+
* The rule (README, "Conventions" -> "A table: a filter on
|
|
7
|
+
* every column, the paginator always, the toolbar in one
|
|
8
|
+
* row"):
|
|
9
|
+
*
|
|
10
|
+
* - a FILTER on every column that holds data;
|
|
11
|
+
* - the PAGINATOR at the bottom, always -- also when every
|
|
12
|
+
* row fits in one page -- with every row loaded in the
|
|
13
|
+
* browser (local pagination);
|
|
14
|
+
* - the toolbars above the table in ONE row, which scrolls
|
|
15
|
+
* sideways when it does not fit (`yui_toolbar()`).
|
|
16
|
+
*
|
|
17
|
+
* Three calls do the table's half of it:
|
|
18
|
+
*
|
|
19
|
+
* let table = new Tabulator($div, {
|
|
20
|
+
* ...yui_tabulator_lang(t),
|
|
21
|
+
* ...yui_table_paging(),
|
|
22
|
+
* columns: yui_table_filters(columns),
|
|
23
|
+
* });
|
|
24
|
+
* yui_table_wire(table, t);
|
|
25
|
+
*
|
|
26
|
+
* WHY THE PAGINATOR STAYS WHEN EVERYTHING FITS: the footer is
|
|
27
|
+
* where a reader looks for "how many", and a control that
|
|
28
|
+
* comes and goes with the number of rows is a control that
|
|
29
|
+
* has to be looked for. The table also has the same shape in
|
|
30
|
+
* every view, which is the point of a standard.
|
|
31
|
+
*
|
|
32
|
+
* WHY EVERY ROW IS LOADED: a filter and a sort work on what
|
|
33
|
+
* the browser holds. With remote pages, a filter searches one
|
|
34
|
+
* page and a "not found" is a lie. The exception is a store
|
|
35
|
+
* of records that cannot be loaded whole (the records of a
|
|
36
|
+
* timeranger2 topic), and it pages from the backend on
|
|
37
|
+
* purpose.
|
|
38
|
+
*
|
|
39
|
+
* The row count needs the key "rows" in the app (every app
|
|
40
|
+
* that shows a treedb table has it already).
|
|
41
|
+
*
|
|
42
|
+
* Copyright (c) 2026, ArtGins.
|
|
43
|
+
* All Rights Reserved.
|
|
44
|
+
***********************************************************************/
|
|
45
|
+
import {yui_tabulator_name_filters} from "./yui_tabulator_i18n.js";
|
|
46
|
+
import {yui_table_filter_clear} from "./yui_table_filter_clear.js";
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/* Rows per page, and the sizes the selector offers. `true` is
|
|
50
|
+
* Tabulator's "All". */
|
|
51
|
+
const YUI_TABLE_PAGE_SIZE = 25;
|
|
52
|
+
const YUI_TABLE_PAGE_SIZES = [25, 50, 100, true];
|
|
53
|
+
|
|
54
|
+
/* The width a column with a text filter needs: the placeholder in the
|
|
55
|
+
* LONGEST locale ("filtrar columna...", ~18 characters). The same
|
|
56
|
+
* floor as the treedb topic table. */
|
|
57
|
+
const YUI_TABLE_FILTER_MIN_WIDTH = 150;
|
|
58
|
+
|
|
59
|
+
/* Formatters whose cell is a CONTROL, not data: nothing to filter. */
|
|
60
|
+
const CONTROL_FORMATTERS = ["rowSelection", "handle", "responsiveCollapse", "buttonCross"];
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/***************************************************************
|
|
64
|
+
* The row count of the footer.
|
|
65
|
+
*
|
|
66
|
+
* Called by Tabulator with `this` = its pagination module, on
|
|
67
|
+
* every page, filter and data change. `total_rows` is the ACTIVE
|
|
68
|
+
* count: the rows the filters leave, all pages together.
|
|
69
|
+
*
|
|
70
|
+
* The number is data; the word comes from the table's locale
|
|
71
|
+
* (`pagination.counter.rows`, which `yui_tabulator_lang()` fills
|
|
72
|
+
* with the app's "rows"), and `langBind` changes it again when
|
|
73
|
+
* `yui_tabulator_relocalize()` installs a new language.
|
|
74
|
+
*
|
|
75
|
+
* Returns a DOM node, never a string: Tabulator puts a string in
|
|
76
|
+
* with `innerHTML`.
|
|
77
|
+
***************************************************************/
|
|
78
|
+
function rows_counter(page_size, current_row, current_page, total_rows)
|
|
79
|
+
{
|
|
80
|
+
let $count = document.createElement("span");
|
|
81
|
+
$count.className = "YUI_TABLE_COUNT";
|
|
82
|
+
|
|
83
|
+
let $number = document.createElement("span");
|
|
84
|
+
$number.className = "YUI_TABLE_COUNT_NUMBER";
|
|
85
|
+
$number.textContent = String(total_rows || 0);
|
|
86
|
+
|
|
87
|
+
let $word = document.createElement("span");
|
|
88
|
+
$word.className = "YUI_TABLE_COUNT_WORD";
|
|
89
|
+
$word.textContent = "rows";
|
|
90
|
+
let localize = this && this.table && this.table.modules ? this.table.modules.localize : null;
|
|
91
|
+
if(localize && typeof localize.langBind === "function") {
|
|
92
|
+
localize.langBind("pagination|counter|rows", (value) => {
|
|
93
|
+
$word.textContent = value;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
$count.appendChild($number);
|
|
98
|
+
$count.appendChild(document.createTextNode(" "));
|
|
99
|
+
$count.appendChild($word);
|
|
100
|
+
return $count;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/***************************************************************
|
|
104
|
+
* The pagination settings of a standard table.
|
|
105
|
+
*
|
|
106
|
+
* opts:
|
|
107
|
+
* size rows per page (default 25)
|
|
108
|
+
* sizes what the selector offers (default [25, 50, 100, true])
|
|
109
|
+
*
|
|
110
|
+
* Spread them into the Tabulator settings. Local pagination: the
|
|
111
|
+
* host gives the table every row (`data` or `setData()`).
|
|
112
|
+
***************************************************************/
|
|
113
|
+
function yui_table_paging(opts)
|
|
114
|
+
{
|
|
115
|
+
let o = opts || {};
|
|
116
|
+
let size = o.size || YUI_TABLE_PAGE_SIZE;
|
|
117
|
+
let sizes = Array.isArray(o.sizes) ? o.sizes.slice() : YUI_TABLE_PAGE_SIZES.slice();
|
|
118
|
+
if(typeof size === "number" && !sizes.includes(size)) {
|
|
119
|
+
sizes.unshift(size);
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
pagination: true,
|
|
123
|
+
paginationMode: "local",
|
|
124
|
+
paginationSize: size,
|
|
125
|
+
paginationSizeSelector: sizes,
|
|
126
|
+
paginationCounter: rows_counter
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/***************************************************************
|
|
131
|
+
* The columns, each with its header filter.
|
|
132
|
+
*
|
|
133
|
+
* A column gets a filter when it has a `field` and says nothing
|
|
134
|
+
* about one (`headerFilter` undefined):
|
|
135
|
+
*
|
|
136
|
+
* - a tick (`formatter: "tickCross"`) gets a three-state tick:
|
|
137
|
+
* any, yes, no;
|
|
138
|
+
* - any other gets a text box ("like": a part of the value, in
|
|
139
|
+
* any case), and a minimum width for the box, unless the
|
|
140
|
+
* column sets `width` or `minWidth` itself.
|
|
141
|
+
*
|
|
142
|
+
* A column that says something keeps it: its own filter, or
|
|
143
|
+
* `headerFilter: false` for a column whose cell is a control (a
|
|
144
|
+
* row of action buttons). A column with no field, or whose cell is
|
|
145
|
+
* a control by its formatter (the selection checkbox), gets none.
|
|
146
|
+
* The groups of columns are walked.
|
|
147
|
+
*
|
|
148
|
+
* The definitions are copied, never changed in place.
|
|
149
|
+
***************************************************************/
|
|
150
|
+
function yui_table_filters(columns)
|
|
151
|
+
{
|
|
152
|
+
if(!Array.isArray(columns)) {
|
|
153
|
+
return columns;
|
|
154
|
+
}
|
|
155
|
+
return columns.map((column) => {
|
|
156
|
+
if(!column || typeof column !== "object") {
|
|
157
|
+
return column;
|
|
158
|
+
}
|
|
159
|
+
if(Array.isArray(column.columns)) {
|
|
160
|
+
return {...column, columns: yui_table_filters(column.columns)};
|
|
161
|
+
}
|
|
162
|
+
if(!column.field || column.headerFilter !== undefined) {
|
|
163
|
+
return column;
|
|
164
|
+
}
|
|
165
|
+
if(CONTROL_FORMATTERS.includes(column.formatter)) {
|
|
166
|
+
return column;
|
|
167
|
+
}
|
|
168
|
+
if(column.formatter === "tickCross") {
|
|
169
|
+
return {
|
|
170
|
+
...column,
|
|
171
|
+
headerFilter: "tickCross",
|
|
172
|
+
headerFilterParams: {tristate: true}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
let filtered = {...column, headerFilter: "input"};
|
|
176
|
+
if(filtered.width === undefined && filtered.minWidth === undefined) {
|
|
177
|
+
filtered.minWidth = YUI_TABLE_FILTER_MIN_WIDTH;
|
|
178
|
+
}
|
|
179
|
+
return filtered;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/***************************************************************
|
|
184
|
+
* What the header filters need after the table is drawn.
|
|
185
|
+
*
|
|
186
|
+
* Tabulator draws the filter boxes with no name, and draws them
|
|
187
|
+
* again on every rebuild of the columns: each one gets its name
|
|
188
|
+
* ("filter by column") and its ✕ (`yui_table_filter_clear()`).
|
|
189
|
+
*
|
|
190
|
+
* Call it right after `new Tabulator(...)`: the table announces
|
|
191
|
+
* `tableBuilt` later.
|
|
192
|
+
***************************************************************/
|
|
193
|
+
function yui_table_wire(table, t)
|
|
194
|
+
{
|
|
195
|
+
if(!table || typeof table.on !== "function") {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
table.on("tableBuilt", () => {
|
|
199
|
+
yui_tabulator_name_filters(table, t);
|
|
200
|
+
yui_table_filter_clear(table);
|
|
201
|
+
});
|
|
202
|
+
table.on("columnsLoaded", () => {
|
|
203
|
+
yui_tabulator_name_filters(table, t);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export {
|
|
208
|
+
YUI_TABLE_PAGE_SIZE,
|
|
209
|
+
YUI_TABLE_PAGE_SIZES,
|
|
210
|
+
YUI_TABLE_FILTER_MIN_WIDTH,
|
|
211
|
+
yui_table_paging,
|
|
212
|
+
yui_table_filters,
|
|
213
|
+
yui_table_wire,
|
|
214
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_table_standard.test.js
|
|
3
|
+
*
|
|
4
|
+
* The standard table (yui_table_standard.js): a filter on every
|
|
5
|
+
* column that holds data, the paginator always with every row
|
|
6
|
+
* loaded, and the row count of the footer in the table's locale.
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2026, ArtGins.
|
|
9
|
+
* All Rights Reserved.
|
|
10
|
+
***********************************************************************/
|
|
11
|
+
import {describe, test, expect} from "vitest";
|
|
12
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
13
|
+
|
|
14
|
+
install_dom_double();
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
YUI_TABLE_FILTER_MIN_WIDTH,
|
|
18
|
+
yui_table_paging,
|
|
19
|
+
yui_table_filters,
|
|
20
|
+
yui_table_wire,
|
|
21
|
+
} from "./yui_table_standard.js";
|
|
22
|
+
|
|
23
|
+
describe("the paging", () => {
|
|
24
|
+
test("is local, always on, with the standard sizes", () => {
|
|
25
|
+
let s = yui_table_paging();
|
|
26
|
+
expect(s.pagination).toBe(true);
|
|
27
|
+
expect(s.paginationMode).toBe("local");
|
|
28
|
+
expect(s.paginationSize).toBe(25);
|
|
29
|
+
expect(s.paginationSizeSelector).toEqual([25, 50, 100, true]);
|
|
30
|
+
expect(typeof s.paginationCounter).toBe("function");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("a size of its own is offered by the selector", () => {
|
|
34
|
+
let s = yui_table_paging({size: 10});
|
|
35
|
+
expect(s.paginationSize).toBe(10);
|
|
36
|
+
expect(s.paginationSizeSelector).toEqual([10, 25, 50, 100, true]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("the sizes of the host are kept, and not shared between tables", () => {
|
|
40
|
+
let a = yui_table_paging({size: 50, sizes: [50, 200, true]});
|
|
41
|
+
expect(a.paginationSizeSelector).toEqual([50, 200, true]);
|
|
42
|
+
let b = yui_table_paging();
|
|
43
|
+
b.paginationSizeSelector.push(7);
|
|
44
|
+
expect(yui_table_paging().paginationSizeSelector).toEqual([25, 50, 100, true]);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("the row count", () => {
|
|
49
|
+
function page_module(word)
|
|
50
|
+
{
|
|
51
|
+
let bindings = [];
|
|
52
|
+
return {
|
|
53
|
+
bindings: bindings,
|
|
54
|
+
table: {
|
|
55
|
+
modules: {
|
|
56
|
+
localize: {
|
|
57
|
+
langBind(path, cb) {
|
|
58
|
+
bindings.push(path);
|
|
59
|
+
cb(word);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
test("says every active row, all pages together, in the table's language", () => {
|
|
68
|
+
let counter = yui_table_paging().paginationCounter;
|
|
69
|
+
let page = page_module("filas");
|
|
70
|
+
let $el = counter.call(page, 25, 26, 2, 113, 5);
|
|
71
|
+
expect($el.textContent).toBe("113 filas");
|
|
72
|
+
expect(page.bindings).toEqual(["pagination|counter|rows"]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("an empty table says 0", () => {
|
|
76
|
+
let counter = yui_table_paging().paginationCounter;
|
|
77
|
+
let $el = counter.call(page_module("rows"), 25, 0, 1, 0, 0);
|
|
78
|
+
expect($el.textContent).toBe("0 rows");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("is a node, never a string Tabulator would put in as html", () => {
|
|
82
|
+
let counter = yui_table_paging().paginationCounter;
|
|
83
|
+
let $el = counter.call(page_module("rows"), 25, 1, 1, 3, 1);
|
|
84
|
+
expect(typeof $el).toBe("object");
|
|
85
|
+
expect($el.className).toBe("YUI_TABLE_COUNT");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("without a localize module it still counts, in English", () => {
|
|
89
|
+
let counter = yui_table_paging().paginationCounter;
|
|
90
|
+
let $el = counter.call({}, 25, 1, 1, 3, 1);
|
|
91
|
+
expect($el.textContent).toBe("3 rows");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("the filters", () => {
|
|
96
|
+
test("a column of data gets a text box, and room for it", () => {
|
|
97
|
+
let [c] = yui_table_filters([{title: "Name", field: "name"}]);
|
|
98
|
+
expect(c.headerFilter).toBe("input");
|
|
99
|
+
expect(c.minWidth).toBe(YUI_TABLE_FILTER_MIN_WIDTH);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("a width set by the host is kept", () => {
|
|
103
|
+
let [a, b] = yui_table_filters([
|
|
104
|
+
{field: "a", width: 110},
|
|
105
|
+
{field: "b", minWidth: 220},
|
|
106
|
+
]);
|
|
107
|
+
expect(a.headerFilter).toBe("input");
|
|
108
|
+
expect(a.minWidth).toBeUndefined();
|
|
109
|
+
expect(a.width).toBe(110);
|
|
110
|
+
expect(b.minWidth).toBe(220);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("a tick gets a three-state tick", () => {
|
|
114
|
+
let [c] = yui_table_filters([{field: "enabled", formatter: "tickCross"}]);
|
|
115
|
+
expect(c.headerFilter).toBe("tickCross");
|
|
116
|
+
expect(c.headerFilterParams).toEqual({tristate: true});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("a column that says something keeps it", () => {
|
|
120
|
+
let own = {field: "kind", headerFilter: "list", headerFilterParams: {values: ["a"]}};
|
|
121
|
+
let off = {field: "user_id", headerFilter: false};
|
|
122
|
+
let [a, b] = yui_table_filters([own, off]);
|
|
123
|
+
expect(a).toBe(own);
|
|
124
|
+
expect(b).toBe(off);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("a control is not filtered: no field, or a control formatter", () => {
|
|
128
|
+
let none = {title: "", formatter: () => "x"};
|
|
129
|
+
let select = {field: "_select", formatter: "rowSelection"};
|
|
130
|
+
let [a, b] = yui_table_filters([none, select]);
|
|
131
|
+
expect(a.headerFilter).toBeUndefined();
|
|
132
|
+
expect(b.headerFilter).toBeUndefined();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("the groups are walked, and nothing is changed in place", () => {
|
|
136
|
+
let inner = {field: "x"};
|
|
137
|
+
let group = {title: "G", columns: [inner]};
|
|
138
|
+
let [g] = yui_table_filters([group]);
|
|
139
|
+
expect(g.columns[0].headerFilter).toBe("input");
|
|
140
|
+
expect(inner.headerFilter).toBeUndefined();
|
|
141
|
+
expect(group.columns[0]).toBe(inner);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("not a list: given back as it is", () => {
|
|
145
|
+
expect(yui_table_filters(null)).toBe(null);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("the wiring", () => {
|
|
150
|
+
test("names the filters when the table is built and on every rebuild", () => {
|
|
151
|
+
let events = {};
|
|
152
|
+
let table = {
|
|
153
|
+
on(name, fn) {
|
|
154
|
+
events[name] = fn;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
yui_table_wire(table, (k) => k);
|
|
158
|
+
expect(Object.keys(events).sort()).toEqual(["columnsLoaded", "tableBuilt"]);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("a table that is not there is ignored", () => {
|
|
162
|
+
expect(() => yui_table_wire(null, (k) => k)).not.toThrow();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -83,7 +83,13 @@ function tabulator_strings(t)
|
|
|
83
83
|
prev_title: tr("prev page", "Prev Page"),
|
|
84
84
|
next: tr("next", "Next"),
|
|
85
85
|
next_title: tr("next page", "Next Page"),
|
|
86
|
-
all: tr("all", "All")
|
|
86
|
+
all: tr("all", "All"),
|
|
87
|
+
/* The word of the row count of a standard table
|
|
88
|
+
* (yui_table_standard.js); the treedb topic table writes the
|
|
89
|
+
* same key in its own footer. */
|
|
90
|
+
counter: {
|
|
91
|
+
rows: tr("rows", "rows")
|
|
92
|
+
}
|
|
87
93
|
},
|
|
88
94
|
headerFilters: {
|
|
89
95
|
default: tr("filter column", "filter column...")
|