@yuneta/gobj-ui 7.32.3 → 7.32.5
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 +12 -5
- package/dist/gobj-ui.cjs.js +38 -2
- package/dist/gobj-ui.es.js +38 -2
- package/package.json +1 -1
- package/src/c_yui_treedb_topic_with_form.js +59 -3
- package/src/treedb_header_filters.wiring.test.js +118 -0
- package/src/yui_table_standard.js +37 -10
- package/src/yui_table_standard.test.js +37 -11
package/README.md
CHANGED
|
@@ -4384,7 +4384,10 @@ yui_table_wire(table, t);
|
|
|
4384
4384
|
`opts.sizes` change them. A size that the sizes do not hold goes first in
|
|
4385
4385
|
the selector. The host gives the table every row. The footer shows the
|
|
4386
4386
|
paginator and the row count. The count is the number of rows that the
|
|
4387
|
-
filters leave, on all pages together.
|
|
4387
|
+
filters leave, on all pages together. With a filter on, it says both
|
|
4388
|
+
numbers: the rows that the filter leaves and the rows that the table holds
|
|
4389
|
+
("12 / 27 rows"). A status line under the table that only counts its rows
|
|
4390
|
+
is then not necessary. The table locale gives its word, so
|
|
4388
4391
|
the word changes language with `yui_tabulator_relocalize()`.
|
|
4389
4392
|
|
|
4390
4393
|
`yui_table_filters(columns)` gives a copy of the columns, each with its
|
|
@@ -4433,8 +4436,11 @@ adds its ✕ (`yui_table_filter_clear()`). It does this when the table is
|
|
|
4433
4436
|
built and again each time Tabulator builds the columns again. Call it right
|
|
4434
4437
|
after `new Tabulator(...)`.
|
|
4435
4438
|
|
|
4436
|
-
The app must define the keys `"rows"`, `"filter by column"`
|
|
4437
|
-
and the paginator keys of `yui_tabulator_lang()`.
|
|
4439
|
+
The app must define the keys `"rows"`, `"rows_one"`, `"filter by column"`
|
|
4440
|
+
and `"clear"`, and the paginator keys of `yui_tabulator_lang()`. The count
|
|
4441
|
+
takes the plural of the number it goes with: `"rows_one"` for one row ("1
|
|
4442
|
+
fila"), `"rows"` for the others. Without `"rows_one"` i18next falls back to
|
|
4443
|
+
`"rows"`, and one row reads "1 filas".
|
|
4438
4444
|
|
|
4439
4445
|
Two things to look at when you apply it:
|
|
4440
4446
|
|
|
@@ -4610,8 +4616,9 @@ let $toolbar = yui_toolbar({class: "ACCOUNTS_TOOLBAR"}, [
|
|
|
4610
4616
|
```
|
|
4611
4617
|
|
|
4612
4618
|
`C_YUI_TREEDB_TOPIC_WITH_FORM` obeys the rule with no work from its host
|
|
4613
|
-
since 7.32.
|
|
4614
|
-
its toolbar wrapped into two rows on a phone.
|
|
4619
|
+
since 7.32.4. Up to 7.32.0 it hid the paginator when all the rows fit, and
|
|
4620
|
+
its toolbar wrapped into two rows on a phone. Up to 7.32.3 the columns of a
|
|
4621
|
+
document, a hook, a file and a time had no filter.
|
|
4615
4622
|
|
|
4616
4623
|
How to make sure that a table obeys it: open the DEPLOYED page at 390 px.
|
|
4617
4624
|
Each control of the toolbar is on one line, the paginator
|
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -62216,8 +62216,39 @@ function create_tabulator(gobj) {
|
|
|
62216
62216
|
if (value === null || value === void 0) return false;
|
|
62217
62217
|
return (typeof value === "string" ? value : JSON.stringify(value)).toLowerCase().includes(String(term).toLowerCase());
|
|
62218
62218
|
}
|
|
62219
|
+
function time_matches(real_type) {
|
|
62220
|
+
return function(term, value) {
|
|
62221
|
+
let needle = String(term ?? "").trim().toLowerCase();
|
|
62222
|
+
if (!needle) return true;
|
|
62223
|
+
let text = time_value_to_text(value, real_type, safe_locale(i18next.default.language));
|
|
62224
|
+
return String(text || "").toLowerCase().includes(needle);
|
|
62225
|
+
};
|
|
62226
|
+
}
|
|
62219
62227
|
function apply_header_filter(colDef, field_desc) {
|
|
62220
62228
|
switch (field_desc.type) {
|
|
62229
|
+
case "object":
|
|
62230
|
+
case "dict":
|
|
62231
|
+
case "template":
|
|
62232
|
+
case "array":
|
|
62233
|
+
case "list":
|
|
62234
|
+
case "coordinates":
|
|
62235
|
+
case "blob":
|
|
62236
|
+
case "gbuffer":
|
|
62237
|
+
case "hook":
|
|
62238
|
+
case "file":
|
|
62239
|
+
colDef.headerFilter = "input";
|
|
62240
|
+
colDef.headerFilterFunc = fkey_matches;
|
|
62241
|
+
break;
|
|
62242
|
+
case "now":
|
|
62243
|
+
case "time":
|
|
62244
|
+
colDef.headerFilter = "input";
|
|
62245
|
+
colDef.headerFilterFunc = time_matches(field_desc.real_type);
|
|
62246
|
+
break;
|
|
62247
|
+
case "image":
|
|
62248
|
+
case "color":
|
|
62249
|
+
case "icon":
|
|
62250
|
+
colDef.headerFilter = "input";
|
|
62251
|
+
break;
|
|
62221
62252
|
case "boolean":
|
|
62222
62253
|
colDef.headerFilter = "tickCross";
|
|
62223
62254
|
colDef.headerFilterParams = { tristate: true };
|
|
@@ -62468,8 +62499,13 @@ function create_tabulator(gobj) {
|
|
|
62468
62499
|
}
|
|
62469
62500
|
let paged = (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "with_remote_paging");
|
|
62470
62501
|
let total = gobj.priv._page_total;
|
|
62471
|
-
if (paged
|
|
62472
|
-
|
|
62502
|
+
if (!paged) try {
|
|
62503
|
+
total = tabulator.getDataCount();
|
|
62504
|
+
} catch (e) {
|
|
62505
|
+
total = n;
|
|
62506
|
+
}
|
|
62507
|
+
if (typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${(0, i18next.t)("rows", { count: total })}`;
|
|
62508
|
+
else $rc.textContent = `${n} ${(0, i18next.t)("rows", { count: n })}`;
|
|
62473
62509
|
}
|
|
62474
62510
|
tabulator.on("columnsLoaded", function() {
|
|
62475
62511
|
yui_tabulator_name_filters(tabulator, i18next.t);
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -62211,8 +62211,39 @@ function create_tabulator(gobj) {
|
|
|
62211
62211
|
if (value === null || value === void 0) return false;
|
|
62212
62212
|
return (typeof value === "string" ? value : JSON.stringify(value)).toLowerCase().includes(String(term).toLowerCase());
|
|
62213
62213
|
}
|
|
62214
|
+
function time_matches(real_type) {
|
|
62215
|
+
return function(term, value) {
|
|
62216
|
+
let needle = String(term ?? "").trim().toLowerCase();
|
|
62217
|
+
if (!needle) return true;
|
|
62218
|
+
let text = time_value_to_text(value, real_type, safe_locale(i18next.language));
|
|
62219
|
+
return String(text || "").toLowerCase().includes(needle);
|
|
62220
|
+
};
|
|
62221
|
+
}
|
|
62214
62222
|
function apply_header_filter(colDef, field_desc) {
|
|
62215
62223
|
switch (field_desc.type) {
|
|
62224
|
+
case "object":
|
|
62225
|
+
case "dict":
|
|
62226
|
+
case "template":
|
|
62227
|
+
case "array":
|
|
62228
|
+
case "list":
|
|
62229
|
+
case "coordinates":
|
|
62230
|
+
case "blob":
|
|
62231
|
+
case "gbuffer":
|
|
62232
|
+
case "hook":
|
|
62233
|
+
case "file":
|
|
62234
|
+
colDef.headerFilter = "input";
|
|
62235
|
+
colDef.headerFilterFunc = fkey_matches;
|
|
62236
|
+
break;
|
|
62237
|
+
case "now":
|
|
62238
|
+
case "time":
|
|
62239
|
+
colDef.headerFilter = "input";
|
|
62240
|
+
colDef.headerFilterFunc = time_matches(field_desc.real_type);
|
|
62241
|
+
break;
|
|
62242
|
+
case "image":
|
|
62243
|
+
case "color":
|
|
62244
|
+
case "icon":
|
|
62245
|
+
colDef.headerFilter = "input";
|
|
62246
|
+
break;
|
|
62216
62247
|
case "boolean":
|
|
62217
62248
|
colDef.headerFilter = "tickCross";
|
|
62218
62249
|
colDef.headerFilterParams = { tristate: true };
|
|
@@ -62463,8 +62494,13 @@ function create_tabulator(gobj) {
|
|
|
62463
62494
|
}
|
|
62464
62495
|
let paged = gobj_read_bool_attr(gobj, "with_remote_paging");
|
|
62465
62496
|
let total = gobj.priv._page_total;
|
|
62466
|
-
if (paged
|
|
62467
|
-
|
|
62497
|
+
if (!paged) try {
|
|
62498
|
+
total = tabulator.getDataCount();
|
|
62499
|
+
} catch (e) {
|
|
62500
|
+
total = n;
|
|
62501
|
+
}
|
|
62502
|
+
if (typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${t("rows", { count: total })}`;
|
|
62503
|
+
else $rc.textContent = `${n} ${t("rows", { count: n })}`;
|
|
62468
62504
|
}
|
|
62469
62505
|
tabulator.on("columnsLoaded", function() {
|
|
62470
62506
|
yui_tabulator_name_filters(tabulator, t);
|
package/package.json
CHANGED
|
@@ -1360,9 +1360,53 @@ function create_tabulator(gobj)
|
|
|
1360
1360
|
return text.toLowerCase().includes(String(term).toLowerCase());
|
|
1361
1361
|
}
|
|
1362
1362
|
|
|
1363
|
+
/* A time is filtered by the date the cell SHOWS, in the app's
|
|
1364
|
+
* language: the value is an epoch (or an ISO text), and typing what
|
|
1365
|
+
* one reads found nothing. */
|
|
1366
|
+
function time_matches(real_type)
|
|
1367
|
+
{
|
|
1368
|
+
return function(term, value) {
|
|
1369
|
+
let needle = String(term ?? "").trim().toLowerCase();
|
|
1370
|
+
if(!needle) {
|
|
1371
|
+
return true;
|
|
1372
|
+
}
|
|
1373
|
+
let text = time_value_to_text(value, real_type, safe_locale(i18next.language));
|
|
1374
|
+
return String(text || "").toLowerCase().includes(needle);
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1363
1378
|
function apply_header_filter(colDef, field_desc)
|
|
1364
1379
|
{
|
|
1365
1380
|
switch(field_desc.type) {
|
|
1381
|
+
/* A document, a list of links, a file reference: the JSON
|
|
1382
|
+
* text is what is searched, the same reading as an fkey
|
|
1383
|
+
* (every column of data has a filter, gobj-ui README,
|
|
1384
|
+
* "Conventions" -> "A table: a filter on every column, the
|
|
1385
|
+
* paginator always, the toolbar in one row"). */
|
|
1386
|
+
case "object":
|
|
1387
|
+
case "dict":
|
|
1388
|
+
case "template":
|
|
1389
|
+
case "array":
|
|
1390
|
+
case "list":
|
|
1391
|
+
case "coordinates":
|
|
1392
|
+
case "blob":
|
|
1393
|
+
case "gbuffer":
|
|
1394
|
+
case "hook":
|
|
1395
|
+
case "file":
|
|
1396
|
+
colDef.headerFilter = "input";
|
|
1397
|
+
colDef.headerFilterFunc = fkey_matches;
|
|
1398
|
+
break;
|
|
1399
|
+
case "now":
|
|
1400
|
+
case "time":
|
|
1401
|
+
colDef.headerFilter = "input";
|
|
1402
|
+
colDef.headerFilterFunc = time_matches(field_desc.real_type);
|
|
1403
|
+
break;
|
|
1404
|
+
/* The name of an image, a colour, an icon: text. */
|
|
1405
|
+
case "image":
|
|
1406
|
+
case "color":
|
|
1407
|
+
case "icon":
|
|
1408
|
+
colDef.headerFilter = "input";
|
|
1409
|
+
break;
|
|
1366
1410
|
case "boolean":
|
|
1367
1411
|
colDef.headerFilter = "tickCross";
|
|
1368
1412
|
colDef.headerFilterParams = {tristate: true};
|
|
@@ -1842,10 +1886,22 @@ function create_tabulator(gobj)
|
|
|
1842
1886
|
* with 114 would be a lie by omission. Say both. */
|
|
1843
1887
|
let paged = gobj_read_bool_attr(gobj, "with_remote_paging");
|
|
1844
1888
|
let total = gobj.priv._page_total;
|
|
1845
|
-
if(paged
|
|
1846
|
-
|
|
1889
|
+
if(!paged) {
|
|
1890
|
+
/* With a filter on, both: the rows it leaves of the rows the
|
|
1891
|
+
* table holds -- the same reading as the standard table
|
|
1892
|
+
* (yui_table_standard.js). */
|
|
1893
|
+
try {
|
|
1894
|
+
total = tabulator.getDataCount();
|
|
1895
|
+
} catch(e) {
|
|
1896
|
+
total = n;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
/* The word in the plural of the number it goes with: "1 fila",
|
|
1900
|
+
* "13 filas" (`rows_one` / `rows`). Up to 7.32.4, "1 filas". */
|
|
1901
|
+
if(typeof total === "number" && total > n) {
|
|
1902
|
+
$rc.textContent = `${n} / ${total} ${t("rows", {count: total})}`;
|
|
1847
1903
|
} else {
|
|
1848
|
-
$rc.textContent = `${n} ${t("rows")}`;
|
|
1904
|
+
$rc.textContent = `${n} ${t("rows", {count: n})}`;
|
|
1849
1905
|
}
|
|
1850
1906
|
}
|
|
1851
1907
|
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* treedb_header_filters.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* Every column of data of C_YUI_TREEDB_TOPIC_WITH_FORM's table has
|
|
5
|
+
* a header filter (gobj-ui README, "Conventions" -> "A table: a
|
|
6
|
+
* filter on every column, the paginator always, the toolbar in one
|
|
7
|
+
* row"). Up to 7.32.3 a document (dict, list, blob, coordinates), a
|
|
8
|
+
* hook, a file and a time had none. A document is searched as its
|
|
9
|
+
* JSON text, a time as the date the cell shows.
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2026, ArtGins.
|
|
12
|
+
* All Rights Reserved.
|
|
13
|
+
***********************************************************************/
|
|
14
|
+
import {describe, test, expect, beforeAll, vi} from "vitest";
|
|
15
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
16
|
+
|
|
17
|
+
install_dom_double();
|
|
18
|
+
|
|
19
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
20
|
+
globalThis.ResizeObserver = class {
|
|
21
|
+
observe() {
|
|
22
|
+
}
|
|
23
|
+
unobserve() {
|
|
24
|
+
}
|
|
25
|
+
disconnect() {
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const tables = vi.hoisted(() => []);
|
|
31
|
+
vi.mock("tabulator-tables", () => {
|
|
32
|
+
class FakeTabulator {
|
|
33
|
+
constructor($el, settings) {
|
|
34
|
+
this.element = $el;
|
|
35
|
+
this.options = settings;
|
|
36
|
+
tables.push(this);
|
|
37
|
+
return new Proxy(this, {
|
|
38
|
+
get(target, prop) {
|
|
39
|
+
if(prop in target) {
|
|
40
|
+
return target[prop];
|
|
41
|
+
}
|
|
42
|
+
return () => [];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
on() {
|
|
47
|
+
}
|
|
48
|
+
off() {
|
|
49
|
+
}
|
|
50
|
+
destroy() {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {TabulatorFull: FakeTabulator, Tabulator: FakeTabulator};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const {
|
|
57
|
+
SDATA_END, gclass_create, set_log_callback,
|
|
58
|
+
gobj_start_up, gobj_create_yuno, gobj_create_service, gobj_start,
|
|
59
|
+
} = await import("@yuneta/gobj-js");
|
|
60
|
+
const {register_c_yui_treedb_topic_with_form} = await import("./c_yui_treedb_topic_with_form.js");
|
|
61
|
+
|
|
62
|
+
const logged = [];
|
|
63
|
+
let yuno = null;
|
|
64
|
+
|
|
65
|
+
beforeAll(async () => {
|
|
66
|
+
const i18next = (await import("i18next")).default;
|
|
67
|
+
await i18next.init({lng: "en", resources: {}});
|
|
68
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
69
|
+
set_log_callback((level, msg) => {
|
|
70
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
71
|
+
});
|
|
72
|
+
gclass_create("C_TEST_FILTERS_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
73
|
+
register_c_yui_treedb_topic_with_form();
|
|
74
|
+
yuno = gobj_create_yuno("filters_yuno", "C_TEST_FILTERS_HOST", {});
|
|
75
|
+
gobj_start(yuno);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("the header filters of a treedb topic's table", () => {
|
|
79
|
+
test("a column of every kind of data has one", () => {
|
|
80
|
+
const view = gobj_create_service("filters_view", "C_YUI_TREEDB_TOPIC_WITH_FORM", {
|
|
81
|
+
treedb_name: "treedb_test",
|
|
82
|
+
topic_name: "devices",
|
|
83
|
+
desc: {id: "devices", pkey: "id", cols: [
|
|
84
|
+
{id: "id", header: "Id", type: "string", flag: ["persistent", "required"]},
|
|
85
|
+
{id: "settings", header: "settings", type: "dict", flag: ["persistent"]},
|
|
86
|
+
{id: "notes", header: "notes", type: "array", flag: ["persistent"]},
|
|
87
|
+
{id: "props", header: "props", type: "blob", flag: ["persistent"]},
|
|
88
|
+
{id: "enabled", header: "enabled", type: "boolean", flag: ["persistent"]},
|
|
89
|
+
{id: "updated", header: "updated", type: "integer", flag: ["persistent", "time"]}
|
|
90
|
+
]}
|
|
91
|
+
}, yuno);
|
|
92
|
+
gobj_start(view);
|
|
93
|
+
const options = tables[tables.length - 1].options;
|
|
94
|
+
const columns = options.columns;
|
|
95
|
+
const col = (field) => columns.find((c) => c.field === field);
|
|
96
|
+
|
|
97
|
+
for(const field of ["id", "settings", "notes", "props", "updated"]) {
|
|
98
|
+
expect(col(field).headerFilter, field).toBe("input");
|
|
99
|
+
}
|
|
100
|
+
expect(col("enabled").headerFilter).toBe("tickCross");
|
|
101
|
+
|
|
102
|
+
/* A document: its JSON text */
|
|
103
|
+
const doc = col("settings").headerFilterFunc;
|
|
104
|
+
expect(doc("volt", {volts: 230})).toBe(true);
|
|
105
|
+
expect(doc("amp", {volts: 230})).toBe(false);
|
|
106
|
+
|
|
107
|
+
/* A time: the date the cell shows */
|
|
108
|
+
const epoch = Math.floor(new Date("2026-03-14T09:26:53").getTime() / 1000);
|
|
109
|
+
const when = col("updated").headerFilterFunc;
|
|
110
|
+
expect(when("2026", epoch)).toBe(true);
|
|
111
|
+
expect(when("1999", epoch)).toBe(false);
|
|
112
|
+
expect(when("", null)).toBe(true);
|
|
113
|
+
|
|
114
|
+
/* The paginator is drawn always: nothing in the settings hides it */
|
|
115
|
+
expect(options.pagination).toBe(true);
|
|
116
|
+
expect(logged.filter((l) => l.level === "error")).toEqual([]);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -41,11 +41,14 @@
|
|
|
41
41
|
* and a parent that fails hides the children that match.
|
|
42
42
|
*
|
|
43
43
|
* The row count needs the key "rows" in the app (every app
|
|
44
|
-
* that shows a treedb table has it already)
|
|
44
|
+
* that shows a treedb table has it already), and "rows_one"
|
|
45
|
+
* for one row ("1 row", "1 fila").
|
|
45
46
|
*
|
|
46
47
|
* Copyright (c) 2026, ArtGins.
|
|
47
48
|
* All Rights Reserved.
|
|
48
49
|
***********************************************************************/
|
|
50
|
+
import i18next from "i18next";
|
|
51
|
+
|
|
49
52
|
import {yui_tabulator_name_filters} from "./yui_tabulator_i18n.js";
|
|
50
53
|
import {yui_table_filter_clear} from "./yui_table_filter_clear.js";
|
|
51
54
|
|
|
@@ -64,17 +67,29 @@ const YUI_TABLE_FILTER_MIN_WIDTH = 150;
|
|
|
64
67
|
const CONTROL_FORMATTERS = ["rowSelection", "handle", "responsiveCollapse", "buttonCross"];
|
|
65
68
|
|
|
66
69
|
|
|
70
|
+
/***************************************************************
|
|
71
|
+
* The word of the row count, in the app's language and plural.
|
|
72
|
+
***************************************************************/
|
|
73
|
+
function rows_word(count)
|
|
74
|
+
{
|
|
75
|
+
return i18next.t("rows", {count: count, defaultValue: count === 1 ? "row" : "rows"});
|
|
76
|
+
}
|
|
77
|
+
|
|
67
78
|
/***************************************************************
|
|
68
79
|
* The row count of the footer.
|
|
69
80
|
*
|
|
70
81
|
* Called by Tabulator with `this` = its pagination module, on
|
|
71
82
|
* every page, filter and data change. `total_rows` is the ACTIVE
|
|
72
|
-
* count: the rows the filters leave, all pages together.
|
|
83
|
+
* count: the rows the filters leave, all pages together. With a
|
|
84
|
+
* filter on, the count says both: "12 / 27 rows".
|
|
73
85
|
*
|
|
74
|
-
* The number is data
|
|
75
|
-
* (`
|
|
76
|
-
*
|
|
77
|
-
*
|
|
86
|
+
* The number is data. The word is the app's plural of "rows"
|
|
87
|
+
* (`rows_one` for one, `rows` for the others; i18next falls back to
|
|
88
|
+
* `rows` when the form is missing), for the number it goes with: the
|
|
89
|
+
* total when there are two. Up to 7.32.4 it was one word for every
|
|
90
|
+
* number, "1 filas". `langBind` on the table's locale is only the
|
|
91
|
+
* trigger: `yui_tabulator_relocalize()` installs a new language and
|
|
92
|
+
* the word is asked again.
|
|
78
93
|
*
|
|
79
94
|
* Returns a DOM node, never a string: Tabulator puts a string in
|
|
80
95
|
* with `innerHTML`.
|
|
@@ -84,17 +99,29 @@ function rows_counter(page_size, current_row, current_page, total_rows)
|
|
|
84
99
|
let $count = document.createElement("span");
|
|
85
100
|
$count.className = "YUI_TABLE_COUNT";
|
|
86
101
|
|
|
102
|
+
/* With a filter on, both numbers: the rows it leaves of the rows
|
|
103
|
+
* the table holds ("12 / 27"). The status lines the apps kept under
|
|
104
|
+
* their tables said it that way, and this count replaces them. */
|
|
105
|
+
let shown = total_rows || 0;
|
|
106
|
+
let all = shown;
|
|
107
|
+
try {
|
|
108
|
+
if(this && this.table && typeof this.table.getDataCount === "function") {
|
|
109
|
+
all = this.table.getDataCount();
|
|
110
|
+
}
|
|
111
|
+
} catch(e) {
|
|
112
|
+
all = shown;
|
|
113
|
+
}
|
|
87
114
|
let $number = document.createElement("span");
|
|
88
115
|
$number.className = "YUI_TABLE_COUNT_NUMBER";
|
|
89
|
-
$number.textContent =
|
|
116
|
+
$number.textContent = (all > shown) ? `${shown} / ${all}` : String(shown);
|
|
90
117
|
|
|
91
118
|
let $word = document.createElement("span");
|
|
92
119
|
$word.className = "YUI_TABLE_COUNT_WORD";
|
|
93
|
-
$word.textContent =
|
|
120
|
+
$word.textContent = rows_word(all);
|
|
94
121
|
let localize = this && this.table && this.table.modules ? this.table.modules.localize : null;
|
|
95
122
|
if(localize && typeof localize.langBind === "function") {
|
|
96
|
-
localize.langBind("pagination|counter|rows", (
|
|
97
|
-
$word.textContent =
|
|
123
|
+
localize.langBind("pagination|counter|rows", () => {
|
|
124
|
+
$word.textContent = rows_word(all);
|
|
98
125
|
});
|
|
99
126
|
}
|
|
100
127
|
|
|
@@ -13,6 +13,13 @@ import {install_dom_double} from "../test/dom_double.js";
|
|
|
13
13
|
|
|
14
14
|
install_dom_double();
|
|
15
15
|
|
|
16
|
+
import i18next from "i18next";
|
|
17
|
+
|
|
18
|
+
await i18next.init({lng: "es", resources: {
|
|
19
|
+
es: {translation: {rows: "filas", rows_one: "fila"}},
|
|
20
|
+
en: {translation: {rows: "rows", rows_one: "row"}}
|
|
21
|
+
}});
|
|
22
|
+
|
|
16
23
|
import {
|
|
17
24
|
YUI_TABLE_FILTER_MIN_WIDTH,
|
|
18
25
|
yui_table_paging,
|
|
@@ -48,7 +55,7 @@ describe("the paging", () => {
|
|
|
48
55
|
});
|
|
49
56
|
|
|
50
57
|
describe("the row count", () => {
|
|
51
|
-
function page_module(
|
|
58
|
+
function page_module()
|
|
52
59
|
{
|
|
53
60
|
let bindings = [];
|
|
54
61
|
return {
|
|
@@ -57,8 +64,8 @@ describe("the row count", () => {
|
|
|
57
64
|
modules: {
|
|
58
65
|
localize: {
|
|
59
66
|
langBind(path, cb) {
|
|
60
|
-
bindings.push(path);
|
|
61
|
-
cb(
|
|
67
|
+
bindings.push({path, cb});
|
|
68
|
+
cb("ignored");
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
71
|
}
|
|
@@ -66,31 +73,50 @@ describe("the row count", () => {
|
|
|
66
73
|
};
|
|
67
74
|
}
|
|
68
75
|
|
|
69
|
-
test("says every active row, all pages together, in the
|
|
76
|
+
test("says every active row, all pages together, in the app's plural", () => {
|
|
70
77
|
let counter = yui_table_paging().paginationCounter;
|
|
71
|
-
let page = page_module(
|
|
78
|
+
let page = page_module();
|
|
72
79
|
let $el = counter.call(page, 25, 26, 2, 113, 5);
|
|
73
80
|
expect($el.textContent).toBe("113 filas");
|
|
74
|
-
expect(page.bindings).toEqual(["pagination|counter|rows"]);
|
|
81
|
+
expect(page.bindings.map((b) => b.path)).toEqual(["pagination|counter|rows"]);
|
|
82
|
+
expect(counter.call(page_module(), 25, 1, 1, 1, 1).textContent).toBe("1 fila");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("a language change asks the word again", async () => {
|
|
86
|
+
let counter = yui_table_paging().paginationCounter;
|
|
87
|
+
let page = page_module();
|
|
88
|
+
let $el = counter.call(page, 25, 1, 1, 1, 1);
|
|
89
|
+
await i18next.changeLanguage("en");
|
|
90
|
+
page.bindings[0].cb("ignored");
|
|
91
|
+
expect($el.textContent).toBe("1 row");
|
|
92
|
+
await i18next.changeLanguage("es");
|
|
75
93
|
});
|
|
76
94
|
|
|
77
95
|
test("an empty table says 0", () => {
|
|
78
96
|
let counter = yui_table_paging().paginationCounter;
|
|
79
|
-
let $el = counter.call(page_module(
|
|
80
|
-
expect($el.textContent).toBe("0
|
|
97
|
+
let $el = counter.call(page_module(), 25, 0, 1, 0, 0);
|
|
98
|
+
expect($el.textContent).toBe("0 filas");
|
|
81
99
|
});
|
|
82
100
|
|
|
83
101
|
test("is a node, never a string Tabulator would put in as html", () => {
|
|
84
102
|
let counter = yui_table_paging().paginationCounter;
|
|
85
|
-
let $el = counter.call(page_module(
|
|
103
|
+
let $el = counter.call(page_module(), 25, 1, 1, 3, 1);
|
|
86
104
|
expect(typeof $el).toBe("object");
|
|
87
105
|
expect($el.className).toBe("YUI_TABLE_COUNT");
|
|
88
106
|
});
|
|
89
107
|
|
|
90
|
-
test("
|
|
108
|
+
test("with a filter on, the rows it leaves of the rows the table holds", () => {
|
|
109
|
+
let counter = yui_table_paging().paginationCounter;
|
|
110
|
+
let page = page_module();
|
|
111
|
+
page.table.getDataCount = () => 27;
|
|
112
|
+
expect(counter.call(page, 25, 1, 1, 12, 1).textContent).toBe("12 / 27 filas");
|
|
113
|
+
expect(counter.call(page, 25, 1, 1, 27, 2).textContent).toBe("27 filas");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("without a localize module it still counts", () => {
|
|
91
117
|
let counter = yui_table_paging().paginationCounter;
|
|
92
118
|
let $el = counter.call({}, 25, 1, 1, 3, 1);
|
|
93
|
-
expect($el.textContent).toBe("3
|
|
119
|
+
expect($el.textContent).toBe("3 filas");
|
|
94
120
|
});
|
|
95
121
|
});
|
|
96
122
|
|