@yuneta/gobj-ui 7.27.21 → 7.27.23
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 +70 -4
- package/dist/gobj-ui.cjs.js +706 -40
- package/dist/gobj-ui.es.js +706 -40
- package/package.json +1 -1
- package/src/c_yui_gobj_tree_js.js +455 -13
- 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 +298 -0
- package/src/i18n_key_functions.js +2 -0
- package/src/yui_dev.js +53 -15
- package/src/yui_dev_copy.test.js +17 -1
- package/src/yui_gobj_tree_view.js +246 -0
package/package.json
CHANGED
|
@@ -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"),
|
|
@@ -334,6 +378,11 @@ let PRIVATE_DATA = {
|
|
|
334
378
|
restoring: false, // guards the store against its own restore
|
|
335
379
|
restored: false, // the saved arrangement is applied ONCE
|
|
336
380
|
last_zoom: 1, // tells a wheel zoom from a drag in aftertransform
|
|
381
|
+
|
|
382
|
+
/*---------------- source "remote" ----------------*/
|
|
383
|
+
remote_root: null, // the descriptor of the backend tree, as last loaded
|
|
384
|
+
trace_info: {}, // gclass -> {gclass_levels, global_levels, gclass_on, global_on, error}
|
|
385
|
+
trace_pending: false, // a trace was set: the block is locked until the host answers
|
|
337
386
|
};
|
|
338
387
|
|
|
339
388
|
let __gclass__ = null;
|
|
@@ -1688,14 +1737,17 @@ function load_tree(gobj)
|
|
|
1688
1737
|
/*
|
|
1689
1738
|
* The tree, as data.
|
|
1690
1739
|
*
|
|
1691
|
-
* The graph draws DESCRIPTORS, so this is the one
|
|
1692
|
-
* says which yuno is on screen
|
|
1693
|
-
*
|
|
1694
|
-
*
|
|
1695
|
-
* below this point changes.
|
|
1740
|
+
* The graph draws DESCRIPTORS, so this is the one place that
|
|
1741
|
+
* says which yuno is on screen: this browser's, read live, or
|
|
1742
|
+
* a backend's, as the host last loaded it (EV_LOAD_TREE).
|
|
1743
|
+
* Nothing below this point knows the difference.
|
|
1696
1744
|
*/
|
|
1697
|
-
let
|
|
1745
|
+
let remote = is_remote(gobj);
|
|
1746
|
+
let root = remote? priv.remote_root: describe_js_gobj(gobj_yuno(), true);
|
|
1698
1747
|
if(!root) {
|
|
1748
|
+
if(remote) {
|
|
1749
|
+
return; /* not loaded yet: the host loads the first tree */
|
|
1750
|
+
}
|
|
1699
1751
|
log_error(`${gobj_short_name(gobj)}: no yuno to draw`);
|
|
1700
1752
|
return;
|
|
1701
1753
|
}
|
|
@@ -1912,6 +1964,220 @@ function render_popover_body(gobj, node_data)
|
|
|
1912
1964
|
`).join("");
|
|
1913
1965
|
|
|
1914
1966
|
$body.innerHTML = rows_html;
|
|
1967
|
+
|
|
1968
|
+
if(is_remote(gobj)) {
|
|
1969
|
+
$body.appendChild(build_traces_block(gobj, node_data));
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
/************************************************************
|
|
1974
|
+
* Whose tree this is.
|
|
1975
|
+
************************************************************/
|
|
1976
|
+
function is_remote(gobj)
|
|
1977
|
+
{
|
|
1978
|
+
return gobj_read_str_attr(gobj, "source") === "remote";
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
/************************************************************
|
|
1982
|
+
* The TRACES block of a backend gobj's popover.
|
|
1983
|
+
*
|
|
1984
|
+
* Two columns of checkboxes, THIS gobj and every gobj of its
|
|
1985
|
+
* gclass, one row per level (trace_rows() in the model says
|
|
1986
|
+
* what each row holds). A box is an action: its change is
|
|
1987
|
+
* sent to the FSM, which publishes it to the host, and the
|
|
1988
|
+
* block stays locked until the host has loaded what the
|
|
1989
|
+
* backend says now -- the box shows the backend's state, not
|
|
1990
|
+
* the click.
|
|
1991
|
+
************************************************************/
|
|
1992
|
+
const TRACES_NOTE_STYLE = 'color:var(--bulma-text-weak, #6B7280); margin:4px 0;';
|
|
1993
|
+
const TRACES_CELL_STYLE = 'padding:1px 4px; text-align:center;';
|
|
1994
|
+
|
|
1995
|
+
function build_traces_block(gobj, d)
|
|
1996
|
+
{
|
|
1997
|
+
let priv = gobj.priv;
|
|
1998
|
+
let info = priv.trace_info[d.gclass] || null;
|
|
1999
|
+
|
|
2000
|
+
let kids = [
|
|
2001
|
+
['div', {class: 'GOBJ_TREE_TRACES_HEAD', i18n: 'traces',
|
|
2002
|
+
style: 'font-weight:700; margin:8px 0 2px 0; ' +
|
|
2003
|
+
'padding-top:6px; border-top:1px solid var(--bulma-border-weak, #E5E7EB);'},
|
|
2004
|
+
t('traces')]
|
|
2005
|
+
];
|
|
2006
|
+
|
|
2007
|
+
if(!info) {
|
|
2008
|
+
kids.push(['div', {class: 'GOBJ_TREE_TRACES_NOTE', i18n: 'loading',
|
|
2009
|
+
style: TRACES_NOTE_STYLE}, t('loading')]);
|
|
2010
|
+
return createElement2(['div', {class: 'GOBJ_TREE_TRACES'}, kids]);
|
|
2011
|
+
}
|
|
2012
|
+
if(info.error) {
|
|
2013
|
+
kids.push(['div', {class: 'GOBJ_TREE_TRACES_ERROR',
|
|
2014
|
+
style: 'color:var(--bulma-danger, #dc2626); margin:4px 0;'},
|
|
2015
|
+
text_node(info.error)]);
|
|
2016
|
+
return createElement2(['div', {class: 'GOBJ_TREE_TRACES'}, kids]);
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
let rows = trace_rows(d, info);
|
|
2020
|
+
let pending = !!priv.trace_pending;
|
|
2021
|
+
|
|
2022
|
+
let trs = [];
|
|
2023
|
+
let group = "";
|
|
2024
|
+
for(let r of rows) {
|
|
2025
|
+
if(r.group !== group) {
|
|
2026
|
+
group = r.group;
|
|
2027
|
+
let $label = (group === "gclass")?
|
|
2028
|
+
text_node(d.gclass):
|
|
2029
|
+
createElement2(['span', {i18n: 'global'}, t('global')]);
|
|
2030
|
+
trs.push(['tr', {class: 'GOBJ_TREE_TRACES_GROUP'}, [
|
|
2031
|
+
['td', {colspan: 3, style: 'padding:4px 4px 1px 4px; font-weight:600; ' +
|
|
2032
|
+
'color:var(--bulma-text-weak, #6B7280);'}, [$label]]
|
|
2033
|
+
]]);
|
|
2034
|
+
}
|
|
2035
|
+
let origin = null;
|
|
2036
|
+
if(r.origin === "global") {
|
|
2037
|
+
origin = ['span', {class: 'GOBJ_TREE_TRACES_ORIGIN', i18n: 'global',
|
|
2038
|
+
style: 'margin-left:6px; color:var(--bulma-text-weak, #6B7280);'},
|
|
2039
|
+
t('global')];
|
|
2040
|
+
} else if(r.origin === "gclass") {
|
|
2041
|
+
origin = ['span', {class: 'GOBJ_TREE_TRACES_ORIGIN', i18n: 'gclass',
|
|
2042
|
+
style: 'margin-left:6px; color:var(--bulma-text-weak, #6B7280);'},
|
|
2043
|
+
t('gclass')];
|
|
2044
|
+
}
|
|
2045
|
+
let $level = createElement2(['td', {class: 'GOBJ_TREE_TRACES_LEVEL',
|
|
2046
|
+
style: 'padding:1px 4px; word-break:break-all;'}, []]);
|
|
2047
|
+
$level.appendChild(text_node(r.level));
|
|
2048
|
+
if(origin) {
|
|
2049
|
+
$level.appendChild(createElement2(origin));
|
|
2050
|
+
}
|
|
2051
|
+
/* What the level does is the backend's text: data, not a key. */
|
|
2052
|
+
$level.setAttribute('title', r.description);
|
|
2053
|
+
|
|
2054
|
+
trs.push(['tr', {class: 'GOBJ_TREE_TRACES_ROW'}, [
|
|
2055
|
+
$level,
|
|
2056
|
+
['td', {style: TRACES_CELL_STYLE}, [
|
|
2057
|
+
trace_checkbox(gobj, "gobj", r.level, r.gobj_on, pending || r.gobj_locked)
|
|
2058
|
+
]],
|
|
2059
|
+
['td', {style: TRACES_CELL_STYLE}, [
|
|
2060
|
+
trace_checkbox(gobj, "gclass", r.level, r.gclass_on, pending || r.gclass_locked)
|
|
2061
|
+
]],
|
|
2062
|
+
]]);
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
kids.push(['table', {class: 'GOBJ_TREE_TRACES_TABLE',
|
|
2066
|
+
style: 'width:100%; border-collapse:collapse;'}, [
|
|
2067
|
+
['thead', {}, [
|
|
2068
|
+
['tr', {}, [
|
|
2069
|
+
['th', {i18n: 'level', style: 'padding:1px 4px; text-align:left;'}, t('level')],
|
|
2070
|
+
['th', {i18n: 'this gobj', style: TRACES_CELL_STYLE}, t('this gobj')],
|
|
2071
|
+
['th', {i18n: 'all of the gclass', style: TRACES_CELL_STYLE}, t('all of the gclass')],
|
|
2072
|
+
]]
|
|
2073
|
+
]],
|
|
2074
|
+
['tbody', {}, trs]
|
|
2075
|
+
]]);
|
|
2076
|
+
|
|
2077
|
+
kids.push(['div', {class: 'GOBJ_TREE_TRACES_NOTE',
|
|
2078
|
+
i18n: 'gclass traces survive a restart, gobj traces end with the yuno',
|
|
2079
|
+
style: TRACES_NOTE_STYLE},
|
|
2080
|
+
t('gclass traces survive a restart, gobj traces end with the yuno')]);
|
|
2081
|
+
|
|
2082
|
+
let none_gobj = pending || own_trace_levels(rows, "gobj").length === 0;
|
|
2083
|
+
let none_gclass = pending || own_trace_levels(rows, "gclass").length === 0;
|
|
2084
|
+
let btn_style = 'padding:0 8px; height:22px; font-size:11px; white-space:nowrap;';
|
|
2085
|
+
let clear = (scope) => {
|
|
2086
|
+
return {
|
|
2087
|
+
click: (evt) => {
|
|
2088
|
+
evt.stopPropagation();
|
|
2089
|
+
gobj_send_event(gobj, "EV_TRACES_CLEARED", {scope: scope}, gobj);
|
|
2090
|
+
}
|
|
2091
|
+
};
|
|
2092
|
+
};
|
|
2093
|
+
let $clear_gobj = createElement2(['button', {
|
|
2094
|
+
type: 'button', class: 'GOBJ_TREE_TRACES_CLEAR_GOBJ button is-small', style: btn_style,
|
|
2095
|
+
i18n: 'remove the traces of this gobj',
|
|
2096
|
+
title: t('remove the traces of this gobj'),
|
|
2097
|
+
'data-i18n-title': 'remove the traces of this gobj',
|
|
2098
|
+
'aria-label': t('remove the traces of this gobj'),
|
|
2099
|
+
'data-i18n-aria-label': 'remove the traces of this gobj',
|
|
2100
|
+
}, t('remove the traces of this gobj'), clear("gobj")]);
|
|
2101
|
+
let $clear_gclass = createElement2(['button', {
|
|
2102
|
+
type: 'button', class: 'GOBJ_TREE_TRACES_CLEAR_GCLASS button is-small', style: btn_style,
|
|
2103
|
+
i18n: 'remove the traces of the gclass',
|
|
2104
|
+
title: t('remove the traces of the gclass'),
|
|
2105
|
+
'data-i18n-title': 'remove the traces of the gclass',
|
|
2106
|
+
'aria-label': t('remove the traces of the gclass'),
|
|
2107
|
+
'data-i18n-aria-label': 'remove the traces of the gclass',
|
|
2108
|
+
}, t('remove the traces of the gclass'), clear("gclass")]);
|
|
2109
|
+
$clear_gobj.disabled = none_gobj;
|
|
2110
|
+
$clear_gclass.disabled = none_gclass;
|
|
2111
|
+
kids.push(['div', {class: 'GOBJ_TREE_TRACES_TOOLS',
|
|
2112
|
+
style: 'display:flex; flex-wrap:wrap; gap:4px; margin-top:4px;'},
|
|
2113
|
+
[$clear_gobj, $clear_gclass]]);
|
|
2114
|
+
|
|
2115
|
+
return createElement2(['div', {class: 'GOBJ_TREE_TRACES'}, kids]);
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
/* One box of the block. `checked` and `disabled` are set as
|
|
2119
|
+
* PROPERTIES: createElement2 writes attributes, and an attribute
|
|
2120
|
+
* `checked="false"` is a checked box. */
|
|
2121
|
+
function trace_checkbox(gobj, scope, level, on, locked)
|
|
2122
|
+
{
|
|
2123
|
+
let $cb = null;
|
|
2124
|
+
if(scope === "gobj") {
|
|
2125
|
+
$cb = createElement2(['input', {
|
|
2126
|
+
type: 'checkbox', class: 'GOBJ_TREE_TRACE_GOBJ',
|
|
2127
|
+
title: t('this gobj'), 'data-i18n-title': 'this gobj',
|
|
2128
|
+
'aria-label': t('this gobj'), 'data-i18n-aria-label': 'this gobj',
|
|
2129
|
+
}]);
|
|
2130
|
+
} else {
|
|
2131
|
+
$cb = createElement2(['input', {
|
|
2132
|
+
type: 'checkbox', class: 'GOBJ_TREE_TRACE_GCLASS',
|
|
2133
|
+
title: t('all of the gclass'), 'data-i18n-title': 'all of the gclass',
|
|
2134
|
+
'aria-label': t('all of the gclass'), 'data-i18n-aria-label': 'all of the gclass',
|
|
2135
|
+
}]);
|
|
2136
|
+
}
|
|
2137
|
+
$cb.setAttribute('data-level', level);
|
|
2138
|
+
$cb.checked = !!on;
|
|
2139
|
+
$cb.disabled = !!locked;
|
|
2140
|
+
$cb.addEventListener('change', (evt) => {
|
|
2141
|
+
evt.stopPropagation();
|
|
2142
|
+
gobj_send_event(gobj, "EV_TRACE_TOGGLED",
|
|
2143
|
+
{scope: scope, level: level, set: !!evt.target.checked}, gobj);
|
|
2144
|
+
});
|
|
2145
|
+
return $cb;
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
/************************************************************
|
|
2149
|
+
* Rebuild the graph and leave the popover where it was, on
|
|
2150
|
+
* the same gobj -- by full name, the node ids are new. A
|
|
2151
|
+
* reader who just ticked a trace is still reading that card.
|
|
2152
|
+
************************************************************/
|
|
2153
|
+
function reload_keeping_popover(gobj, opts)
|
|
2154
|
+
{
|
|
2155
|
+
let priv = gobj.priv;
|
|
2156
|
+
let $popover = priv.$popover;
|
|
2157
|
+
let keep = (priv.popover_node && $popover && $popover.style.display === "block")?
|
|
2158
|
+
priv.popover_node.full_name: null;
|
|
2159
|
+
let left = $popover? $popover.style.left: "";
|
|
2160
|
+
let top = $popover? $popover.style.top: "";
|
|
2161
|
+
|
|
2162
|
+
refresh_tree(gobj, opts); /* hides the popover */
|
|
2163
|
+
|
|
2164
|
+
if(!keep || !priv.node_by_id) {
|
|
2165
|
+
return;
|
|
2166
|
+
}
|
|
2167
|
+
for(let id of Object.keys(priv.node_by_id)) {
|
|
2168
|
+
let d = priv.node_by_id[id];
|
|
2169
|
+
if(d.full_name === keep) {
|
|
2170
|
+
priv.popover_node = d;
|
|
2171
|
+
priv.$popover_title.textContent = d.short_name ||
|
|
2172
|
+
(d.gclass + (d.name ? "^" + d.name : ""));
|
|
2173
|
+
priv.$popover_title.title = priv.$popover_title.textContent;
|
|
2174
|
+
render_popover_body(gobj, d);
|
|
2175
|
+
$popover.style.left = left;
|
|
2176
|
+
$popover.style.top = top;
|
|
2177
|
+
$popover.style.display = "block";
|
|
2178
|
+
return;
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
1915
2181
|
}
|
|
1916
2182
|
|
|
1917
2183
|
/************************************************************
|
|
@@ -2370,6 +2636,11 @@ function ac_find_nodes(gobj, event, kw, src)
|
|
|
2370
2636
|
function ac_refresh(gobj, event, kw, src)
|
|
2371
2637
|
{
|
|
2372
2638
|
save_view_state(gobj);
|
|
2639
|
+
if(is_remote(gobj)) {
|
|
2640
|
+
/* The backend has the tree: the host fetches it and loads it. */
|
|
2641
|
+
gobj_publish_event(gobj, "EV_TREE_WANTED", {});
|
|
2642
|
+
return 0;
|
|
2643
|
+
}
|
|
2373
2644
|
refresh_tree(gobj);
|
|
2374
2645
|
return 0;
|
|
2375
2646
|
}
|
|
@@ -2806,6 +3077,12 @@ function ac_node_click(gobj, event, kw, src)
|
|
|
2806
3077
|
let client_y = kw.client_y || 0;
|
|
2807
3078
|
show_popover(gobj, node_data, client_x, client_y);
|
|
2808
3079
|
|
|
3080
|
+
/* Asked on every opening, not cached for good: another reader,
|
|
3081
|
+
* or a restart, may have changed what the gclass traces. */
|
|
3082
|
+
if(is_remote(gobj)) {
|
|
3083
|
+
gobj_publish_event(gobj, "EV_TRACE_INFO_WANTED", {gclass: node_data.gclass});
|
|
3084
|
+
}
|
|
3085
|
+
|
|
2809
3086
|
return 0;
|
|
2810
3087
|
}
|
|
2811
3088
|
|
|
@@ -2895,25 +3172,62 @@ function ac_open_gclass(gobj, event, kw, src)
|
|
|
2895
3172
|
return -1;
|
|
2896
3173
|
}
|
|
2897
3174
|
|
|
3175
|
+
/* A backend gclass is not in this registry (or worse, one of the
|
|
3176
|
+
* same name is, and describes the BROWSER's): its `view-gclass`
|
|
3177
|
+
* is fetched by the host and comes back as EV_GCLASS_DESCRIPTION. */
|
|
3178
|
+
if(is_remote(gobj)) {
|
|
3179
|
+
gobj_publish_event(gobj, "EV_GCLASS_WANTED", {gclass: node_data.gclass});
|
|
3180
|
+
return 0;
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3183
|
+
open_gclass_window(gobj, node_data.gclass, null, node_data.state || "");
|
|
3184
|
+
|
|
3185
|
+
return 0;
|
|
3186
|
+
}
|
|
3187
|
+
|
|
3188
|
+
/************************************************************
|
|
3189
|
+
* remote: the `view-gclass` answer the host fetched.
|
|
3190
|
+
************************************************************/
|
|
3191
|
+
function ac_gclass_description(gobj, event, kw, src)
|
|
3192
|
+
{
|
|
3193
|
+
let priv = gobj.priv;
|
|
3194
|
+
if(!kw || !kw.gclass || !kw.description || typeof kw.description !== "object") {
|
|
3195
|
+
log_error(`${gobj_short_name(gobj)}: EV_GCLASS_DESCRIPTION without a gclass description`);
|
|
3196
|
+
return -1;
|
|
3197
|
+
}
|
|
3198
|
+
let d = priv.popover_node;
|
|
3199
|
+
open_gclass_window(gobj, kw.gclass, kw.description,
|
|
3200
|
+
(d && d.gclass === kw.gclass)? (d.state || ""): "");
|
|
3201
|
+
return 0;
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3204
|
+
/* One window at a time: a second gclass replaces the first. */
|
|
3205
|
+
function open_gclass_window(gobj, gclass, description, state)
|
|
3206
|
+
{
|
|
3207
|
+
let priv = gobj.priv;
|
|
3208
|
+
|
|
2898
3209
|
close_gclass_view(priv.gclass_view);
|
|
2899
3210
|
priv.gclass_view = null;
|
|
2900
3211
|
|
|
2901
|
-
|
|
2902
|
-
title_prefix:
|
|
3212
|
+
let opts = {
|
|
3213
|
+
title_prefix: is_remote(gobj)?
|
|
3214
|
+
(gobj_read_str_attr(gobj, "yuno_name") || ""): (gobj_yuno_name() || ""),
|
|
2903
3215
|
/* Which state THIS gobj is in. The description describes the
|
|
2904
3216
|
* CLASS and cannot carry it, and the tree is the only party
|
|
2905
3217
|
* that knows -- so the machine lights the column the reader
|
|
2906
3218
|
* is actually standing in. */
|
|
2907
|
-
current_state:
|
|
3219
|
+
current_state: state,
|
|
2908
3220
|
on_close: () => {
|
|
2909
3221
|
if(gobj_is_destroying(gobj)) {
|
|
2910
3222
|
return;
|
|
2911
3223
|
}
|
|
2912
3224
|
gobj_send_event(gobj, "EV_GCLASS_CLOSED", {}, gobj);
|
|
2913
3225
|
},
|
|
2914
|
-
}
|
|
2915
|
-
|
|
2916
|
-
|
|
3226
|
+
};
|
|
3227
|
+
if(description) {
|
|
3228
|
+
opts.description = description;
|
|
3229
|
+
}
|
|
3230
|
+
priv.gclass_view = open_gclass_view(gobj, /* i18n: data */ gclass, opts);
|
|
2917
3231
|
}
|
|
2918
3232
|
|
|
2919
3233
|
/************************************************************
|
|
@@ -2929,6 +3243,119 @@ function ac_gclass_closed(gobj, event, kw, src)
|
|
|
2929
3243
|
return 0;
|
|
2930
3244
|
}
|
|
2931
3245
|
|
|
3246
|
+
/************************************************************
|
|
3247
|
+
* remote: the host loaded the tree (`view-gobj-tree`).
|
|
3248
|
+
*
|
|
3249
|
+
* The first one is framed like any opening; the next ones
|
|
3250
|
+
* keep the camera and the card the reader is on.
|
|
3251
|
+
************************************************************/
|
|
3252
|
+
function ac_load_tree(gobj, event, kw, src)
|
|
3253
|
+
{
|
|
3254
|
+
let priv = gobj.priv;
|
|
3255
|
+
if(!is_remote(gobj)) {
|
|
3256
|
+
log_error(`${gobj_short_name(gobj)}: EV_LOAD_TREE on a tree whose source is not remote`);
|
|
3257
|
+
return -1;
|
|
3258
|
+
}
|
|
3259
|
+
let root = describe_backend_tree(kw && kw.tree);
|
|
3260
|
+
if(!root) {
|
|
3261
|
+
log_warning(`${gobj_short_name(gobj)}: what was loaded is not a view-gobj-tree answer`);
|
|
3262
|
+
return -1;
|
|
3263
|
+
}
|
|
3264
|
+
let first = !priv.remote_root;
|
|
3265
|
+
priv.remote_root = root;
|
|
3266
|
+
priv.trace_pending = false;
|
|
3267
|
+
reload_keeping_popover(gobj, first? {}: {preserve_view: true});
|
|
3268
|
+
return 0;
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
/************************************************************
|
|
3272
|
+
* remote: the trace levels of a gclass, as the backend has
|
|
3273
|
+
* them now (or why they could not be read).
|
|
3274
|
+
************************************************************/
|
|
3275
|
+
function ac_trace_info(gobj, event, kw, src)
|
|
3276
|
+
{
|
|
3277
|
+
let priv = gobj.priv;
|
|
3278
|
+
if(!kw || !kw.gclass) {
|
|
3279
|
+
log_error(`${gobj_short_name(gobj)}: EV_TRACE_INFO without a gclass`);
|
|
3280
|
+
return -1;
|
|
3281
|
+
}
|
|
3282
|
+
let list = (x) => Array.isArray(x)? x: [];
|
|
3283
|
+
priv.trace_info[kw.gclass] = {
|
|
3284
|
+
gclass_levels: kw.gclass_levels || {},
|
|
3285
|
+
global_levels: kw.global_levels || {},
|
|
3286
|
+
gclass_on: list(kw.gclass_on),
|
|
3287
|
+
global_on: list(kw.global_on),
|
|
3288
|
+
error: kw.error || "",
|
|
3289
|
+
};
|
|
3290
|
+
priv.trace_pending = false;
|
|
3291
|
+
|
|
3292
|
+
let d = priv.popover_node;
|
|
3293
|
+
if(d && d.gclass === kw.gclass && priv.$popover && priv.$popover.style.display === "block") {
|
|
3294
|
+
render_popover_body(gobj, d);
|
|
3295
|
+
}
|
|
3296
|
+
return 0;
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
/************************************************************
|
|
3300
|
+
* A box of the TRACES block was ticked or cleared.
|
|
3301
|
+
************************************************************/
|
|
3302
|
+
function ac_trace_toggled(gobj, event, kw, src)
|
|
3303
|
+
{
|
|
3304
|
+
let priv = gobj.priv;
|
|
3305
|
+
let d = priv.popover_node;
|
|
3306
|
+
if(!is_remote(gobj) || !d) {
|
|
3307
|
+
log_error(`${gobj_short_name(gobj)}: a trace set with no backend card open`);
|
|
3308
|
+
return -1;
|
|
3309
|
+
}
|
|
3310
|
+
if(!kw.level || (kw.scope !== "gobj" && kw.scope !== "gclass")) {
|
|
3311
|
+
log_error(`${gobj_short_name(gobj)}: a trace set of no level or scope: ` +
|
|
3312
|
+
`'${kw.scope}' '${kw.level}'`);
|
|
3313
|
+
return -1;
|
|
3314
|
+
}
|
|
3315
|
+
set_trace_levels(gobj, d, kw.scope, [kw.level], !!kw.set);
|
|
3316
|
+
return 0;
|
|
3317
|
+
}
|
|
3318
|
+
|
|
3319
|
+
/************************************************************
|
|
3320
|
+
* "Remove the traces" of the gobj or of its gclass: every
|
|
3321
|
+
* level that scope holds on its own.
|
|
3322
|
+
************************************************************/
|
|
3323
|
+
function ac_traces_cleared(gobj, event, kw, src)
|
|
3324
|
+
{
|
|
3325
|
+
let priv = gobj.priv;
|
|
3326
|
+
let d = priv.popover_node;
|
|
3327
|
+
if(!is_remote(gobj) || !d) {
|
|
3328
|
+
log_error(`${gobj_short_name(gobj)}: traces removed with no backend card open`);
|
|
3329
|
+
return -1;
|
|
3330
|
+
}
|
|
3331
|
+
let rows = trace_rows(d, priv.trace_info[d.gclass]);
|
|
3332
|
+
let levels = own_trace_levels(rows, kw.scope);
|
|
3333
|
+
if(!levels.length) {
|
|
3334
|
+
/* The button is off when there is nothing: reaching here is
|
|
3335
|
+
* a button that did not follow the block. */
|
|
3336
|
+
log_error(`${gobj_short_name(gobj)}: no ${kw.scope} trace of ${d.full_name} to remove`);
|
|
3337
|
+
return -1;
|
|
3338
|
+
}
|
|
3339
|
+
set_trace_levels(gobj, d, kw.scope, levels, false);
|
|
3340
|
+
return 0;
|
|
3341
|
+
}
|
|
3342
|
+
|
|
3343
|
+
/* Lock the block and hand the change to the host. The block is
|
|
3344
|
+
* repainted from what the backend says next, never from here. */
|
|
3345
|
+
function set_trace_levels(gobj, d, scope, levels, set)
|
|
3346
|
+
{
|
|
3347
|
+
let priv = gobj.priv;
|
|
3348
|
+
priv.trace_pending = true;
|
|
3349
|
+
render_popover_body(gobj, d);
|
|
3350
|
+
gobj_publish_event(gobj, "EV_SET_TRACE_LEVEL", {
|
|
3351
|
+
scope: scope,
|
|
3352
|
+
gobj: d.full_name,
|
|
3353
|
+
gclass: d.gclass,
|
|
3354
|
+
levels: levels,
|
|
3355
|
+
set: set,
|
|
3356
|
+
});
|
|
3357
|
+
}
|
|
3358
|
+
|
|
2932
3359
|
/************************************************************
|
|
2933
3360
|
* The app switched language.
|
|
2934
3361
|
*
|
|
@@ -3004,6 +3431,11 @@ function create_gclass(gclass_name)
|
|
|
3004
3431
|
["EV_OPEN_GCLASS", ac_open_gclass, null],
|
|
3005
3432
|
["EV_GCLASS_CLOSED", ac_gclass_closed, null],
|
|
3006
3433
|
["EV_LANGUAGE_CHANGED", ac_language_changed, null],
|
|
3434
|
+
["EV_LOAD_TREE", ac_load_tree, null],
|
|
3435
|
+
["EV_TRACE_INFO", ac_trace_info, null],
|
|
3436
|
+
["EV_TRACE_TOGGLED", ac_trace_toggled, null],
|
|
3437
|
+
["EV_TRACES_CLEARED", ac_traces_cleared, null],
|
|
3438
|
+
["EV_GCLASS_DESCRIPTION", ac_gclass_description, null],
|
|
3007
3439
|
]]
|
|
3008
3440
|
];
|
|
3009
3441
|
|
|
@@ -3031,6 +3463,16 @@ function create_gclass(gclass_name)
|
|
|
3031
3463
|
["EV_OPEN_GCLASS", 0],
|
|
3032
3464
|
["EV_GCLASS_CLOSED", 0],
|
|
3033
3465
|
["EV_LANGUAGE_CHANGED", 0],
|
|
3466
|
+
["EV_LOAD_TREE", 0],
|
|
3467
|
+
["EV_TRACE_INFO", 0],
|
|
3468
|
+
["EV_TRACE_TOGGLED", 0],
|
|
3469
|
+
["EV_TRACES_CLEARED", 0],
|
|
3470
|
+
["EV_GCLASS_DESCRIPTION", 0],
|
|
3471
|
+
/* Published only when `source` is "remote" (see the header). */
|
|
3472
|
+
["EV_TREE_WANTED", event_flag_t.EVF_OUTPUT_EVENT],
|
|
3473
|
+
["EV_TRACE_INFO_WANTED", event_flag_t.EVF_OUTPUT_EVENT],
|
|
3474
|
+
["EV_SET_TRACE_LEVEL", event_flag_t.EVF_OUTPUT_EVENT],
|
|
3475
|
+
["EV_GCLASS_WANTED", event_flag_t.EVF_OUTPUT_EVENT],
|
|
3034
3476
|
];
|
|
3035
3477
|
|
|
3036
3478
|
__gclass__ = gclass_create(
|