@yuneta/gobj-ui 7.32.0 → 7.32.2
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 +146 -2
- package/dist/gobj-ui.cjs.js +7 -32
- package/dist/gobj-ui.es.js +7 -32
- 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/yui_table_standard.js +278 -0
- package/src/yui_table_standard.test.js +212 -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
|
|
@@ -4351,6 +4351,90 @@ The app must define the i18n key **`"clear"`**. Three decisions are baked in:
|
|
|
4351
4351
|
they change. The walk is idempotent and gated by a single `querySelector`, so
|
|
4352
4352
|
repeating it on every render costs nothing.
|
|
4353
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
|
+
A tree table (`dataTree`) filters each column with
|
|
4405
|
+
`yui_tree_filter(text_of)`. Tabulator filters a tree from its roots, so a
|
|
4406
|
+
parent that fails is hidden with all its children: a filter on the name of
|
|
4407
|
+
a yuno hid every node. `text_of(data)` gives the text that a row shows in
|
|
4408
|
+
the column. A row passes when its own text holds the term, or when the text
|
|
4409
|
+
of one of its descendants does. Tabulator then filters the children with the
|
|
4410
|
+
same function, so only the children that match are shown:
|
|
4411
|
+
|
|
4412
|
+
```js
|
|
4413
|
+
{title: t("name"), field: "id",
|
|
4414
|
+
headerFilterFunc: yui_tree_filter((d) => d._type === "yuno" ? d.label : d.host)}
|
|
4415
|
+
```
|
|
4416
|
+
|
|
4417
|
+
`yui_table_filters()` gives that column its text box. The second argument of
|
|
4418
|
+
`yui_tree_filter()` is the `dataTreeChildField` of the table, `"_children"`
|
|
4419
|
+
by default.
|
|
4420
|
+
|
|
4421
|
+
`yui_table_wire(table, t)` names each filter box ("filter by column") and
|
|
4422
|
+
adds its ✕ (`yui_table_filter_clear()`). It does this when the table is
|
|
4423
|
+
built and again each time Tabulator builds the columns again. Call it right
|
|
4424
|
+
after `new Tabulator(...)`.
|
|
4425
|
+
|
|
4426
|
+
The app must define the keys `"rows"`, `"filter by column"` and `"clear"`,
|
|
4427
|
+
and the paginator keys of `yui_tabulator_lang()`.
|
|
4428
|
+
|
|
4429
|
+
Two things to look at when you apply it:
|
|
4430
|
+
|
|
4431
|
+
- A text filter compares the value of the row, not what the formatter
|
|
4432
|
+
shows. If a column shows a boolean as "Yes" or "No", give it a tick
|
|
4433
|
+
(`headerFilter: "tickCross"`, `headerFilterParams: {tristate: true}`) or
|
|
4434
|
+
a list.
|
|
4435
|
+
- A column with a fixed `width` under 150 px cuts the placeholder of its
|
|
4436
|
+
filter. Give it 150.
|
|
4437
|
+
|
|
4354
4438
|
### Searching a row that is not flat — `yui_row_search.js`
|
|
4355
4439
|
|
|
4356
4440
|
`row_matches(row, term)` is what the treedb topic table's search box uses, and
|
|
@@ -4477,6 +4561,66 @@ text is in the yunetas `CLAUDE.md` ("JS GUI conventions"); in short:
|
|
|
4477
4561
|
let $a = $c.querySelector(`a[data-route="${css_string(route)}"]`);
|
|
4478
4562
|
```
|
|
4479
4563
|
|
|
4564
|
+
### A table: a filter on every column, the paginator always, the toolbar in one row
|
|
4565
|
+
|
|
4566
|
+
Every table of an admin view obeys this rule. The admin views are the
|
|
4567
|
+
treedb editor of each app (`C_YUI_TREEDB_TOPICS`), the accounts views, and
|
|
4568
|
+
the tables of `gui_treedb` and `gui_agent`. Other tables can obey it too.
|
|
4569
|
+
|
|
4570
|
+
1. Each column that holds data has a header filter. A column whose cell is
|
|
4571
|
+
a control has none, for example the action buttons or the selection
|
|
4572
|
+
checkbox.
|
|
4573
|
+
2. The footer shows the paginator at all times, also when all the rows fit
|
|
4574
|
+
in one page.
|
|
4575
|
+
3. The table holds all its rows in the browser and pages them there. This
|
|
4576
|
+
is local pagination.
|
|
4577
|
+
4. Each toolbar above the table takes one row. When the row does not fit,
|
|
4578
|
+
it scrolls sideways with its arrows (`yui_toolbar()`). It never wraps into
|
|
4579
|
+
a second row.
|
|
4580
|
+
|
|
4581
|
+
There is one exception: the records of a timeranger2 topic. A topic can
|
|
4582
|
+
hold millions of records, so those tables do not obey point 3. They page
|
|
4583
|
+
from the backend (remote pagination). Their filters are the ones that the
|
|
4584
|
+
backend can apply, or they filter the page that is loaded, and the table
|
|
4585
|
+
says so. The live view of a topic holds a rolling buffer of the newest
|
|
4586
|
+
records, so it has no pages. These tables obey point 4.
|
|
4587
|
+
|
|
4588
|
+
How to write it: the table with `yui_table_standard.js` (see
|
|
4589
|
+
[The standard table](#the-standard-table-yui_table_standardjs)), the
|
|
4590
|
+
toolbar with `yui_toolbar()`, each group of controls in a
|
|
4591
|
+
`yui-horizontal-toolbar-section`:
|
|
4592
|
+
|
|
4593
|
+
```js
|
|
4594
|
+
import {yui_toolbar} from "@yuneta/gobj-ui/src/yui_toolbar.js";
|
|
4595
|
+
|
|
4596
|
+
let $toolbar = yui_toolbar({class: "ACCOUNTS_TOOLBAR"}, [
|
|
4597
|
+
["div", {class: "ACCOUNTS_ACTIONS yui-horizontal-toolbar-section"}, [$new]],
|
|
4598
|
+
["div", {class: "ACCOUNTS_TOOLS yui-horizontal-toolbar-section"}, [$search, $refresh]],
|
|
4599
|
+
]);
|
|
4600
|
+
```
|
|
4601
|
+
|
|
4602
|
+
`C_YUI_TREEDB_TOPIC_WITH_FORM` obeys the rule with no work from its host
|
|
4603
|
+
since 7.32.1. Up to 7.32.0 it hid the paginator when all the rows fit, and
|
|
4604
|
+
its toolbar wrapped into two rows on a phone.
|
|
4605
|
+
|
|
4606
|
+
How to make sure that a table obeys it: open the DEPLOYED page at 390 px.
|
|
4607
|
+
Each control of the toolbar is on one line, the paginator
|
|
4608
|
+
(`.tabulator-paginator`) has a width with one page of rows, and each column
|
|
4609
|
+
of data has a filter box.
|
|
4610
|
+
|
|
4611
|
+
Why each point:
|
|
4612
|
+
|
|
4613
|
+
- The footer is where a reader looks for the row count and the page size.
|
|
4614
|
+
A control that comes and goes with the number of rows is a control that
|
|
4615
|
+
the reader must look for. The same footer in each table also tells the
|
|
4616
|
+
reader that it is the same kind of table.
|
|
4617
|
+
- A filter and a sort work on the rows that the browser holds. With remote
|
|
4618
|
+
pages, a filter searches one page, and "nothing found" can be false. A
|
|
4619
|
+
treedb is a memory database, so the backend holds the whole topic anyway.
|
|
4620
|
+
- A toolbar that wraps takes a row from the table on a phone. It also puts
|
|
4621
|
+
the same button in a different place on each screen width. A row that
|
|
4622
|
+
scrolls keeps each button in its place.
|
|
4623
|
+
|
|
4480
4624
|
### `index.html`: title, metadata and the Content-Security-Policy
|
|
4481
4625
|
|
|
4482
4626
|
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
|
};
|
|
@@ -61938,7 +61939,7 @@ function build_ui$5(gobj) {
|
|
|
61938
61939
|
},
|
|
61939
61940
|
[["div", {
|
|
61940
61941
|
class: "TREEDB_TABLE_TOOLBAR toolbar_tabulator_table m-1",
|
|
61941
|
-
style: "flex:none;
|
|
61942
|
+
style: "flex:none; min-width:0;"
|
|
61942
61943
|
}], ["div", {
|
|
61943
61944
|
id: `${table_id}`,
|
|
61944
61945
|
style: "margin-top:0px !important; flex:1 1 auto; min-height:0;"
|
|
@@ -61999,9 +62000,10 @@ function build_ui$5(gobj) {
|
|
|
61999
62000
|
gobj.priv.$parent_filter = $parent_filter;
|
|
62000
62001
|
$container.insertBefore($parent_filter, find_by_id($container, table_id));
|
|
62001
62002
|
let $toolbar_slot = $container.querySelector(".toolbar_tabulator_table");
|
|
62002
|
-
|
|
62003
|
-
|
|
62004
|
-
$
|
|
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]));
|
|
62005
62007
|
(0, _yuneta_gobj_js.gobj_write_attr)(gobj, "$container", $container);
|
|
62006
62008
|
(0, _yuneta_gobj_js.refresh_language)($container, i18next.t);
|
|
62007
62009
|
}
|
|
@@ -62468,33 +62470,6 @@ function create_tabulator(gobj) {
|
|
|
62468
62470
|
let total = gobj.priv._page_total;
|
|
62469
62471
|
if (paged && typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${(0, i18next.t)("rows")}`;
|
|
62470
62472
|
else $rc.textContent = `${n} ${(0, i18next.t)("rows")}`;
|
|
62471
|
-
let single_page = true;
|
|
62472
|
-
try {
|
|
62473
|
-
if (paged) {
|
|
62474
|
-
let max = tabulator.getPageMax();
|
|
62475
|
-
single_page = max === false || max <= 1;
|
|
62476
|
-
} else {
|
|
62477
|
-
let size = tabulator.getPageSize();
|
|
62478
|
-
single_page = size === true || !size || n <= size;
|
|
62479
|
-
}
|
|
62480
|
-
} catch (e) {
|
|
62481
|
-
single_page = true;
|
|
62482
|
-
}
|
|
62483
|
-
let total_rows;
|
|
62484
|
-
if (paged) total_rows = total;
|
|
62485
|
-
else try {
|
|
62486
|
-
total_rows = tabulator.getDataCount();
|
|
62487
|
-
} catch (e) {
|
|
62488
|
-
total_rows = n;
|
|
62489
|
-
}
|
|
62490
|
-
let min_size = 0;
|
|
62491
|
-
let sizes = tabulator.options ? tabulator.options.paginationSizeSelector : null;
|
|
62492
|
-
if (Array.isArray(sizes)) sizes.forEach(function(size) {
|
|
62493
|
-
if (typeof size === "number" && (!min_size || size < min_size)) min_size = size;
|
|
62494
|
-
});
|
|
62495
|
-
let no_paginator = single_page && (!min_size || typeof total_rows !== "number" || total_rows <= min_size);
|
|
62496
|
-
tabulator.element.classList.toggle("yui-single-page", single_page);
|
|
62497
|
-
tabulator.element.classList.toggle("yui-no-paginator", no_paginator);
|
|
62498
62473
|
}
|
|
62499
62474
|
tabulator.on("columnsLoaded", function() {
|
|
62500
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
|
};
|
|
@@ -61933,7 +61934,7 @@ function build_ui$5(gobj) {
|
|
|
61933
61934
|
},
|
|
61934
61935
|
[["div", {
|
|
61935
61936
|
class: "TREEDB_TABLE_TOOLBAR toolbar_tabulator_table m-1",
|
|
61936
|
-
style: "flex:none;
|
|
61937
|
+
style: "flex:none; min-width:0;"
|
|
61937
61938
|
}], ["div", {
|
|
61938
61939
|
id: `${table_id}`,
|
|
61939
61940
|
style: "margin-top:0px !important; flex:1 1 auto; min-height:0;"
|
|
@@ -61994,9 +61995,10 @@ function build_ui$5(gobj) {
|
|
|
61994
61995
|
gobj.priv.$parent_filter = $parent_filter;
|
|
61995
61996
|
$container.insertBefore($parent_filter, find_by_id($container, table_id));
|
|
61996
61997
|
let $toolbar_slot = $container.querySelector(".toolbar_tabulator_table");
|
|
61997
|
-
|
|
61998
|
-
|
|
61999
|
-
$
|
|
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]));
|
|
62000
62002
|
gobj_write_attr(gobj, "$container", $container);
|
|
62001
62003
|
refresh_language($container, t);
|
|
62002
62004
|
}
|
|
@@ -62463,33 +62465,6 @@ function create_tabulator(gobj) {
|
|
|
62463
62465
|
let total = gobj.priv._page_total;
|
|
62464
62466
|
if (paged && typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${t("rows")}`;
|
|
62465
62467
|
else $rc.textContent = `${n} ${t("rows")}`;
|
|
62466
|
-
let single_page = true;
|
|
62467
|
-
try {
|
|
62468
|
-
if (paged) {
|
|
62469
|
-
let max = tabulator.getPageMax();
|
|
62470
|
-
single_page = max === false || max <= 1;
|
|
62471
|
-
} else {
|
|
62472
|
-
let size = tabulator.getPageSize();
|
|
62473
|
-
single_page = size === true || !size || n <= size;
|
|
62474
|
-
}
|
|
62475
|
-
} catch (e) {
|
|
62476
|
-
single_page = true;
|
|
62477
|
-
}
|
|
62478
|
-
let total_rows;
|
|
62479
|
-
if (paged) total_rows = total;
|
|
62480
|
-
else try {
|
|
62481
|
-
total_rows = tabulator.getDataCount();
|
|
62482
|
-
} catch (e) {
|
|
62483
|
-
total_rows = n;
|
|
62484
|
-
}
|
|
62485
|
-
let min_size = 0;
|
|
62486
|
-
let sizes = tabulator.options ? tabulator.options.paginationSizeSelector : null;
|
|
62487
|
-
if (Array.isArray(sizes)) sizes.forEach(function(size) {
|
|
62488
|
-
if (typeof size === "number" && (!min_size || size < min_size)) min_size = size;
|
|
62489
|
-
});
|
|
62490
|
-
let no_paginator = single_page && (!min_size || typeof total_rows !== "number" || total_rows <= min_size);
|
|
62491
|
-
tabulator.element.classList.toggle("yui-single-page", single_page);
|
|
62492
|
-
tabulator.element.classList.toggle("yui-no-paginator", no_paginator);
|
|
62493
62468
|
}
|
|
62494
62469
|
tabulator.on("columnsLoaded", function() {
|
|
62495
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
|
|
@@ -0,0 +1,278 @@
|
|
|
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
|
+
* A TREE table (`dataTree`) filters each column with
|
|
40
|
+
* `yui_tree_filter()`: Tabulator filters a tree from its roots,
|
|
41
|
+
* and a parent that fails hides the children that match.
|
|
42
|
+
*
|
|
43
|
+
* The row count needs the key "rows" in the app (every app
|
|
44
|
+
* that shows a treedb table has it already).
|
|
45
|
+
*
|
|
46
|
+
* Copyright (c) 2026, ArtGins.
|
|
47
|
+
* All Rights Reserved.
|
|
48
|
+
***********************************************************************/
|
|
49
|
+
import {yui_tabulator_name_filters} from "./yui_tabulator_i18n.js";
|
|
50
|
+
import {yui_table_filter_clear} from "./yui_table_filter_clear.js";
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/* Rows per page, and the sizes the selector offers. `true` is
|
|
54
|
+
* Tabulator's "All". */
|
|
55
|
+
const YUI_TABLE_PAGE_SIZE = 25;
|
|
56
|
+
const YUI_TABLE_PAGE_SIZES = [25, 50, 100, true];
|
|
57
|
+
|
|
58
|
+
/* The width a column with a text filter needs: the placeholder in the
|
|
59
|
+
* LONGEST locale ("filtrar columna...", ~18 characters). The same
|
|
60
|
+
* floor as the treedb topic table. */
|
|
61
|
+
const YUI_TABLE_FILTER_MIN_WIDTH = 150;
|
|
62
|
+
|
|
63
|
+
/* Formatters whose cell is a CONTROL, not data: nothing to filter. */
|
|
64
|
+
const CONTROL_FORMATTERS = ["rowSelection", "handle", "responsiveCollapse", "buttonCross"];
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/***************************************************************
|
|
68
|
+
* The row count of the footer.
|
|
69
|
+
*
|
|
70
|
+
* Called by Tabulator with `this` = its pagination module, on
|
|
71
|
+
* every page, filter and data change. `total_rows` is the ACTIVE
|
|
72
|
+
* count: the rows the filters leave, all pages together.
|
|
73
|
+
*
|
|
74
|
+
* The number is data; the word comes from the table's locale
|
|
75
|
+
* (`pagination.counter.rows`, which `yui_tabulator_lang()` fills
|
|
76
|
+
* with the app's "rows"), and `langBind` changes it again when
|
|
77
|
+
* `yui_tabulator_relocalize()` installs a new language.
|
|
78
|
+
*
|
|
79
|
+
* Returns a DOM node, never a string: Tabulator puts a string in
|
|
80
|
+
* with `innerHTML`.
|
|
81
|
+
***************************************************************/
|
|
82
|
+
function rows_counter(page_size, current_row, current_page, total_rows)
|
|
83
|
+
{
|
|
84
|
+
let $count = document.createElement("span");
|
|
85
|
+
$count.className = "YUI_TABLE_COUNT";
|
|
86
|
+
|
|
87
|
+
let $number = document.createElement("span");
|
|
88
|
+
$number.className = "YUI_TABLE_COUNT_NUMBER";
|
|
89
|
+
$number.textContent = String(total_rows || 0);
|
|
90
|
+
|
|
91
|
+
let $word = document.createElement("span");
|
|
92
|
+
$word.className = "YUI_TABLE_COUNT_WORD";
|
|
93
|
+
$word.textContent = "rows";
|
|
94
|
+
let localize = this && this.table && this.table.modules ? this.table.modules.localize : null;
|
|
95
|
+
if(localize && typeof localize.langBind === "function") {
|
|
96
|
+
localize.langBind("pagination|counter|rows", (value) => {
|
|
97
|
+
$word.textContent = value;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
$count.appendChild($number);
|
|
102
|
+
$count.appendChild(document.createTextNode(" "));
|
|
103
|
+
$count.appendChild($word);
|
|
104
|
+
return $count;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/***************************************************************
|
|
108
|
+
* The pagination settings of a standard table.
|
|
109
|
+
*
|
|
110
|
+
* opts:
|
|
111
|
+
* size rows per page (default 25)
|
|
112
|
+
* sizes what the selector offers (default [25, 50, 100, true])
|
|
113
|
+
*
|
|
114
|
+
* Spread them into the Tabulator settings. Local pagination: the
|
|
115
|
+
* host gives the table every row (`data` or `setData()`).
|
|
116
|
+
***************************************************************/
|
|
117
|
+
function yui_table_paging(opts)
|
|
118
|
+
{
|
|
119
|
+
let o = opts || {};
|
|
120
|
+
let size = o.size || YUI_TABLE_PAGE_SIZE;
|
|
121
|
+
let sizes = Array.isArray(o.sizes) ? o.sizes.slice() : YUI_TABLE_PAGE_SIZES.slice();
|
|
122
|
+
if(typeof size === "number" && !sizes.includes(size)) {
|
|
123
|
+
sizes.unshift(size);
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
pagination: true,
|
|
127
|
+
paginationMode: "local",
|
|
128
|
+
paginationSize: size,
|
|
129
|
+
paginationSizeSelector: sizes,
|
|
130
|
+
paginationCounter: rows_counter
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/***************************************************************
|
|
135
|
+
* The columns, each with its header filter.
|
|
136
|
+
*
|
|
137
|
+
* A column gets a filter when it has a `field` and says nothing
|
|
138
|
+
* about one (`headerFilter` undefined):
|
|
139
|
+
*
|
|
140
|
+
* - a tick (`formatter: "tickCross"`) gets a three-state tick:
|
|
141
|
+
* any, yes, no;
|
|
142
|
+
* - any other gets a text box ("like": a part of the value, in
|
|
143
|
+
* any case), and a minimum width for the box, unless the
|
|
144
|
+
* column sets `width` or `minWidth` itself.
|
|
145
|
+
*
|
|
146
|
+
* A column that says something keeps it: its own filter, or
|
|
147
|
+
* `headerFilter: false` for a column whose cell is a control (a
|
|
148
|
+
* row of action buttons). A column with no field, or whose cell is
|
|
149
|
+
* a control by its formatter (the selection checkbox), gets none.
|
|
150
|
+
* The groups of columns are walked.
|
|
151
|
+
*
|
|
152
|
+
* The definitions are copied, never changed in place.
|
|
153
|
+
***************************************************************/
|
|
154
|
+
function yui_table_filters(columns)
|
|
155
|
+
{
|
|
156
|
+
if(!Array.isArray(columns)) {
|
|
157
|
+
return columns;
|
|
158
|
+
}
|
|
159
|
+
return columns.map((column) => {
|
|
160
|
+
if(!column || typeof column !== "object") {
|
|
161
|
+
return column;
|
|
162
|
+
}
|
|
163
|
+
if(Array.isArray(column.columns)) {
|
|
164
|
+
return {...column, columns: yui_table_filters(column.columns)};
|
|
165
|
+
}
|
|
166
|
+
if(!column.field || column.headerFilter !== undefined) {
|
|
167
|
+
return column;
|
|
168
|
+
}
|
|
169
|
+
if(CONTROL_FORMATTERS.includes(column.formatter)) {
|
|
170
|
+
return column;
|
|
171
|
+
}
|
|
172
|
+
if(column.formatter === "tickCross") {
|
|
173
|
+
return {
|
|
174
|
+
...column,
|
|
175
|
+
headerFilter: "tickCross",
|
|
176
|
+
headerFilterParams: {tristate: true}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
let filtered = {...column, headerFilter: "input"};
|
|
180
|
+
if(filtered.width === undefined && filtered.minWidth === undefined) {
|
|
181
|
+
filtered.minWidth = YUI_TABLE_FILTER_MIN_WIDTH;
|
|
182
|
+
}
|
|
183
|
+
return filtered;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/***************************************************************
|
|
188
|
+
* The header filter of a column of a TREE table (`dataTree`).
|
|
189
|
+
*
|
|
190
|
+
* `text_of(data)` answers the text that a row shows in the column.
|
|
191
|
+
* A row passes when its own text holds the term (in any case), or
|
|
192
|
+
* when the text of one of its descendants does.
|
|
193
|
+
*
|
|
194
|
+
* Why the descendants: Tabulator filters a tree from its roots, and
|
|
195
|
+
* a parent that fails is hidden with all its children. A filter on
|
|
196
|
+
* the name of a yuno would hide every node, and the yunos with
|
|
197
|
+
* them. With this one the node stays, and Tabulator then filters
|
|
198
|
+
* its children with the same function (`dataTreeFilter`, on by
|
|
199
|
+
* default), so only the yunos that match are shown.
|
|
200
|
+
*
|
|
201
|
+
* `child_field` is the table's `dataTreeChildField` ("_children").
|
|
202
|
+
*
|
|
203
|
+
* {title: t("name"), field: "id",
|
|
204
|
+
* headerFilterFunc: yui_tree_filter((d) => d.label || d.host)}
|
|
205
|
+
*
|
|
206
|
+
* `yui_table_filters()` then gives the column its text box.
|
|
207
|
+
***************************************************************/
|
|
208
|
+
function yui_tree_filter(text_of, child_field)
|
|
209
|
+
{
|
|
210
|
+
let field = child_field || "_children";
|
|
211
|
+
|
|
212
|
+
function matches(data, needle, depth)
|
|
213
|
+
{
|
|
214
|
+
if(!data || typeof data !== "object") {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
let text = "";
|
|
218
|
+
try {
|
|
219
|
+
text = String(text_of(data) ?? "");
|
|
220
|
+
} catch(e) {
|
|
221
|
+
text = "";
|
|
222
|
+
}
|
|
223
|
+
if(text.toLowerCase().includes(needle)) {
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
/* A guard against a cycle in data that is not a tree. */
|
|
227
|
+
if(depth > 32) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
let children = data[field];
|
|
231
|
+
if(!Array.isArray(children)) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
return children.some((child) => matches(child, needle, depth + 1));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return function(term, value, data) {
|
|
238
|
+
let needle = String(term ?? "").trim().toLowerCase();
|
|
239
|
+
if(!needle) {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
return matches(data, needle, 0);
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/***************************************************************
|
|
247
|
+
* What the header filters need after the table is drawn.
|
|
248
|
+
*
|
|
249
|
+
* Tabulator draws the filter boxes with no name, and draws them
|
|
250
|
+
* again on every rebuild of the columns: each one gets its name
|
|
251
|
+
* ("filter by column") and its ✕ (`yui_table_filter_clear()`).
|
|
252
|
+
*
|
|
253
|
+
* Call it right after `new Tabulator(...)`: the table announces
|
|
254
|
+
* `tableBuilt` later.
|
|
255
|
+
***************************************************************/
|
|
256
|
+
function yui_table_wire(table, t)
|
|
257
|
+
{
|
|
258
|
+
if(!table || typeof table.on !== "function") {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
table.on("tableBuilt", () => {
|
|
262
|
+
yui_tabulator_name_filters(table, t);
|
|
263
|
+
yui_table_filter_clear(table);
|
|
264
|
+
});
|
|
265
|
+
table.on("columnsLoaded", () => {
|
|
266
|
+
yui_tabulator_name_filters(table, t);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export {
|
|
271
|
+
YUI_TABLE_PAGE_SIZE,
|
|
272
|
+
YUI_TABLE_PAGE_SIZES,
|
|
273
|
+
YUI_TABLE_FILTER_MIN_WIDTH,
|
|
274
|
+
yui_table_paging,
|
|
275
|
+
yui_table_filters,
|
|
276
|
+
yui_tree_filter,
|
|
277
|
+
yui_table_wire,
|
|
278
|
+
};
|
|
@@ -0,0 +1,212 @@
|
|
|
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_tree_filter,
|
|
21
|
+
yui_table_wire,
|
|
22
|
+
} from "./yui_table_standard.js";
|
|
23
|
+
|
|
24
|
+
describe("the paging", () => {
|
|
25
|
+
test("is local, always on, with the standard sizes", () => {
|
|
26
|
+
let s = yui_table_paging();
|
|
27
|
+
expect(s.pagination).toBe(true);
|
|
28
|
+
expect(s.paginationMode).toBe("local");
|
|
29
|
+
expect(s.paginationSize).toBe(25);
|
|
30
|
+
expect(s.paginationSizeSelector).toEqual([25, 50, 100, true]);
|
|
31
|
+
expect(typeof s.paginationCounter).toBe("function");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("a size of its own is offered by the selector", () => {
|
|
35
|
+
let s = yui_table_paging({size: 10});
|
|
36
|
+
expect(s.paginationSize).toBe(10);
|
|
37
|
+
expect(s.paginationSizeSelector).toEqual([10, 25, 50, 100, true]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("the sizes of the host are kept, and not shared between tables", () => {
|
|
41
|
+
let a = yui_table_paging({size: 50, sizes: [50, 200, true]});
|
|
42
|
+
expect(a.paginationSizeSelector).toEqual([50, 200, true]);
|
|
43
|
+
let b = yui_table_paging();
|
|
44
|
+
b.paginationSizeSelector.push(7);
|
|
45
|
+
expect(yui_table_paging().paginationSizeSelector).toEqual([25, 50, 100, true]);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("the row count", () => {
|
|
50
|
+
function page_module(word)
|
|
51
|
+
{
|
|
52
|
+
let bindings = [];
|
|
53
|
+
return {
|
|
54
|
+
bindings: bindings,
|
|
55
|
+
table: {
|
|
56
|
+
modules: {
|
|
57
|
+
localize: {
|
|
58
|
+
langBind(path, cb) {
|
|
59
|
+
bindings.push(path);
|
|
60
|
+
cb(word);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
test("says every active row, all pages together, in the table's language", () => {
|
|
69
|
+
let counter = yui_table_paging().paginationCounter;
|
|
70
|
+
let page = page_module("filas");
|
|
71
|
+
let $el = counter.call(page, 25, 26, 2, 113, 5);
|
|
72
|
+
expect($el.textContent).toBe("113 filas");
|
|
73
|
+
expect(page.bindings).toEqual(["pagination|counter|rows"]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("an empty table says 0", () => {
|
|
77
|
+
let counter = yui_table_paging().paginationCounter;
|
|
78
|
+
let $el = counter.call(page_module("rows"), 25, 0, 1, 0, 0);
|
|
79
|
+
expect($el.textContent).toBe("0 rows");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("is a node, never a string Tabulator would put in as html", () => {
|
|
83
|
+
let counter = yui_table_paging().paginationCounter;
|
|
84
|
+
let $el = counter.call(page_module("rows"), 25, 1, 1, 3, 1);
|
|
85
|
+
expect(typeof $el).toBe("object");
|
|
86
|
+
expect($el.className).toBe("YUI_TABLE_COUNT");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("without a localize module it still counts, in English", () => {
|
|
90
|
+
let counter = yui_table_paging().paginationCounter;
|
|
91
|
+
let $el = counter.call({}, 25, 1, 1, 3, 1);
|
|
92
|
+
expect($el.textContent).toBe("3 rows");
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe("the filters", () => {
|
|
97
|
+
test("a column of data gets a text box, and room for it", () => {
|
|
98
|
+
let [c] = yui_table_filters([{title: "Name", field: "name"}]);
|
|
99
|
+
expect(c.headerFilter).toBe("input");
|
|
100
|
+
expect(c.minWidth).toBe(YUI_TABLE_FILTER_MIN_WIDTH);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("a width set by the host is kept", () => {
|
|
104
|
+
let [a, b] = yui_table_filters([
|
|
105
|
+
{field: "a", width: 110},
|
|
106
|
+
{field: "b", minWidth: 220},
|
|
107
|
+
]);
|
|
108
|
+
expect(a.headerFilter).toBe("input");
|
|
109
|
+
expect(a.minWidth).toBeUndefined();
|
|
110
|
+
expect(a.width).toBe(110);
|
|
111
|
+
expect(b.minWidth).toBe(220);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("a tick gets a three-state tick", () => {
|
|
115
|
+
let [c] = yui_table_filters([{field: "enabled", formatter: "tickCross"}]);
|
|
116
|
+
expect(c.headerFilter).toBe("tickCross");
|
|
117
|
+
expect(c.headerFilterParams).toEqual({tristate: true});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("a column that says something keeps it", () => {
|
|
121
|
+
let own = {field: "kind", headerFilter: "list", headerFilterParams: {values: ["a"]}};
|
|
122
|
+
let off = {field: "user_id", headerFilter: false};
|
|
123
|
+
let [a, b] = yui_table_filters([own, off]);
|
|
124
|
+
expect(a).toBe(own);
|
|
125
|
+
expect(b).toBe(off);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("a control is not filtered: no field, or a control formatter", () => {
|
|
129
|
+
let none = {title: "", formatter: () => "x"};
|
|
130
|
+
let select = {field: "_select", formatter: "rowSelection"};
|
|
131
|
+
let [a, b] = yui_table_filters([none, select]);
|
|
132
|
+
expect(a.headerFilter).toBeUndefined();
|
|
133
|
+
expect(b.headerFilter).toBeUndefined();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("the groups are walked, and nothing is changed in place", () => {
|
|
137
|
+
let inner = {field: "x"};
|
|
138
|
+
let group = {title: "G", columns: [inner]};
|
|
139
|
+
let [g] = yui_table_filters([group]);
|
|
140
|
+
expect(g.columns[0].headerFilter).toBe("input");
|
|
141
|
+
expect(inner.headerFilter).toBeUndefined();
|
|
142
|
+
expect(group.columns[0]).toBe(inner);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("not a list: given back as it is", () => {
|
|
146
|
+
expect(yui_table_filters(null)).toBe(null);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe("the filter of a tree", () => {
|
|
151
|
+
const node = {
|
|
152
|
+
host: "artgins",
|
|
153
|
+
_children: [
|
|
154
|
+
{label: "yuneta_agent"},
|
|
155
|
+
{label: "controlcenter", _children: [{label: "auth_bff"}]},
|
|
156
|
+
]
|
|
157
|
+
};
|
|
158
|
+
const f = yui_tree_filter((d) => d.label || d.host);
|
|
159
|
+
|
|
160
|
+
test("a row passes on its own text, in any case", () => {
|
|
161
|
+
expect(f("ArtG", null, node)).toBe(true);
|
|
162
|
+
expect(f("agent", null, node._children[0])).toBe(true);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("a parent passes when a descendant matches, at any depth", () => {
|
|
166
|
+
expect(f("control", null, node)).toBe(true);
|
|
167
|
+
expect(f("bff", null, node)).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("a row that does not match, with no descendant that does, fails", () => {
|
|
171
|
+
expect(f("mqtt", null, node)).toBe(false);
|
|
172
|
+
expect(f("control", null, node._children[0])).toBe(false);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("an empty term passes everything", () => {
|
|
176
|
+
expect(f("", null, node)).toBe(true);
|
|
177
|
+
expect(f(" ", null, node)).toBe(true);
|
|
178
|
+
expect(f(null, null, node)).toBe(true);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("another child field, and a text_of that throws", () => {
|
|
182
|
+
let g = yui_tree_filter((d) => d.name, "kids");
|
|
183
|
+
expect(g("b", null, {name: "a", kids: [{name: "b"}]})).toBe(true);
|
|
184
|
+
let bad = yui_tree_filter(() => {
|
|
185
|
+
throw new Error("x");
|
|
186
|
+
});
|
|
187
|
+
expect(bad("a", null, {})).toBe(false);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("with yui_table_filters, the column gets its text box", () => {
|
|
191
|
+
let [c] = yui_table_filters([{field: "id", headerFilterFunc: f}]);
|
|
192
|
+
expect(c.headerFilter).toBe("input");
|
|
193
|
+
expect(c.headerFilterFunc).toBe(f);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe("the wiring", () => {
|
|
198
|
+
test("names the filters when the table is built and on every rebuild", () => {
|
|
199
|
+
let events = {};
|
|
200
|
+
let table = {
|
|
201
|
+
on(name, fn) {
|
|
202
|
+
events[name] = fn;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
yui_table_wire(table, (k) => k);
|
|
206
|
+
expect(Object.keys(events).sort()).toEqual(["columnsLoaded", "tableBuilt"]);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("a table that is not there is ignored", () => {
|
|
210
|
+
expect(() => yui_table_wire(null, (k) => k)).not.toThrow();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -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...")
|