@yuneta/gobj-ui 7.29.4 → 7.29.6
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 +27 -27
- package/dist/gobj-ui.cjs.js +16 -16
- package/dist/gobj-ui.es.js +16 -16
- package/package.json +1 -1
- package/src/c_g6_nodes_tree.js +1 -1
- package/src/c_yui_node.js +1 -1
- package/src/c_yui_treedb_topics.js +5 -5
- package/src/c_yui_window.js +1 -1
- package/src/lib_icons.test.js +1 -1
- package/src/named_controls.wiring.test.js +2 -2
- package/src/schema_version_bump.test.js +6 -6
- package/src/shell_dialog_names.wiring.test.js +2 -2
- package/src/treedb_fold_model.js +3 -3
- package/src/treedb_fold_model.test.js +141 -141
- package/src/treedb_layout.js +7 -7
- package/src/vite_plugin_yuneta_html.test.js +4 -4
- package/src/yui_dev.js +1 -1
- package/src/yui_dev_copy.test.js +5 -5
- package/src/yui_gobj_tree_view.js +3 -3
- package/src/yui_icons.css +3 -3
- package/src/yui_row_search.test.js +16 -16
- package/src/yui_shell_last_route.test.js +2 -2
- package/src/yui_tab_routes.test.js +2 -2
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The fold arithmetic of the treedb graph, pinned.
|
|
5
5
|
*
|
|
6
|
-
* A small
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* A small sites / buildings / devices inventory: sites (a
|
|
7
|
+
* self-referent tree), devices hanging from a site AND a building,
|
|
8
|
+
* buildings hanging from a site, and a topic with hooks and no
|
|
9
|
+
* fkeys (extended) whose children must be roots.
|
|
10
10
|
***********************************************************************/
|
|
11
11
|
import { describe, test, expect } from "vitest";
|
|
12
12
|
import {
|
|
@@ -34,15 +34,15 @@ import {
|
|
|
34
34
|
fold_is_hierarchical,
|
|
35
35
|
} from "./treedb_fold_model.js";
|
|
36
36
|
|
|
37
|
-
const
|
|
38
|
-
topic_name: "
|
|
37
|
+
const sites_desc = {
|
|
38
|
+
topic_name: "sites",
|
|
39
39
|
node_treedb_type: "entity",
|
|
40
40
|
cols: [
|
|
41
41
|
{id: "id", flag: []},
|
|
42
|
-
{id: "
|
|
43
|
-
{id: "
|
|
44
|
-
{id: "devices", flag: ["hook"], hook: {devices: "
|
|
45
|
-
{id: "
|
|
42
|
+
{id: "site", flag: ["fkey"], fkey: {sites: "sites"}},
|
|
43
|
+
{id: "sites", flag: ["hook"], hook: {sites: "site"}},
|
|
44
|
+
{id: "devices", flag: ["hook"], hook: {devices: "site"}},
|
|
45
|
+
{id: "buildings", flag: ["hook"], hook: {buildings: "site"}},
|
|
46
46
|
],
|
|
47
47
|
};
|
|
48
48
|
const devices_desc = {
|
|
@@ -50,29 +50,29 @@ const devices_desc = {
|
|
|
50
50
|
node_treedb_type: "child",
|
|
51
51
|
cols: [
|
|
52
52
|
{id: "id", flag: []},
|
|
53
|
-
{id: "
|
|
54
|
-
{id: "
|
|
53
|
+
{id: "site", flag: ["fkey"], fkey: {sites: "devices"}},
|
|
54
|
+
{id: "building", flag: ["fkey"], fkey: {buildings: "devices"}},
|
|
55
55
|
{id: "photo", flag: ["fkey", "file"], fkey: {__assets__: "photos"}},
|
|
56
56
|
],
|
|
57
57
|
};
|
|
58
|
-
const
|
|
59
|
-
topic_name: "
|
|
58
|
+
const buildings_desc = {
|
|
59
|
+
topic_name: "buildings",
|
|
60
60
|
node_treedb_type: "entity",
|
|
61
61
|
cols: [
|
|
62
62
|
{id: "id", flag: []},
|
|
63
|
-
{id: "
|
|
64
|
-
{id: "devices", flag: ["hook"], hook: {devices: "
|
|
63
|
+
{id: "site", flag: ["fkey"], fkey: {sites: "buildings"}},
|
|
64
|
+
{id: "devices", flag: ["hook"], hook: {devices: "building"}},
|
|
65
65
|
],
|
|
66
66
|
};
|
|
67
|
-
/*
|
|
68
|
-
const
|
|
69
|
-
cols:
|
|
70
|
-
{id: "
|
|
71
|
-
{id: "parent", flag: ["fkey"], fkey: {
|
|
67
|
+
/* buildings inside buildings: a second HIERARCHICAL topic */
|
|
68
|
+
const buildings_self = Object.assign({}, buildings_desc, {
|
|
69
|
+
cols: buildings_desc.cols.concat([
|
|
70
|
+
{id: "buildings", flag: ["hook"], hook: {buildings: "parent"}},
|
|
71
|
+
{id: "parent", flag: ["fkey"], fkey: {buildings: "buildings"}},
|
|
72
72
|
]),
|
|
73
73
|
});
|
|
74
74
|
const groups_desc = {
|
|
75
|
-
topic_name: "
|
|
75
|
+
topic_name: "groups",
|
|
76
76
|
node_treedb_type: "extended",
|
|
77
77
|
cols: [
|
|
78
78
|
{id: "id", flag: []},
|
|
@@ -82,34 +82,34 @@ const groups_desc = {
|
|
|
82
82
|
|
|
83
83
|
const descs = {
|
|
84
84
|
__graphs__: {topic_name: "__graphs__", cols: []},
|
|
85
|
-
|
|
85
|
+
sites: sites_desc,
|
|
86
86
|
devices: devices_desc,
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
buildings: buildings_desc,
|
|
88
|
+
groups: groups_desc,
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
/* region > (north, south); north > site1; site1 has 30 devices and one
|
|
92
|
-
*
|
|
92
|
+
* building b1 that also reaches devices d0..d9. */
|
|
93
93
|
function make_records(n_devices)
|
|
94
94
|
{
|
|
95
95
|
let devices = [];
|
|
96
96
|
for(let i = 0; i < n_devices; i++) {
|
|
97
|
-
let rec = {id: `d${i}`,
|
|
97
|
+
let rec = {id: `d${i}`, site: "sites^site1^devices", photo: "x^y^photos"};
|
|
98
98
|
if(i < 10) {
|
|
99
|
-
rec.
|
|
99
|
+
rec.building = ["buildings^b1^devices"];
|
|
100
100
|
}
|
|
101
101
|
devices.push(rec);
|
|
102
102
|
}
|
|
103
103
|
return {
|
|
104
|
-
|
|
105
|
-
{id: "region",
|
|
106
|
-
{id: "north",
|
|
107
|
-
{id: "south",
|
|
108
|
-
{id: "site1",
|
|
104
|
+
sites: [
|
|
105
|
+
{id: "region", site: ""},
|
|
106
|
+
{id: "north", site: "sites^region^sites"},
|
|
107
|
+
{id: "south", site: "sites^region^sites"},
|
|
108
|
+
{id: "site1", site: "sites^north^sites"},
|
|
109
109
|
],
|
|
110
110
|
devices: devices,
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
buildings: [{id: "b1", site: "sites^site1^buildings"}],
|
|
112
|
+
groups: [{id: "g1"}],
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -119,16 +119,16 @@ describe("the model", () => {
|
|
|
119
119
|
test("every record is a node, system topics are skipped", () => {
|
|
120
120
|
let m = fold_build_model(descs, make_records(3));
|
|
121
121
|
expect(m.nodes.size).toBe(4 + 3 + 1 + 1);
|
|
122
|
-
expect(m.topics).toEqual(["
|
|
122
|
+
expect(m.topics).toEqual(["sites", "devices", "buildings", "groups"]);
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
test("children hang from the hook the fkey names, in record order", () => {
|
|
126
126
|
let m = fold_build_model(descs, make_records(3));
|
|
127
|
-
expect(m.groups.get(fold_group_key(K("
|
|
128
|
-
.toEqual([K("
|
|
129
|
-
expect(m.groups.get(fold_group_key(K("
|
|
127
|
+
expect(m.groups.get(fold_group_key(K("sites", "region"), "sites")))
|
|
128
|
+
.toEqual([K("sites", "north"), K("sites", "south")]);
|
|
129
|
+
expect(m.groups.get(fold_group_key(K("sites", "site1"), "devices")))
|
|
130
130
|
.toEqual([K("devices", "d0"), K("devices", "d1"), K("devices", "d2")]);
|
|
131
|
-
expect(m.groups.get(fold_group_key(K("
|
|
131
|
+
expect(m.groups.get(fold_group_key(K("buildings", "b1"), "devices")))
|
|
132
132
|
.toEqual([K("devices", "d0"), K("devices", "d1"), K("devices", "d2")]);
|
|
133
133
|
});
|
|
134
134
|
|
|
@@ -136,88 +136,88 @@ describe("the model", () => {
|
|
|
136
136
|
let m = fold_build_model(descs, make_records(3));
|
|
137
137
|
let d0 = m.nodes.get(K("devices", "d0"));
|
|
138
138
|
expect(d0.parents.map((p) => p.node_key).sort())
|
|
139
|
-
.toEqual([K("
|
|
139
|
+
.toEqual([K("buildings", "b1"), K("sites", "site1")]);
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
test("roots: no drawable parent -- and a fkey into a topic nobody fetched is not a parent", () => {
|
|
143
143
|
let m = fold_build_model(descs, make_records(3));
|
|
144
|
-
expect(m.groups.get(fold_root_group_key("
|
|
144
|
+
expect(m.groups.get(fold_root_group_key("sites"))).toEqual([K("sites", "region")]);
|
|
145
145
|
expect(m.groups.get(fold_root_group_key("devices"))).toBeUndefined();
|
|
146
146
|
/* `photo` names __assets__, which has no desc: ignored */
|
|
147
147
|
expect(m.nodes.get(K("devices", "d0")).parents.length).toBe(2);
|
|
148
|
-
expect(m.groups.get(fold_root_group_key("
|
|
148
|
+
expect(m.groups.get(fold_root_group_key("groups"))).toEqual([K("groups", "g1")]);
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
test("a child of an `extended` parent only has no parent: the engine draws no edge to one", () => {
|
|
152
152
|
let recs = make_records(1);
|
|
153
|
-
recs.devices[0] = {id: "d0", group: "
|
|
153
|
+
recs.devices[0] = {id: "d0", group: "groups^g1^members"};
|
|
154
154
|
let m = fold_build_model(descs, recs);
|
|
155
|
-
expect(m.nodes.get(K("
|
|
156
|
-
/* devices hang from
|
|
155
|
+
expect(m.nodes.get(K("groups", "g1")).hooks).toEqual({});
|
|
156
|
+
/* devices hang from sites (the main topic), so a device with
|
|
157
157
|
* no parent is LOOSE, not a root -- see the "main topic" block */
|
|
158
158
|
expect(m.loose.devices).toEqual([K("devices", "d0")]);
|
|
159
159
|
expect(m.groups.get(fold_root_group_key("devices"))).toBeUndefined();
|
|
160
160
|
/* and with no main topic it is a plain root */
|
|
161
|
-
let m2 = fold_build_model({
|
|
162
|
-
expect(m2.main_topic).toBe("
|
|
163
|
-
let m3 = fold_build_model({devices: devices_desc,
|
|
161
|
+
let m2 = fold_build_model({sites: sites_desc, devices: devices_desc, groups: groups_desc}, recs, {main_topic: ""});
|
|
162
|
+
expect(m2.main_topic).toBe("sites"); /* "" means "deduce", and sites reaches devices */
|
|
163
|
+
let m3 = fold_build_model({devices: devices_desc, groups: groups_desc}, recs);
|
|
164
164
|
expect(m3.main_topic).toBe("");
|
|
165
165
|
expect(m3.groups.get(fold_root_group_key("devices"))).toEqual([K("devices", "d0")]);
|
|
166
166
|
});
|
|
167
167
|
|
|
168
168
|
test("a cycle with no way in gets one root, not a row of them", () => {
|
|
169
169
|
let recs = {
|
|
170
|
-
|
|
171
|
-
{id: "a",
|
|
172
|
-
{id: "b",
|
|
173
|
-
{id: "c",
|
|
170
|
+
sites: [
|
|
171
|
+
{id: "a", site: "sites^c^sites"},
|
|
172
|
+
{id: "b", site: "sites^a^sites"},
|
|
173
|
+
{id: "c", site: "sites^b^sites"},
|
|
174
174
|
],
|
|
175
175
|
};
|
|
176
|
-
let m = fold_build_model({
|
|
177
|
-
expect(m.groups.get(fold_root_group_key("
|
|
176
|
+
let m = fold_build_model({sites: sites_desc}, recs);
|
|
177
|
+
expect(m.groups.get(fold_root_group_key("sites"))).toEqual([K("sites", "a")]);
|
|
178
178
|
let st = fold_new_state(24);
|
|
179
179
|
fold_expand_all(m, st);
|
|
180
180
|
expect(fold_visible_set(m, st).size).toBe(3);
|
|
181
181
|
});
|
|
182
182
|
|
|
183
183
|
test("group keys split back", () => {
|
|
184
|
-
expect(fold_split_group_key("
|
|
185
|
-
.toEqual({node_key: "
|
|
184
|
+
expect(fold_split_group_key("sites^site1|devices"))
|
|
185
|
+
.toEqual({node_key: "sites^site1", hook: "devices"});
|
|
186
186
|
expect(fold_split_group_key("|devices")).toEqual({node_key: "", hook: "devices"});
|
|
187
187
|
expect(fold_split_group_key("nope")).toBeNull();
|
|
188
188
|
});
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
describe("main topic, hidden topics, loose records", () => {
|
|
192
|
-
test("the main topic is the one whose hooks reach the most others;
|
|
193
|
-
expect(fold_main_topic(descs)).toBe("
|
|
192
|
+
test("the main topic is the one whose hooks reach the most others; sites, not groups", () => {
|
|
193
|
+
expect(fold_main_topic(descs)).toBe("sites");
|
|
194
194
|
let m = fold_build_model(descs, make_records(3));
|
|
195
|
-
expect(m.main_topic).toBe("
|
|
196
|
-
expect([...m.linked].sort()).toEqual(["
|
|
197
|
-
expect(m.linked.has("
|
|
195
|
+
expect(m.main_topic).toBe("sites");
|
|
196
|
+
expect([...m.linked].sort()).toEqual(["buildings", "devices", "sites"]);
|
|
197
|
+
expect(m.linked.has("groups")).toBe(false);
|
|
198
198
|
});
|
|
199
199
|
|
|
200
200
|
test("only a topic hooked to ITSELF can be the main one", () => {
|
|
201
|
-
expect(fold_is_hierarchical(descs, "
|
|
202
|
-
expect(fold_is_hierarchical(descs, "
|
|
203
|
-
expect(fold_is_hierarchical(descs, "
|
|
201
|
+
expect(fold_is_hierarchical(descs, "sites")).toBe(true);
|
|
202
|
+
expect(fold_is_hierarchical(descs, "buildings")).toBe(false);
|
|
203
|
+
expect(fold_is_hierarchical(descs, "groups")).toBe(false);
|
|
204
204
|
/* c reaches x and nothing reaches itself: no trunk at all */
|
|
205
205
|
let c = {topic_name: "c", cols: [{id: "id", flag: []},
|
|
206
206
|
{id: "xs", flag: ["hook"], hook: {x: "c"}}]};
|
|
207
207
|
let x = {topic_name: "x", cols: [{id: "id", flag: []}, {id: "c", flag: ["fkey"]}]};
|
|
208
208
|
expect(fold_main_topic({c: c, x: x})).toBe("");
|
|
209
|
-
/* a tree of
|
|
210
|
-
expect(fold_main_topic({
|
|
209
|
+
/* a tree of sites alone, reaching no other topic, is still a trunk */
|
|
210
|
+
expect(fold_main_topic({sites: sites_desc})).toBe("sites");
|
|
211
211
|
});
|
|
212
212
|
|
|
213
213
|
test("the schema's mark wins over the deduction, among hierarchical topics", () => {
|
|
214
|
-
let d = Object.assign({}, descs, {
|
|
215
|
-
expect(fold_main_topic(d)).toBe("
|
|
216
|
-
let marked = Object.assign({}, d, {
|
|
217
|
-
expect(fold_main_topic(marked)).toBe("
|
|
214
|
+
let d = Object.assign({}, descs, {buildings: buildings_self});
|
|
215
|
+
expect(fold_main_topic(d)).toBe("sites"); /* sites reaches more */
|
|
216
|
+
let marked = Object.assign({}, d, {buildings: Object.assign({}, buildings_self, {main_topic: true})});
|
|
217
|
+
expect(fold_main_topic(marked)).toBe("buildings");
|
|
218
218
|
/* a mark on a topic that is not hierarchical is not a trunk */
|
|
219
219
|
let wrong = Object.assign({}, descs, {devices: Object.assign({}, devices_desc, {main_topic: true})});
|
|
220
|
-
expect(fold_main_topic(wrong)).toBe("
|
|
220
|
+
expect(fold_main_topic(wrong)).toBe("sites");
|
|
221
221
|
});
|
|
222
222
|
|
|
223
223
|
test("a self-referent hook breaks a tie", () => {
|
|
@@ -233,18 +233,18 @@ describe("main topic, hidden topics, loose records", () => {
|
|
|
233
233
|
});
|
|
234
234
|
|
|
235
235
|
test("the reader's pick wins -- if it is a hierarchical topic", () => {
|
|
236
|
-
let d = Object.assign({}, descs, {
|
|
237
|
-
let m = fold_build_model(d, make_records(3), {main_topic: "
|
|
238
|
-
expect(m.main_topic).toBe("
|
|
239
|
-
expect([...m.linked].sort()).toEqual(["
|
|
240
|
-
/*
|
|
241
|
-
expect(m.groups.get(fold_root_group_key("
|
|
236
|
+
let d = Object.assign({}, descs, {buildings: buildings_self});
|
|
237
|
+
let m = fold_build_model(d, make_records(3), {main_topic: "buildings"});
|
|
238
|
+
expect(m.main_topic).toBe("buildings");
|
|
239
|
+
expect([...m.linked].sort()).toEqual(["buildings", "devices"]);
|
|
240
|
+
/* sites is not linked to buildings, so its roots are roots */
|
|
241
|
+
expect(m.groups.get(fold_root_group_key("sites"))).toEqual([K("sites", "region")]);
|
|
242
242
|
/* a pick the rule refuses is ignored, and the trunk is deduced */
|
|
243
|
-
let m2 = fold_build_model(descs, make_records(3), {main_topic: "
|
|
244
|
-
expect(m2.main_topic).toBe("
|
|
243
|
+
let m2 = fold_build_model(descs, make_records(3), {main_topic: "buildings"});
|
|
244
|
+
expect(m2.main_topic).toBe("sites");
|
|
245
245
|
});
|
|
246
246
|
|
|
247
|
-
test("a device with no
|
|
247
|
+
test("a device with no site is LOOSE: counted, not a root, unless asked for", () => {
|
|
248
248
|
let recs = make_records(3);
|
|
249
249
|
recs.devices.push({id: "d_loose"});
|
|
250
250
|
let m = fold_build_model(descs, recs);
|
|
@@ -256,55 +256,55 @@ describe("main topic, hidden topics, loose records", () => {
|
|
|
256
256
|
expect(m2.loose.devices).toEqual([K("devices", "d_loose")]);
|
|
257
257
|
});
|
|
258
258
|
|
|
259
|
-
test("a device hanging from a loose
|
|
259
|
+
test("a device hanging from a loose building only is loose too, and follows it", () => {
|
|
260
260
|
let recs = make_records(0);
|
|
261
|
-
recs.
|
|
262
|
-
recs.devices.push({id: "d_under",
|
|
261
|
+
recs.buildings.push({id: "b_loose"});
|
|
262
|
+
recs.devices.push({id: "d_under", building: ["buildings^b_loose^devices"]});
|
|
263
263
|
let m = fold_build_model(descs, recs);
|
|
264
|
-
expect(m.loose.
|
|
264
|
+
expect(m.loose.buildings).toEqual([K("buildings", "b_loose")]);
|
|
265
265
|
expect(m.loose.devices).toEqual([K("devices", "d_under")]);
|
|
266
266
|
let st = fold_new_state(24);
|
|
267
267
|
fold_expand_all(m, st);
|
|
268
268
|
expect(fold_visible_set(m, st).has(K("devices", "d_under"))).toBe(false);
|
|
269
|
-
let m2 = fold_build_model(descs, recs, {loose_topics: ["
|
|
269
|
+
let m2 = fold_build_model(descs, recs, {loose_topics: ["buildings"]});
|
|
270
270
|
fold_expand_all(m2, st);
|
|
271
271
|
expect(fold_visible_set(m2, st).has(K("devices", "d_under"))).toBe(true);
|
|
272
272
|
});
|
|
273
273
|
|
|
274
274
|
test("a hidden topic leaves the model whole: no node, no pill, no edge", () => {
|
|
275
275
|
let m = fold_build_model(descs, make_records(30), {hidden_topics: ["devices"]});
|
|
276
|
-
expect(m.topics).toEqual(["
|
|
276
|
+
expect(m.topics).toEqual(["sites", "buildings", "groups"]);
|
|
277
277
|
expect(m.totals.devices).toBe(30);
|
|
278
|
-
expect(m.nodes.get(K("
|
|
279
|
-
expect(fold_pills_of(m, fold_new_state(24), K("
|
|
280
|
-
.toEqual(["
|
|
278
|
+
expect(m.nodes.get(K("sites", "site1")).hooks.devices).toBeUndefined();
|
|
279
|
+
expect(fold_pills_of(m, fold_new_state(24), K("sites", "site1")).map((p) => p.hook))
|
|
280
|
+
.toEqual(["buildings"]);
|
|
281
281
|
expect(m.hidden.has("devices")).toBe(true);
|
|
282
282
|
});
|
|
283
283
|
|
|
284
284
|
test("hiding a topic in the middle: what hung from it alone becomes loose", () => {
|
|
285
|
-
let m = fold_build_model(descs, make_records(12), {hidden_topics: ["
|
|
286
|
-
/* d0..d9 hang from site1 AND
|
|
285
|
+
let m = fold_build_model(descs, make_records(12), {hidden_topics: ["buildings"]});
|
|
286
|
+
/* d0..d9 hang from site1 AND b1: still under site1 */
|
|
287
287
|
expect(m.nodes.get(K("devices", "d0")).parents.length).toBe(1);
|
|
288
288
|
expect(m.loose.devices).toEqual([]);
|
|
289
|
-
/*
|
|
290
|
-
* whatever has no parent left is a root --
|
|
289
|
+
/* sites hidden = the main topic gone: nothing governs, and
|
|
290
|
+
* whatever has no parent left is a root -- b1, with d0 and d1
|
|
291
291
|
* still hanging from it */
|
|
292
|
-
let m2 = fold_build_model(descs, make_records(2), {hidden_topics: ["
|
|
292
|
+
let m2 = fold_build_model(descs, make_records(2), {hidden_topics: ["sites"]});
|
|
293
293
|
expect(m2.main_topic).toBe("");
|
|
294
|
-
expect(m2.groups.get(fold_root_group_key("
|
|
294
|
+
expect(m2.groups.get(fold_root_group_key("buildings"))).toEqual([K("buildings", "b1")]);
|
|
295
295
|
expect(m2.groups.get(fold_root_group_key("devices"))).toBeUndefined();
|
|
296
|
-
let m3 = fold_build_model(descs, {devices: [{id: "d9"}]}, {hidden_topics: ["
|
|
296
|
+
let m3 = fold_build_model(descs, {devices: [{id: "d9"}]}, {hidden_topics: ["sites"]});
|
|
297
297
|
expect(m3.groups.get(fold_root_group_key("devices"))).toEqual([K("devices", "d9")]);
|
|
298
298
|
});
|
|
299
299
|
|
|
300
300
|
test("a topic shown again opens on its roots' first page: nobody folds the roots", () => {
|
|
301
301
|
let recs = make_records(3);
|
|
302
302
|
let st = fold_new_state(24);
|
|
303
|
-
let m = fold_build_model(descs, recs, {hidden_topics: ["
|
|
303
|
+
let m = fold_build_model(descs, recs, {hidden_topics: ["groups"]});
|
|
304
304
|
fold_expand_to_depth(m, st, 2);
|
|
305
|
-
expect(fold_visible_set(m, st).has(K("
|
|
305
|
+
expect(fold_visible_set(m, st).has(K("groups", "g1"))).toBe(false);
|
|
306
306
|
let m2 = fold_build_model(descs, recs);
|
|
307
|
-
expect(fold_visible_set(m2, st).has(K("
|
|
307
|
+
expect(fold_visible_set(m2, st).has(K("groups", "g1"))).toBe(true);
|
|
308
308
|
expect(fold_pending_groups(m2, st, fold_visible_set(m2, st))).toEqual([]);
|
|
309
309
|
});
|
|
310
310
|
|
|
@@ -313,7 +313,7 @@ describe("main topic, hidden topics, loose records", () => {
|
|
|
313
313
|
let st = fold_new_state(24);
|
|
314
314
|
let m = fold_build_model(descs, recs);
|
|
315
315
|
fold_expand_to_depth(m, st, 4);
|
|
316
|
-
let g = fold_group_key(K("
|
|
316
|
+
let g = fold_group_key(K("sites", "site1"), "devices");
|
|
317
317
|
expect(fold_group_shown(m, st, g)).toBe(24);
|
|
318
318
|
let m_hidden = fold_build_model(descs, recs, {hidden_topics: ["devices"]});
|
|
319
319
|
expect(fold_group_shown(m_hidden, st, g)).toBe(0); /* no group: nothing shown */
|
|
@@ -328,7 +328,7 @@ describe("depth", () => {
|
|
|
328
328
|
let st = fold_new_state(24);
|
|
329
329
|
fold_expand_to_depth(m, st, 1);
|
|
330
330
|
expect([...fold_visible_set(m, st)].sort())
|
|
331
|
-
.toEqual([K("
|
|
331
|
+
.toEqual([K("groups", "g1"), K("sites", "region")]);
|
|
332
332
|
});
|
|
333
333
|
|
|
334
334
|
test("depth 2 opens the roots' hooks on their first page", () => {
|
|
@@ -336,9 +336,9 @@ describe("depth", () => {
|
|
|
336
336
|
let st = fold_new_state(24);
|
|
337
337
|
fold_expand_to_depth(m, st, 2);
|
|
338
338
|
let v = fold_visible_set(m, st);
|
|
339
|
-
expect(v.has(K("
|
|
340
|
-
expect(v.has(K("
|
|
341
|
-
expect(v.has(K("
|
|
339
|
+
expect(v.has(K("sites", "north"))).toBe(true);
|
|
340
|
+
expect(v.has(K("sites", "south"))).toBe(true);
|
|
341
|
+
expect(v.has(K("sites", "site1"))).toBe(false);
|
|
342
342
|
expect(v.has(K("devices", "d0"))).toBe(false);
|
|
343
343
|
});
|
|
344
344
|
|
|
@@ -350,7 +350,7 @@ describe("depth", () => {
|
|
|
350
350
|
expect(v.has(K("devices", "d0"))).toBe(true);
|
|
351
351
|
expect(v.has(K("devices", "d23"))).toBe(true);
|
|
352
352
|
expect(v.has(K("devices", "d24"))).toBe(false);
|
|
353
|
-
expect(v.has(K("
|
|
353
|
+
expect(v.has(K("buildings", "b1"))).toBe(true);
|
|
354
354
|
});
|
|
355
355
|
|
|
356
356
|
test("expand all shows everything, collapse all the roots' first page", () => {
|
|
@@ -366,18 +366,18 @@ describe("depth", () => {
|
|
|
366
366
|
describe("levels of the main tree (the toolbar's stepper)", () => {
|
|
367
367
|
test("levels count from the main topic's roots, down every hook", () => {
|
|
368
368
|
let m = fold_build_model(descs, make_records(30));
|
|
369
|
-
/* region 1, north/south 2, site1 3, its devices and
|
|
369
|
+
/* region 1, north/south 2, site1 3, its devices and b1 4 */
|
|
370
370
|
expect(m.levels).toBe(4);
|
|
371
|
-
expect(m.level_of.get(K("
|
|
372
|
-
expect(m.level_of.get(K("
|
|
373
|
-
/* d0 hangs from site1 (3) and
|
|
371
|
+
expect(m.level_of.get(K("sites", "region"))).toBe(1);
|
|
372
|
+
expect(m.level_of.get(K("sites", "site1"))).toBe(3);
|
|
373
|
+
/* d0 hangs from site1 (3) and b1 (4): the shallowest wins */
|
|
374
374
|
expect(m.level_of.get(K("devices", "d0"))).toBe(4);
|
|
375
|
-
/*
|
|
376
|
-
expect(m.level_of.has(K("
|
|
375
|
+
/* groups is not tied to sites: a tree of its own, no level */
|
|
376
|
+
expect(m.level_of.has(K("groups", "g1"))).toBe(false);
|
|
377
377
|
});
|
|
378
378
|
|
|
379
379
|
test("a hidden topic takes its levels with it", () => {
|
|
380
|
-
let m = fold_build_model(descs, make_records(30), {hidden_topics: ["devices", "
|
|
380
|
+
let m = fold_build_model(descs, make_records(30), {hidden_topics: ["devices", "buildings"]});
|
|
381
381
|
expect(m.levels).toBe(3);
|
|
382
382
|
let m0 = fold_build_model({}, {});
|
|
383
383
|
expect(m0.levels).toBe(0);
|
|
@@ -397,44 +397,44 @@ describe("levels of the main tree (the toolbar's stepper)", () => {
|
|
|
397
397
|
let st = fold_new_state(24);
|
|
398
398
|
fold_expand_to_level(m, st, 1);
|
|
399
399
|
expect([...fold_visible_set(m, st)].sort())
|
|
400
|
-
.toEqual([K("
|
|
400
|
+
.toEqual([K("groups", "g1"), K("sites", "region")]);
|
|
401
401
|
fold_open_levels(m, st, 2);
|
|
402
402
|
let v = fold_visible_set(m, st);
|
|
403
|
-
expect(v.has(K("
|
|
404
|
-
expect(v.has(K("
|
|
403
|
+
expect(v.has(K("sites", "north"))).toBe(true);
|
|
404
|
+
expect(v.has(K("sites", "site1"))).toBe(false);
|
|
405
405
|
fold_open_levels(m, st, 3);
|
|
406
|
-
expect(fold_visible_set(m, st).has(K("
|
|
406
|
+
expect(fold_visible_set(m, st).has(K("sites", "site1"))).toBe(true);
|
|
407
407
|
expect(fold_visible_set(m, st).has(K("devices", "d0"))).toBe(false);
|
|
408
408
|
fold_open_levels(m, st, 4);
|
|
409
409
|
v = fold_visible_set(m, st);
|
|
410
410
|
expect(v.has(K("devices", "d23"))).toBe(true);
|
|
411
411
|
expect(v.has(K("devices", "d24"))).toBe(false); /* one page */
|
|
412
|
-
expect(v.has(K("
|
|
412
|
+
expect(v.has(K("buildings", "b1"))).toBe(true);
|
|
413
413
|
});
|
|
414
414
|
|
|
415
415
|
test("opening keeps the pages already shown; closing folds only from its level down", () => {
|
|
416
416
|
let m = fold_build_model(descs, make_records(30));
|
|
417
417
|
let st = fold_new_state(24);
|
|
418
418
|
fold_expand_to_level(m, st, 4);
|
|
419
|
-
let g = fold_group_key(K("
|
|
419
|
+
let g = fold_group_key(K("sites", "site1"), "devices");
|
|
420
420
|
fold_show_more(m, st, g); /* 30 */
|
|
421
421
|
fold_open_levels(m, st, 4);
|
|
422
422
|
expect(fold_group_shown(m, st, g)).toBe(30);
|
|
423
423
|
fold_close_levels(m, st, 3);
|
|
424
424
|
let v = fold_visible_set(m, st);
|
|
425
|
-
expect(v.has(K("
|
|
425
|
+
expect(v.has(K("sites", "site1"))).toBe(true); /* level 3 stays */
|
|
426
426
|
expect(v.has(K("devices", "d0"))).toBe(false); /* its hooks folded */
|
|
427
|
-
expect(v.has(K("
|
|
428
|
-
expect(fold_is_open(st, fold_group_key(K("
|
|
427
|
+
expect(v.has(K("buildings", "b1"))).toBe(false);
|
|
428
|
+
expect(fold_is_open(st, fold_group_key(K("sites", "north"), "sites"))).toBe(true);
|
|
429
429
|
});
|
|
430
430
|
|
|
431
431
|
test("closing does not reopen what the reader folded above the level", () => {
|
|
432
432
|
let m = fold_build_model(descs, make_records(3));
|
|
433
433
|
let st = fold_new_state(24);
|
|
434
434
|
fold_expand_to_level(m, st, 4);
|
|
435
|
-
fold_toggle(m, st, fold_group_key(K("
|
|
435
|
+
fold_toggle(m, st, fold_group_key(K("sites", "region"), "sites")); /* fold region */
|
|
436
436
|
fold_close_levels(m, st, 3);
|
|
437
|
-
expect(fold_is_open(st, fold_group_key(K("
|
|
437
|
+
expect(fold_is_open(st, fold_group_key(K("sites", "region"), "sites"))).toBe(false);
|
|
438
438
|
});
|
|
439
439
|
});
|
|
440
440
|
|
|
@@ -443,7 +443,7 @@ describe("toggle and pages", () => {
|
|
|
443
443
|
let m = fold_build_model(descs, make_records(30));
|
|
444
444
|
let st = fold_new_state(24);
|
|
445
445
|
fold_expand_to_depth(m, st, 3);
|
|
446
|
-
let g = fold_group_key(K("
|
|
446
|
+
let g = fold_group_key(K("sites", "site1"), "devices");
|
|
447
447
|
expect(fold_toggle(m, st, g)).toBe(true);
|
|
448
448
|
expect(fold_visible_set(m, st).has(K("devices", "d5"))).toBe(true);
|
|
449
449
|
expect(fold_toggle(m, st, g)).toBe(false);
|
|
@@ -453,7 +453,7 @@ describe("toggle and pages", () => {
|
|
|
453
453
|
test("show more adds a page and stops at the total", () => {
|
|
454
454
|
let m = fold_build_model(descs, make_records(30));
|
|
455
455
|
let st = fold_new_state(24);
|
|
456
|
-
let g = fold_group_key(K("
|
|
456
|
+
let g = fold_group_key(K("sites", "site1"), "devices");
|
|
457
457
|
expect(fold_show_more(m, st, g)).toBe(24);
|
|
458
458
|
expect(fold_show_more(m, st, g)).toBe(30);
|
|
459
459
|
expect(fold_show_more(m, st, g)).toBe(30);
|
|
@@ -463,11 +463,11 @@ describe("toggle and pages", () => {
|
|
|
463
463
|
let m = fold_build_model(descs, make_records(30));
|
|
464
464
|
let st = fold_new_state(24);
|
|
465
465
|
fold_expand_to_depth(m, st, 4);
|
|
466
|
-
fold_toggle(m, st, fold_group_key(K("
|
|
466
|
+
fold_toggle(m, st, fold_group_key(K("sites", "region"), "sites")); /* close */
|
|
467
467
|
let v = fold_visible_set(m, st);
|
|
468
468
|
expect(v.has(K("devices", "d0"))).toBe(false);
|
|
469
469
|
expect(v.size).toBe(2);
|
|
470
|
-
fold_toggle(m, st, fold_group_key(K("
|
|
470
|
+
fold_toggle(m, st, fold_group_key(K("sites", "region"), "sites")); /* reopen */
|
|
471
471
|
expect(fold_visible_set(m, st).has(K("devices", "d0"))).toBe(true);
|
|
472
472
|
});
|
|
473
473
|
|
|
@@ -475,12 +475,12 @@ describe("toggle and pages", () => {
|
|
|
475
475
|
let m = fold_build_model(descs, make_records(30));
|
|
476
476
|
let st = fold_new_state(24);
|
|
477
477
|
fold_expand_to_depth(m, st, 4);
|
|
478
|
-
let
|
|
479
|
-
let
|
|
480
|
-
fold_toggle(m, st,
|
|
481
|
-
fold_toggle(m, st,
|
|
478
|
+
let g_site = fold_group_key(K("sites", "site1"), "devices");
|
|
479
|
+
let g_bldg = fold_group_key(K("buildings", "b1"), "devices");
|
|
480
|
+
fold_toggle(m, st, g_bldg); /* b1's devices open too */
|
|
481
|
+
fold_toggle(m, st, g_site); /* site1's devices folded */
|
|
482
482
|
let v = fold_visible_set(m, st);
|
|
483
|
-
expect(v.has(K("devices", "d3"))).toBe(true); /* via
|
|
483
|
+
expect(v.has(K("devices", "d3"))).toBe(true); /* via b1 */
|
|
484
484
|
expect(v.has(K("devices", "d15"))).toBe(false); /* only via site1 */
|
|
485
485
|
});
|
|
486
486
|
|
|
@@ -492,8 +492,8 @@ describe("toggle and pages", () => {
|
|
|
492
492
|
let pending = fold_pending_groups(m, st, v);
|
|
493
493
|
expect(pending.length).toBe(1);
|
|
494
494
|
expect(pending[0]).toMatchObject({
|
|
495
|
-
group_key: fold_group_key(K("
|
|
496
|
-
node_key: K("
|
|
495
|
+
group_key: fold_group_key(K("sites", "site1"), "devices"),
|
|
496
|
+
node_key: K("sites", "site1"), hook: "devices",
|
|
497
497
|
shown: 24, total: 30, rest: 6,
|
|
498
498
|
});
|
|
499
499
|
});
|
|
@@ -502,11 +502,11 @@ describe("toggle and pages", () => {
|
|
|
502
502
|
let m = fold_build_model(descs, make_records(30));
|
|
503
503
|
let st = fold_new_state(24);
|
|
504
504
|
fold_expand_to_depth(m, st, 4);
|
|
505
|
-
let pills = fold_pills_of(m, st, K("
|
|
506
|
-
expect(pills.map((p) => p.hook)).toEqual(["devices", "
|
|
505
|
+
let pills = fold_pills_of(m, st, K("sites", "site1"));
|
|
506
|
+
expect(pills.map((p) => p.hook)).toEqual(["devices", "buildings"]);
|
|
507
507
|
expect(pills[0]).toMatchObject({total: 30, shown: 24, open: true, child_topic: "devices"});
|
|
508
|
-
expect(pills[1]).toMatchObject({total: 1, shown: 1, open: true, child_topic: "
|
|
509
|
-
expect(fold_pills_of(m, st, K("
|
|
508
|
+
expect(pills[1]).toMatchObject({total: 1, shown: 1, open: true, child_topic: "buildings"});
|
|
509
|
+
expect(fold_pills_of(m, st, K("sites", "south"))).toEqual([]);
|
|
510
510
|
});
|
|
511
511
|
});
|
|
512
512
|
|
|
@@ -521,14 +521,14 @@ describe("reveal", () => {
|
|
|
521
521
|
/* d40 is the 41st: two pages, not three, and not all */
|
|
522
522
|
expect(v.has(K("devices", "d47"))).toBe(true);
|
|
523
523
|
expect(v.has(K("devices", "d48"))).toBe(false);
|
|
524
|
-
expect(v.has(K("
|
|
524
|
+
expect(v.has(K("sites", "south"))).toBe(true); /* region|sites opened whole page */
|
|
525
525
|
});
|
|
526
526
|
|
|
527
527
|
test("does not close what was open", () => {
|
|
528
528
|
let m = fold_build_model(descs, make_records(60));
|
|
529
529
|
let st = fold_new_state(24);
|
|
530
530
|
fold_expand_to_depth(m, st, 4);
|
|
531
|
-
fold_show_more(m, st, fold_group_key(K("
|
|
531
|
+
fold_show_more(m, st, fold_group_key(K("sites", "site1"), "devices")); /* 48 */
|
|
532
532
|
fold_reveal(m, st, K("devices", "d3"));
|
|
533
533
|
expect(fold_visible_set(m, st).has(K("devices", "d47"))).toBe(true);
|
|
534
534
|
});
|
package/src/treedb_layout.js
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* Two layouts made for a treedb, and nothing else.
|
|
5
5
|
*
|
|
6
6
|
* What a treedb graph IS, once it is folded (treedb_fold_model.js):
|
|
7
|
-
* a forest read top to bottom. A main topic is a tree (
|
|
8
|
-
* country, region,
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* a forest read top to bottom. A main topic is a tree (sites:
|
|
8
|
+
* country, region, campus), the other topics hang from its nodes
|
|
9
|
+
* through hooks (buildings, devices, users), a record may hang
|
|
10
|
+
* from two parents (a device from its site AND its building), and
|
|
11
|
+
* every visible node was reached from a root.
|
|
12
12
|
* Tens to a few hundred cards on screen, never the whole store.
|
|
13
13
|
*
|
|
14
14
|
* G6's own layouts either do not know that or pay for not knowing:
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
*
|
|
31
31
|
* - roots are the nodes with no incoming edge, in node order;
|
|
32
32
|
* - a node belongs to the FIRST parent that reaches it in a
|
|
33
|
-
* breadth-first walk from the roots -- the
|
|
34
|
-
*
|
|
33
|
+
* breadth-first walk from the roots -- the site, not the
|
|
34
|
+
* building, because the site's column came first -- and the
|
|
35
35
|
* other links are drawn as edges across the tree;
|
|
36
36
|
* - the children of a node are ordered by the HOOK they hang from
|
|
37
37
|
* (the parent's port order, which is the schema's column order)
|