@yuneta/gobj-ui 7.27.22 → 7.27.24
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 +69 -3
- package/dist/gobj-ui.cjs.js +762 -121
- package/dist/gobj-ui.es.js +762 -121
- package/package.json +4 -1
- package/src/c_yui_gobj_tree_js.js +540 -25
- package/src/c_yui_json_graph.js +9 -3
- package/src/gobj_tree_camera.wiring.test.js +71 -1
- package/src/gobj_tree_model.js +104 -0
- package/src/gobj_tree_model.test.js +52 -1
- package/src/gobj_tree_remote.wiring.test.js +314 -0
- package/src/i18n_key_functions.js +2 -0
- package/src/yui_gobj_tree_view.js +246 -0
|
@@ -1,7 +1,42 @@
|
|
|
1
1
|
/***********************************************************************
|
|
2
2
|
* c_yui_gobj_tree_js.js
|
|
3
3
|
*
|
|
4
|
-
* Hierarchical tree graph (G6) of the gobj tree of
|
|
4
|
+
* Hierarchical tree graph (G6) of the gobj tree of a yuno.
|
|
5
|
+
*
|
|
6
|
+
* Two sources (`source`):
|
|
7
|
+
*
|
|
8
|
+
* - "local" (default): the yuno of THIS browser, read live.
|
|
9
|
+
* - "remote": a BACKEND yuno. The view cannot ask a backend
|
|
10
|
+
* anything -- it has no transport, and which link reaches
|
|
11
|
+
* the yuno is the host's business -- so it publishes what
|
|
12
|
+
* it WANTS and the host answers with the data:
|
|
13
|
+
*
|
|
14
|
+
* out EV_TREE_WANTED {} Refresh pressed
|
|
15
|
+
* in EV_LOAD_TREE {tree} the `view-gobj-tree` answer
|
|
16
|
+
* out EV_TRACE_INFO_WANTED {gclass} a card was opened
|
|
17
|
+
* in EV_TRACE_INFO {gclass, gclass_levels, global_levels,
|
|
18
|
+
* gclass_on, global_on, error}
|
|
19
|
+
* out EV_SET_TRACE_LEVEL {scope: "gobj"|"gclass", gobj,
|
|
20
|
+
* gclass, levels: [...], set}
|
|
21
|
+
* out EV_GCLASS_WANTED {gclass} the gclass button
|
|
22
|
+
* in EV_GCLASS_DESCRIPTION {gclass, description}
|
|
23
|
+
*
|
|
24
|
+
* The host loads the FIRST tree on its own (it opened the
|
|
25
|
+
* view); the view asks again only when Refresh is pressed.
|
|
26
|
+
* After a trace is set the host loads the tree and the
|
|
27
|
+
* trace info again: the card the reader is on stays open.
|
|
28
|
+
*
|
|
29
|
+
* In "remote" the popover of a card has a TRACES block: one
|
|
30
|
+
* row per level (the gclass' own, then the global ones), a
|
|
31
|
+
* checkbox for THIS gobj (`set-gobj-trace`) and one for every
|
|
32
|
+
* gobj of its gclass (`set-gclass-trace`). A level that is on
|
|
33
|
+
* for the gclass, or globally, is shown on and locked in the
|
|
34
|
+
* gobj column, with where it comes from: it cannot be turned
|
|
35
|
+
* off from one gobj. A gclass level is saved by the yuno and
|
|
36
|
+
* survives a restart; a gobj level lasts until the yuno ends.
|
|
37
|
+
*
|
|
38
|
+
* The output events are published ONLY in "remote", so a host
|
|
39
|
+
* of a local tree (the Frontend view) declares none of them.
|
|
5
40
|
*
|
|
6
41
|
* Copyright (c) 2025-2026, ArtGins.
|
|
7
42
|
* All Rights Reserved.
|
|
@@ -35,10 +70,12 @@ import {
|
|
|
35
70
|
escapeHtml,
|
|
36
71
|
log_warning,
|
|
37
72
|
refresh_language,
|
|
73
|
+
gobj_publish_event,
|
|
38
74
|
} from "@yuneta/gobj-js";
|
|
39
75
|
|
|
40
76
|
import {
|
|
41
77
|
describe_js_gobj,
|
|
78
|
+
describe_backend_tree,
|
|
42
79
|
node_badge_keys,
|
|
43
80
|
node_info_rows,
|
|
44
81
|
node_labels,
|
|
@@ -46,7 +83,10 @@ import {
|
|
|
46
83
|
node_status,
|
|
47
84
|
node_status_key,
|
|
48
85
|
node_status_symbol,
|
|
86
|
+
trace_rows,
|
|
87
|
+
own_trace_levels,
|
|
49
88
|
} from "./gobj_tree_model.js";
|
|
89
|
+
import {text_node} from "./yui_text.js";
|
|
50
90
|
import {
|
|
51
91
|
close_gclass_view,
|
|
52
92
|
gclass_view_available,
|
|
@@ -100,6 +140,10 @@ SDATA(data_type_t.DTP_POINTER, "subscriber", 0, null, "Subscriber of o
|
|
|
100
140
|
SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "Container element"),
|
|
101
141
|
SDATA(data_type_t.DTP_STRING, "canvas_id", 0, "", "Canvas ID"),
|
|
102
142
|
|
|
143
|
+
/*---------------- Source ----------------*/
|
|
144
|
+
SDATA(data_type_t.DTP_STRING, "source", 0, "local", "Whose tree: local (this browser yuno, read live) | remote (a backend yuno, loaded by the host with EV_LOAD_TREE)"),
|
|
145
|
+
SDATA(data_type_t.DTP_STRING, "yuno_name", 0, "", "remote: the name the yuno is shown by (the gclass window says it before the gclass)"),
|
|
146
|
+
|
|
103
147
|
/*---------------- Graph Settings ----------------*/
|
|
104
148
|
SDATA(data_type_t.DTP_STRING, "wide", 0, "40px", "Height of header. 40px and not 36: it is what an untouched Bulma control measures, so the find box stood 4px taller than every button beside it, and it is what the third graph of the family (C_YUI_TREEDB_GRAPH) uses"),
|
|
105
149
|
SDATA(data_type_t.DTP_STRING, "layout", 0, "vertical-compact", "Current layout key"),
|
|
@@ -198,19 +242,37 @@ function restore_view_state(gobj)
|
|
|
198
242
|
return false;
|
|
199
243
|
}
|
|
200
244
|
|
|
245
|
+
/* A camera saved by an older version can hold nulls (a NaN written
|
|
246
|
+
* as json): what is not a number is not restored. */
|
|
247
|
+
let zoom = (Number.isFinite(state.zoom) && state.zoom > 0)? state.zoom: null;
|
|
248
|
+
let position = (Array.isArray(state.position) && state.position.length >= 2 &&
|
|
249
|
+
Number.isFinite(state.position[0]) && Number.isFinite(state.position[1]))?
|
|
250
|
+
[state.position[0], state.position[1]]: null;
|
|
251
|
+
|
|
252
|
+
/* Nor a camera that would show none of the tree. One was saved from
|
|
253
|
+
* an EMPTY graph -- a remote tree is empty until its host loads it,
|
|
254
|
+
* and a fit pressed then frames nothing -- and every opening after
|
|
255
|
+
* it went back to the same blank canvas. It is judged from the
|
|
256
|
+
* numbers BEFORE it is applied, so a refused camera never moves the
|
|
257
|
+
* graph: the opening frames the tree as a first one does, and the
|
|
258
|
+
* next move saves a good camera. */
|
|
259
|
+
if((zoom !== null || position !== null) && !camera_shows_a_card(gobj, zoom, position)) {
|
|
260
|
+
log_warning(`${gobj_short_name(gobj)}: the saved view shows none of the ` +
|
|
261
|
+
`${Object.keys(priv.node_by_id || {}).length} gobjs, framed again`);
|
|
262
|
+
zoom = null;
|
|
263
|
+
position = null;
|
|
264
|
+
}
|
|
265
|
+
|
|
201
266
|
let done = false;
|
|
202
267
|
priv.restoring = true;
|
|
203
268
|
try {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
graph.zoomTo(state.zoom);
|
|
208
|
-
priv.last_zoom = state.zoom;
|
|
269
|
+
if(zoom !== null) {
|
|
270
|
+
graph.zoomTo(zoom);
|
|
271
|
+
priv.last_zoom = zoom;
|
|
209
272
|
done = true;
|
|
210
273
|
}
|
|
211
|
-
if(
|
|
212
|
-
|
|
213
|
-
graph.translateTo([state.position[0], state.position[1]]);
|
|
274
|
+
if(position !== null) {
|
|
275
|
+
graph.translateTo(position);
|
|
214
276
|
done = true;
|
|
215
277
|
}
|
|
216
278
|
if(state.anchor) {
|
|
@@ -232,6 +294,46 @@ function restore_view_state(gobj)
|
|
|
232
294
|
return done;
|
|
233
295
|
}
|
|
234
296
|
|
|
297
|
+
/* Would the centre of at least one card land inside the canvas under
|
|
298
|
+
* this camera? `zoom` and `position` are what getZoom()/getPosition()
|
|
299
|
+
* answer (a null one: the current). A camera absolute-translated to T
|
|
300
|
+
* at zoom Z puts a point n of the graph at (n - C) * Z + T + C on the
|
|
301
|
+
* canvas, C its centre -- the closed form of G6's own
|
|
302
|
+
* getTranslateOptions(), the one yui_graph_center_on() relies on.
|
|
303
|
+
* True when there is nothing to show or it cannot be computed: only a
|
|
304
|
+
* camera KNOWN to show nothing is refused. */
|
|
305
|
+
function camera_shows_a_card(gobj, zoom, position)
|
|
306
|
+
{
|
|
307
|
+
let priv = gobj.priv;
|
|
308
|
+
let graph = priv.graph;
|
|
309
|
+
let ids = Object.keys(priv.node_by_id || {});
|
|
310
|
+
if(!graph || !ids.length) {
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
try {
|
|
314
|
+
let size = graph.getSize();
|
|
315
|
+
let c = graph.getCanvasCenter();
|
|
316
|
+
let z = (zoom !== null)? zoom: graph.getZoom();
|
|
317
|
+
let t = (position !== null)? position: graph.getPosition();
|
|
318
|
+
let w = size[0];
|
|
319
|
+
let h = size[1];
|
|
320
|
+
if(!(w > 0 && h > 0) || !(z > 0)) {
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
for(let id of ids) {
|
|
324
|
+
let n = graph.getElementPosition(id);
|
|
325
|
+
let vx = (n[0] - c[0]) * z + t[0] + c[0];
|
|
326
|
+
let vy = (n[1] - c[1]) * z + t[1] + c[1];
|
|
327
|
+
if(vx >= 0 && vx <= w && vy >= 0 && vy <= h) {
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
} catch(e) {
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
|
|
235
337
|
function save_view_state(gobj)
|
|
236
338
|
{
|
|
237
339
|
let priv = gobj.priv;
|
|
@@ -247,8 +349,13 @@ function save_view_state(gobj)
|
|
|
247
349
|
anchor: (priv.anchor_state === "on")? priv.anchor_name: "",
|
|
248
350
|
};
|
|
249
351
|
let camera = null;
|
|
352
|
+
/* The camera of an EMPTY graph frames nothing: a remote tree before
|
|
353
|
+
* its host loads it, where a fit or a zoom would save a view of no
|
|
354
|
+
* card that every later opening goes back to. Not saved; the one
|
|
355
|
+
* saved before stays (below). */
|
|
356
|
+
let has_nodes = !!priv.node_by_id && Object.keys(priv.node_by_id).length > 0;
|
|
250
357
|
try {
|
|
251
|
-
camera = camera_of(graph.getZoom(), graph.getPosition());
|
|
358
|
+
camera = has_nodes ? camera_of(graph.getZoom(), graph.getPosition()) : null;
|
|
252
359
|
} catch(e) {
|
|
253
360
|
/* between renders: keep the rest, the camera is not readable */
|
|
254
361
|
}
|
|
@@ -334,6 +441,11 @@ let PRIVATE_DATA = {
|
|
|
334
441
|
restoring: false, // guards the store against its own restore
|
|
335
442
|
restored: false, // the saved arrangement is applied ONCE
|
|
336
443
|
last_zoom: 1, // tells a wheel zoom from a drag in aftertransform
|
|
444
|
+
|
|
445
|
+
/*---------------- source "remote" ----------------*/
|
|
446
|
+
remote_root: null, // the descriptor of the backend tree, as last loaded
|
|
447
|
+
trace_info: {}, // gclass -> {gclass_levels, global_levels, gclass_on, global_on, error}
|
|
448
|
+
trace_pending: false, // a trace was set: the block is locked until the host answers
|
|
337
449
|
};
|
|
338
450
|
|
|
339
451
|
let __gclass__ = null;
|
|
@@ -1688,14 +1800,17 @@ function load_tree(gobj)
|
|
|
1688
1800
|
/*
|
|
1689
1801
|
* The tree, as data.
|
|
1690
1802
|
*
|
|
1691
|
-
* The graph draws DESCRIPTORS, so this is the one
|
|
1692
|
-
* says which yuno is on screen
|
|
1693
|
-
*
|
|
1694
|
-
*
|
|
1695
|
-
* below this point changes.
|
|
1803
|
+
* The graph draws DESCRIPTORS, so this is the one place that
|
|
1804
|
+
* says which yuno is on screen: this browser's, read live, or
|
|
1805
|
+
* a backend's, as the host last loaded it (EV_LOAD_TREE).
|
|
1806
|
+
* Nothing below this point knows the difference.
|
|
1696
1807
|
*/
|
|
1697
|
-
let
|
|
1808
|
+
let remote = is_remote(gobj);
|
|
1809
|
+
let root = remote? priv.remote_root: describe_js_gobj(gobj_yuno(), true);
|
|
1698
1810
|
if(!root) {
|
|
1811
|
+
if(remote) {
|
|
1812
|
+
return; /* not loaded yet: the host loads the first tree */
|
|
1813
|
+
}
|
|
1699
1814
|
log_error(`${gobj_short_name(gobj)}: no yuno to draw`);
|
|
1700
1815
|
return;
|
|
1701
1816
|
}
|
|
@@ -1763,9 +1878,19 @@ function load_tree(gobj)
|
|
|
1763
1878
|
* -- never parked at the layout's origin, which is a
|
|
1764
1879
|
* corner with nothing in it.
|
|
1765
1880
|
*/
|
|
1766
|
-
Promise.resolve(graph.zoomTo(1)).then(() => {
|
|
1767
|
-
|
|
1768
|
-
|
|
1881
|
+
Promise.resolve(graph.zoomTo(1)).then(async () => {
|
|
1882
|
+
/* yui_graph_center_on() is ASYNC: unawaited, its answer
|
|
1883
|
+
* is a promise, always truthy, so `!` of it was always
|
|
1884
|
+
* false and the root was never centred -- the opening
|
|
1885
|
+
* stayed wherever the camera happened to be. (And the
|
|
1886
|
+
* root is at y = 0, a camera coordinate @antv/g-lite
|
|
1887
|
+
* below 2.7.2 could not reach: its createVec3() read
|
|
1888
|
+
* `x[1] || y`, so a 0 kept the old value. package.json
|
|
1889
|
+
* holds the antv floors that bring 2.7.2.) */
|
|
1890
|
+
let on_anchor = priv.anchor_id?
|
|
1891
|
+
await yui_graph_center_on(graph, priv.anchor_id): false;
|
|
1892
|
+
if(!on_anchor) {
|
|
1893
|
+
await yui_graph_center_on(graph, root_id);
|
|
1769
1894
|
}
|
|
1770
1895
|
priv.last_zoom = 1;
|
|
1771
1896
|
yui_graph_update_zoom(gobj_read_attr(gobj, "$container"), priv.graph);
|
|
@@ -1912,6 +2037,220 @@ function render_popover_body(gobj, node_data)
|
|
|
1912
2037
|
`).join("");
|
|
1913
2038
|
|
|
1914
2039
|
$body.innerHTML = rows_html;
|
|
2040
|
+
|
|
2041
|
+
if(is_remote(gobj)) {
|
|
2042
|
+
$body.appendChild(build_traces_block(gobj, node_data));
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
/************************************************************
|
|
2047
|
+
* Whose tree this is.
|
|
2048
|
+
************************************************************/
|
|
2049
|
+
function is_remote(gobj)
|
|
2050
|
+
{
|
|
2051
|
+
return gobj_read_str_attr(gobj, "source") === "remote";
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
/************************************************************
|
|
2055
|
+
* The TRACES block of a backend gobj's popover.
|
|
2056
|
+
*
|
|
2057
|
+
* Two columns of checkboxes, THIS gobj and every gobj of its
|
|
2058
|
+
* gclass, one row per level (trace_rows() in the model says
|
|
2059
|
+
* what each row holds). A box is an action: its change is
|
|
2060
|
+
* sent to the FSM, which publishes it to the host, and the
|
|
2061
|
+
* block stays locked until the host has loaded what the
|
|
2062
|
+
* backend says now -- the box shows the backend's state, not
|
|
2063
|
+
* the click.
|
|
2064
|
+
************************************************************/
|
|
2065
|
+
const TRACES_NOTE_STYLE = 'color:var(--bulma-text-weak, #6B7280); margin:4px 0;';
|
|
2066
|
+
const TRACES_CELL_STYLE = 'padding:1px 4px; text-align:center;';
|
|
2067
|
+
|
|
2068
|
+
function build_traces_block(gobj, d)
|
|
2069
|
+
{
|
|
2070
|
+
let priv = gobj.priv;
|
|
2071
|
+
let info = priv.trace_info[d.gclass] || null;
|
|
2072
|
+
|
|
2073
|
+
let kids = [
|
|
2074
|
+
['div', {class: 'GOBJ_TREE_TRACES_HEAD', i18n: 'traces',
|
|
2075
|
+
style: 'font-weight:700; margin:8px 0 2px 0; ' +
|
|
2076
|
+
'padding-top:6px; border-top:1px solid var(--bulma-border-weak, #E5E7EB);'},
|
|
2077
|
+
t('traces')]
|
|
2078
|
+
];
|
|
2079
|
+
|
|
2080
|
+
if(!info) {
|
|
2081
|
+
kids.push(['div', {class: 'GOBJ_TREE_TRACES_NOTE', i18n: 'loading',
|
|
2082
|
+
style: TRACES_NOTE_STYLE}, t('loading')]);
|
|
2083
|
+
return createElement2(['div', {class: 'GOBJ_TREE_TRACES'}, kids]);
|
|
2084
|
+
}
|
|
2085
|
+
if(info.error) {
|
|
2086
|
+
kids.push(['div', {class: 'GOBJ_TREE_TRACES_ERROR',
|
|
2087
|
+
style: 'color:var(--bulma-danger, #dc2626); margin:4px 0;'},
|
|
2088
|
+
text_node(info.error)]);
|
|
2089
|
+
return createElement2(['div', {class: 'GOBJ_TREE_TRACES'}, kids]);
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
let rows = trace_rows(d, info);
|
|
2093
|
+
let pending = !!priv.trace_pending;
|
|
2094
|
+
|
|
2095
|
+
let trs = [];
|
|
2096
|
+
let group = "";
|
|
2097
|
+
for(let r of rows) {
|
|
2098
|
+
if(r.group !== group) {
|
|
2099
|
+
group = r.group;
|
|
2100
|
+
let $label = (group === "gclass")?
|
|
2101
|
+
text_node(d.gclass):
|
|
2102
|
+
createElement2(['span', {i18n: 'global'}, t('global')]);
|
|
2103
|
+
trs.push(['tr', {class: 'GOBJ_TREE_TRACES_GROUP'}, [
|
|
2104
|
+
['td', {colspan: 3, style: 'padding:4px 4px 1px 4px; font-weight:600; ' +
|
|
2105
|
+
'color:var(--bulma-text-weak, #6B7280);'}, [$label]]
|
|
2106
|
+
]]);
|
|
2107
|
+
}
|
|
2108
|
+
let origin = null;
|
|
2109
|
+
if(r.origin === "global") {
|
|
2110
|
+
origin = ['span', {class: 'GOBJ_TREE_TRACES_ORIGIN', i18n: 'global',
|
|
2111
|
+
style: 'margin-left:6px; color:var(--bulma-text-weak, #6B7280);'},
|
|
2112
|
+
t('global')];
|
|
2113
|
+
} else if(r.origin === "gclass") {
|
|
2114
|
+
origin = ['span', {class: 'GOBJ_TREE_TRACES_ORIGIN', i18n: 'gclass',
|
|
2115
|
+
style: 'margin-left:6px; color:var(--bulma-text-weak, #6B7280);'},
|
|
2116
|
+
t('gclass')];
|
|
2117
|
+
}
|
|
2118
|
+
let $level = createElement2(['td', {class: 'GOBJ_TREE_TRACES_LEVEL',
|
|
2119
|
+
style: 'padding:1px 4px; word-break:break-all;'}, []]);
|
|
2120
|
+
$level.appendChild(text_node(r.level));
|
|
2121
|
+
if(origin) {
|
|
2122
|
+
$level.appendChild(createElement2(origin));
|
|
2123
|
+
}
|
|
2124
|
+
/* What the level does is the backend's text: data, not a key. */
|
|
2125
|
+
$level.setAttribute('title', r.description);
|
|
2126
|
+
|
|
2127
|
+
trs.push(['tr', {class: 'GOBJ_TREE_TRACES_ROW'}, [
|
|
2128
|
+
$level,
|
|
2129
|
+
['td', {style: TRACES_CELL_STYLE}, [
|
|
2130
|
+
trace_checkbox(gobj, "gobj", r.level, r.gobj_on, pending || r.gobj_locked)
|
|
2131
|
+
]],
|
|
2132
|
+
['td', {style: TRACES_CELL_STYLE}, [
|
|
2133
|
+
trace_checkbox(gobj, "gclass", r.level, r.gclass_on, pending || r.gclass_locked)
|
|
2134
|
+
]],
|
|
2135
|
+
]]);
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
kids.push(['table', {class: 'GOBJ_TREE_TRACES_TABLE',
|
|
2139
|
+
style: 'width:100%; border-collapse:collapse;'}, [
|
|
2140
|
+
['thead', {}, [
|
|
2141
|
+
['tr', {}, [
|
|
2142
|
+
['th', {i18n: 'level', style: 'padding:1px 4px; text-align:left;'}, t('level')],
|
|
2143
|
+
['th', {i18n: 'this gobj', style: TRACES_CELL_STYLE}, t('this gobj')],
|
|
2144
|
+
['th', {i18n: 'all of the gclass', style: TRACES_CELL_STYLE}, t('all of the gclass')],
|
|
2145
|
+
]]
|
|
2146
|
+
]],
|
|
2147
|
+
['tbody', {}, trs]
|
|
2148
|
+
]]);
|
|
2149
|
+
|
|
2150
|
+
kids.push(['div', {class: 'GOBJ_TREE_TRACES_NOTE',
|
|
2151
|
+
i18n: 'gclass traces survive a restart, gobj traces end with the yuno',
|
|
2152
|
+
style: TRACES_NOTE_STYLE},
|
|
2153
|
+
t('gclass traces survive a restart, gobj traces end with the yuno')]);
|
|
2154
|
+
|
|
2155
|
+
let none_gobj = pending || own_trace_levels(rows, "gobj").length === 0;
|
|
2156
|
+
let none_gclass = pending || own_trace_levels(rows, "gclass").length === 0;
|
|
2157
|
+
let btn_style = 'padding:0 8px; height:22px; font-size:11px; white-space:nowrap;';
|
|
2158
|
+
let clear = (scope) => {
|
|
2159
|
+
return {
|
|
2160
|
+
click: (evt) => {
|
|
2161
|
+
evt.stopPropagation();
|
|
2162
|
+
gobj_send_event(gobj, "EV_TRACES_CLEARED", {scope: scope}, gobj);
|
|
2163
|
+
}
|
|
2164
|
+
};
|
|
2165
|
+
};
|
|
2166
|
+
let $clear_gobj = createElement2(['button', {
|
|
2167
|
+
type: 'button', class: 'GOBJ_TREE_TRACES_CLEAR_GOBJ button is-small', style: btn_style,
|
|
2168
|
+
i18n: 'remove the traces of this gobj',
|
|
2169
|
+
title: t('remove the traces of this gobj'),
|
|
2170
|
+
'data-i18n-title': 'remove the traces of this gobj',
|
|
2171
|
+
'aria-label': t('remove the traces of this gobj'),
|
|
2172
|
+
'data-i18n-aria-label': 'remove the traces of this gobj',
|
|
2173
|
+
}, t('remove the traces of this gobj'), clear("gobj")]);
|
|
2174
|
+
let $clear_gclass = createElement2(['button', {
|
|
2175
|
+
type: 'button', class: 'GOBJ_TREE_TRACES_CLEAR_GCLASS button is-small', style: btn_style,
|
|
2176
|
+
i18n: 'remove the traces of the gclass',
|
|
2177
|
+
title: t('remove the traces of the gclass'),
|
|
2178
|
+
'data-i18n-title': 'remove the traces of the gclass',
|
|
2179
|
+
'aria-label': t('remove the traces of the gclass'),
|
|
2180
|
+
'data-i18n-aria-label': 'remove the traces of the gclass',
|
|
2181
|
+
}, t('remove the traces of the gclass'), clear("gclass")]);
|
|
2182
|
+
$clear_gobj.disabled = none_gobj;
|
|
2183
|
+
$clear_gclass.disabled = none_gclass;
|
|
2184
|
+
kids.push(['div', {class: 'GOBJ_TREE_TRACES_TOOLS',
|
|
2185
|
+
style: 'display:flex; flex-wrap:wrap; gap:4px; margin-top:4px;'},
|
|
2186
|
+
[$clear_gobj, $clear_gclass]]);
|
|
2187
|
+
|
|
2188
|
+
return createElement2(['div', {class: 'GOBJ_TREE_TRACES'}, kids]);
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
/* One box of the block. `checked` and `disabled` are set as
|
|
2192
|
+
* PROPERTIES: createElement2 writes attributes, and an attribute
|
|
2193
|
+
* `checked="false"` is a checked box. */
|
|
2194
|
+
function trace_checkbox(gobj, scope, level, on, locked)
|
|
2195
|
+
{
|
|
2196
|
+
let $cb = null;
|
|
2197
|
+
if(scope === "gobj") {
|
|
2198
|
+
$cb = createElement2(['input', {
|
|
2199
|
+
type: 'checkbox', class: 'GOBJ_TREE_TRACE_GOBJ',
|
|
2200
|
+
title: t('this gobj'), 'data-i18n-title': 'this gobj',
|
|
2201
|
+
'aria-label': t('this gobj'), 'data-i18n-aria-label': 'this gobj',
|
|
2202
|
+
}]);
|
|
2203
|
+
} else {
|
|
2204
|
+
$cb = createElement2(['input', {
|
|
2205
|
+
type: 'checkbox', class: 'GOBJ_TREE_TRACE_GCLASS',
|
|
2206
|
+
title: t('all of the gclass'), 'data-i18n-title': 'all of the gclass',
|
|
2207
|
+
'aria-label': t('all of the gclass'), 'data-i18n-aria-label': 'all of the gclass',
|
|
2208
|
+
}]);
|
|
2209
|
+
}
|
|
2210
|
+
$cb.setAttribute('data-level', level);
|
|
2211
|
+
$cb.checked = !!on;
|
|
2212
|
+
$cb.disabled = !!locked;
|
|
2213
|
+
$cb.addEventListener('change', (evt) => {
|
|
2214
|
+
evt.stopPropagation();
|
|
2215
|
+
gobj_send_event(gobj, "EV_TRACE_TOGGLED",
|
|
2216
|
+
{scope: scope, level: level, set: !!evt.target.checked}, gobj);
|
|
2217
|
+
});
|
|
2218
|
+
return $cb;
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
/************************************************************
|
|
2222
|
+
* Rebuild the graph and leave the popover where it was, on
|
|
2223
|
+
* the same gobj -- by full name, the node ids are new. A
|
|
2224
|
+
* reader who just ticked a trace is still reading that card.
|
|
2225
|
+
************************************************************/
|
|
2226
|
+
function reload_keeping_popover(gobj, opts)
|
|
2227
|
+
{
|
|
2228
|
+
let priv = gobj.priv;
|
|
2229
|
+
let $popover = priv.$popover;
|
|
2230
|
+
let keep = (priv.popover_node && $popover && $popover.style.display === "block")?
|
|
2231
|
+
priv.popover_node.full_name: null;
|
|
2232
|
+
let left = $popover? $popover.style.left: "";
|
|
2233
|
+
let top = $popover? $popover.style.top: "";
|
|
2234
|
+
|
|
2235
|
+
refresh_tree(gobj, opts); /* hides the popover */
|
|
2236
|
+
|
|
2237
|
+
if(!keep || !priv.node_by_id) {
|
|
2238
|
+
return;
|
|
2239
|
+
}
|
|
2240
|
+
for(let id of Object.keys(priv.node_by_id)) {
|
|
2241
|
+
let d = priv.node_by_id[id];
|
|
2242
|
+
if(d.full_name === keep) {
|
|
2243
|
+
priv.popover_node = d;
|
|
2244
|
+
priv.$popover_title.textContent = d.short_name ||
|
|
2245
|
+
(d.gclass + (d.name ? "^" + d.name : ""));
|
|
2246
|
+
priv.$popover_title.title = priv.$popover_title.textContent;
|
|
2247
|
+
render_popover_body(gobj, d);
|
|
2248
|
+
$popover.style.left = left;
|
|
2249
|
+
$popover.style.top = top;
|
|
2250
|
+
$popover.style.display = "block";
|
|
2251
|
+
return;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
1915
2254
|
}
|
|
1916
2255
|
|
|
1917
2256
|
/************************************************************
|
|
@@ -2370,6 +2709,11 @@ function ac_find_nodes(gobj, event, kw, src)
|
|
|
2370
2709
|
function ac_refresh(gobj, event, kw, src)
|
|
2371
2710
|
{
|
|
2372
2711
|
save_view_state(gobj);
|
|
2712
|
+
if(is_remote(gobj)) {
|
|
2713
|
+
/* The backend has the tree: the host fetches it and loads it. */
|
|
2714
|
+
gobj_publish_event(gobj, "EV_TREE_WANTED", {});
|
|
2715
|
+
return 0;
|
|
2716
|
+
}
|
|
2373
2717
|
refresh_tree(gobj);
|
|
2374
2718
|
return 0;
|
|
2375
2719
|
}
|
|
@@ -2806,6 +3150,12 @@ function ac_node_click(gobj, event, kw, src)
|
|
|
2806
3150
|
let client_y = kw.client_y || 0;
|
|
2807
3151
|
show_popover(gobj, node_data, client_x, client_y);
|
|
2808
3152
|
|
|
3153
|
+
/* Asked on every opening, not cached for good: another reader,
|
|
3154
|
+
* or a restart, may have changed what the gclass traces. */
|
|
3155
|
+
if(is_remote(gobj)) {
|
|
3156
|
+
gobj_publish_event(gobj, "EV_TRACE_INFO_WANTED", {gclass: node_data.gclass});
|
|
3157
|
+
}
|
|
3158
|
+
|
|
2809
3159
|
return 0;
|
|
2810
3160
|
}
|
|
2811
3161
|
|
|
@@ -2895,25 +3245,62 @@ function ac_open_gclass(gobj, event, kw, src)
|
|
|
2895
3245
|
return -1;
|
|
2896
3246
|
}
|
|
2897
3247
|
|
|
3248
|
+
/* A backend gclass is not in this registry (or worse, one of the
|
|
3249
|
+
* same name is, and describes the BROWSER's): its `view-gclass`
|
|
3250
|
+
* is fetched by the host and comes back as EV_GCLASS_DESCRIPTION. */
|
|
3251
|
+
if(is_remote(gobj)) {
|
|
3252
|
+
gobj_publish_event(gobj, "EV_GCLASS_WANTED", {gclass: node_data.gclass});
|
|
3253
|
+
return 0;
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3256
|
+
open_gclass_window(gobj, node_data.gclass, null, node_data.state || "");
|
|
3257
|
+
|
|
3258
|
+
return 0;
|
|
3259
|
+
}
|
|
3260
|
+
|
|
3261
|
+
/************************************************************
|
|
3262
|
+
* remote: the `view-gclass` answer the host fetched.
|
|
3263
|
+
************************************************************/
|
|
3264
|
+
function ac_gclass_description(gobj, event, kw, src)
|
|
3265
|
+
{
|
|
3266
|
+
let priv = gobj.priv;
|
|
3267
|
+
if(!kw || !kw.gclass || !kw.description || typeof kw.description !== "object") {
|
|
3268
|
+
log_error(`${gobj_short_name(gobj)}: EV_GCLASS_DESCRIPTION without a gclass description`);
|
|
3269
|
+
return -1;
|
|
3270
|
+
}
|
|
3271
|
+
let d = priv.popover_node;
|
|
3272
|
+
open_gclass_window(gobj, kw.gclass, kw.description,
|
|
3273
|
+
(d && d.gclass === kw.gclass)? (d.state || ""): "");
|
|
3274
|
+
return 0;
|
|
3275
|
+
}
|
|
3276
|
+
|
|
3277
|
+
/* One window at a time: a second gclass replaces the first. */
|
|
3278
|
+
function open_gclass_window(gobj, gclass, description, state)
|
|
3279
|
+
{
|
|
3280
|
+
let priv = gobj.priv;
|
|
3281
|
+
|
|
2898
3282
|
close_gclass_view(priv.gclass_view);
|
|
2899
3283
|
priv.gclass_view = null;
|
|
2900
3284
|
|
|
2901
|
-
|
|
2902
|
-
title_prefix:
|
|
3285
|
+
let opts = {
|
|
3286
|
+
title_prefix: is_remote(gobj)?
|
|
3287
|
+
(gobj_read_str_attr(gobj, "yuno_name") || ""): (gobj_yuno_name() || ""),
|
|
2903
3288
|
/* Which state THIS gobj is in. The description describes the
|
|
2904
3289
|
* CLASS and cannot carry it, and the tree is the only party
|
|
2905
3290
|
* that knows -- so the machine lights the column the reader
|
|
2906
3291
|
* is actually standing in. */
|
|
2907
|
-
current_state:
|
|
3292
|
+
current_state: state,
|
|
2908
3293
|
on_close: () => {
|
|
2909
3294
|
if(gobj_is_destroying(gobj)) {
|
|
2910
3295
|
return;
|
|
2911
3296
|
}
|
|
2912
3297
|
gobj_send_event(gobj, "EV_GCLASS_CLOSED", {}, gobj);
|
|
2913
3298
|
},
|
|
2914
|
-
}
|
|
2915
|
-
|
|
2916
|
-
|
|
3299
|
+
};
|
|
3300
|
+
if(description) {
|
|
3301
|
+
opts.description = description;
|
|
3302
|
+
}
|
|
3303
|
+
priv.gclass_view = open_gclass_view(gobj, /* i18n: data */ gclass, opts);
|
|
2917
3304
|
}
|
|
2918
3305
|
|
|
2919
3306
|
/************************************************************
|
|
@@ -2929,6 +3316,119 @@ function ac_gclass_closed(gobj, event, kw, src)
|
|
|
2929
3316
|
return 0;
|
|
2930
3317
|
}
|
|
2931
3318
|
|
|
3319
|
+
/************************************************************
|
|
3320
|
+
* remote: the host loaded the tree (`view-gobj-tree`).
|
|
3321
|
+
*
|
|
3322
|
+
* The first one is framed like any opening; the next ones
|
|
3323
|
+
* keep the camera and the card the reader is on.
|
|
3324
|
+
************************************************************/
|
|
3325
|
+
function ac_load_tree(gobj, event, kw, src)
|
|
3326
|
+
{
|
|
3327
|
+
let priv = gobj.priv;
|
|
3328
|
+
if(!is_remote(gobj)) {
|
|
3329
|
+
log_error(`${gobj_short_name(gobj)}: EV_LOAD_TREE on a tree whose source is not remote`);
|
|
3330
|
+
return -1;
|
|
3331
|
+
}
|
|
3332
|
+
let root = describe_backend_tree(kw && kw.tree);
|
|
3333
|
+
if(!root) {
|
|
3334
|
+
log_warning(`${gobj_short_name(gobj)}: what was loaded is not a view-gobj-tree answer`);
|
|
3335
|
+
return -1;
|
|
3336
|
+
}
|
|
3337
|
+
let first = !priv.remote_root;
|
|
3338
|
+
priv.remote_root = root;
|
|
3339
|
+
priv.trace_pending = false;
|
|
3340
|
+
reload_keeping_popover(gobj, first? {}: {preserve_view: true});
|
|
3341
|
+
return 0;
|
|
3342
|
+
}
|
|
3343
|
+
|
|
3344
|
+
/************************************************************
|
|
3345
|
+
* remote: the trace levels of a gclass, as the backend has
|
|
3346
|
+
* them now (or why they could not be read).
|
|
3347
|
+
************************************************************/
|
|
3348
|
+
function ac_trace_info(gobj, event, kw, src)
|
|
3349
|
+
{
|
|
3350
|
+
let priv = gobj.priv;
|
|
3351
|
+
if(!kw || !kw.gclass) {
|
|
3352
|
+
log_error(`${gobj_short_name(gobj)}: EV_TRACE_INFO without a gclass`);
|
|
3353
|
+
return -1;
|
|
3354
|
+
}
|
|
3355
|
+
let list = (x) => Array.isArray(x)? x: [];
|
|
3356
|
+
priv.trace_info[kw.gclass] = {
|
|
3357
|
+
gclass_levels: kw.gclass_levels || {},
|
|
3358
|
+
global_levels: kw.global_levels || {},
|
|
3359
|
+
gclass_on: list(kw.gclass_on),
|
|
3360
|
+
global_on: list(kw.global_on),
|
|
3361
|
+
error: kw.error || "",
|
|
3362
|
+
};
|
|
3363
|
+
priv.trace_pending = false;
|
|
3364
|
+
|
|
3365
|
+
let d = priv.popover_node;
|
|
3366
|
+
if(d && d.gclass === kw.gclass && priv.$popover && priv.$popover.style.display === "block") {
|
|
3367
|
+
render_popover_body(gobj, d);
|
|
3368
|
+
}
|
|
3369
|
+
return 0;
|
|
3370
|
+
}
|
|
3371
|
+
|
|
3372
|
+
/************************************************************
|
|
3373
|
+
* A box of the TRACES block was ticked or cleared.
|
|
3374
|
+
************************************************************/
|
|
3375
|
+
function ac_trace_toggled(gobj, event, kw, src)
|
|
3376
|
+
{
|
|
3377
|
+
let priv = gobj.priv;
|
|
3378
|
+
let d = priv.popover_node;
|
|
3379
|
+
if(!is_remote(gobj) || !d) {
|
|
3380
|
+
log_error(`${gobj_short_name(gobj)}: a trace set with no backend card open`);
|
|
3381
|
+
return -1;
|
|
3382
|
+
}
|
|
3383
|
+
if(!kw.level || (kw.scope !== "gobj" && kw.scope !== "gclass")) {
|
|
3384
|
+
log_error(`${gobj_short_name(gobj)}: a trace set of no level or scope: ` +
|
|
3385
|
+
`'${kw.scope}' '${kw.level}'`);
|
|
3386
|
+
return -1;
|
|
3387
|
+
}
|
|
3388
|
+
set_trace_levels(gobj, d, kw.scope, [kw.level], !!kw.set);
|
|
3389
|
+
return 0;
|
|
3390
|
+
}
|
|
3391
|
+
|
|
3392
|
+
/************************************************************
|
|
3393
|
+
* "Remove the traces" of the gobj or of its gclass: every
|
|
3394
|
+
* level that scope holds on its own.
|
|
3395
|
+
************************************************************/
|
|
3396
|
+
function ac_traces_cleared(gobj, event, kw, src)
|
|
3397
|
+
{
|
|
3398
|
+
let priv = gobj.priv;
|
|
3399
|
+
let d = priv.popover_node;
|
|
3400
|
+
if(!is_remote(gobj) || !d) {
|
|
3401
|
+
log_error(`${gobj_short_name(gobj)}: traces removed with no backend card open`);
|
|
3402
|
+
return -1;
|
|
3403
|
+
}
|
|
3404
|
+
let rows = trace_rows(d, priv.trace_info[d.gclass]);
|
|
3405
|
+
let levels = own_trace_levels(rows, kw.scope);
|
|
3406
|
+
if(!levels.length) {
|
|
3407
|
+
/* The button is off when there is nothing: reaching here is
|
|
3408
|
+
* a button that did not follow the block. */
|
|
3409
|
+
log_error(`${gobj_short_name(gobj)}: no ${kw.scope} trace of ${d.full_name} to remove`);
|
|
3410
|
+
return -1;
|
|
3411
|
+
}
|
|
3412
|
+
set_trace_levels(gobj, d, kw.scope, levels, false);
|
|
3413
|
+
return 0;
|
|
3414
|
+
}
|
|
3415
|
+
|
|
3416
|
+
/* Lock the block and hand the change to the host. The block is
|
|
3417
|
+
* repainted from what the backend says next, never from here. */
|
|
3418
|
+
function set_trace_levels(gobj, d, scope, levels, set)
|
|
3419
|
+
{
|
|
3420
|
+
let priv = gobj.priv;
|
|
3421
|
+
priv.trace_pending = true;
|
|
3422
|
+
render_popover_body(gobj, d);
|
|
3423
|
+
gobj_publish_event(gobj, "EV_SET_TRACE_LEVEL", {
|
|
3424
|
+
scope: scope,
|
|
3425
|
+
gobj: d.full_name,
|
|
3426
|
+
gclass: d.gclass,
|
|
3427
|
+
levels: levels,
|
|
3428
|
+
set: set,
|
|
3429
|
+
});
|
|
3430
|
+
}
|
|
3431
|
+
|
|
2932
3432
|
/************************************************************
|
|
2933
3433
|
* The app switched language.
|
|
2934
3434
|
*
|
|
@@ -3004,6 +3504,11 @@ function create_gclass(gclass_name)
|
|
|
3004
3504
|
["EV_OPEN_GCLASS", ac_open_gclass, null],
|
|
3005
3505
|
["EV_GCLASS_CLOSED", ac_gclass_closed, null],
|
|
3006
3506
|
["EV_LANGUAGE_CHANGED", ac_language_changed, null],
|
|
3507
|
+
["EV_LOAD_TREE", ac_load_tree, null],
|
|
3508
|
+
["EV_TRACE_INFO", ac_trace_info, null],
|
|
3509
|
+
["EV_TRACE_TOGGLED", ac_trace_toggled, null],
|
|
3510
|
+
["EV_TRACES_CLEARED", ac_traces_cleared, null],
|
|
3511
|
+
["EV_GCLASS_DESCRIPTION", ac_gclass_description, null],
|
|
3007
3512
|
]]
|
|
3008
3513
|
];
|
|
3009
3514
|
|
|
@@ -3031,6 +3536,16 @@ function create_gclass(gclass_name)
|
|
|
3031
3536
|
["EV_OPEN_GCLASS", 0],
|
|
3032
3537
|
["EV_GCLASS_CLOSED", 0],
|
|
3033
3538
|
["EV_LANGUAGE_CHANGED", 0],
|
|
3539
|
+
["EV_LOAD_TREE", 0],
|
|
3540
|
+
["EV_TRACE_INFO", 0],
|
|
3541
|
+
["EV_TRACE_TOGGLED", 0],
|
|
3542
|
+
["EV_TRACES_CLEARED", 0],
|
|
3543
|
+
["EV_GCLASS_DESCRIPTION", 0],
|
|
3544
|
+
/* Published only when `source` is "remote" (see the header). */
|
|
3545
|
+
["EV_TREE_WANTED", event_flag_t.EVF_OUTPUT_EVENT],
|
|
3546
|
+
["EV_TRACE_INFO_WANTED", event_flag_t.EVF_OUTPUT_EVENT],
|
|
3547
|
+
["EV_SET_TRACE_LEVEL", event_flag_t.EVF_OUTPUT_EVENT],
|
|
3548
|
+
["EV_GCLASS_WANTED", event_flag_t.EVF_OUTPUT_EVENT],
|
|
3034
3549
|
];
|
|
3035
3550
|
|
|
3036
3551
|
__gclass__ = gclass_create(
|