author | usveticic |
Wed, 05 Aug 2020 15:16:03 +0200 | |
branch | svghmi |
changeset 3013 | 0ea6b4f435de |
parent 2997 | 2f298089e32e |
child 3028 | 72ee99635db7 |
permissions | -rw-r--r-- |
2994
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
1 |
// widget_jsontable.ysl2 |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
2 |
|
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
3 |
template "widget[@type='JsonTable']", mode="widget_class" |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
4 |
|| |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
5 |
class JsonTableWidget extends Widget{ |
2996
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
6 |
do_http_request() { |
2994
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
7 |
const query = { |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
8 |
offset: '42', |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
9 |
filter: '*powerloss*', |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
10 |
args: this.args |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
11 |
}; |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
12 |
|
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
13 |
const options = { |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
14 |
method: 'POST', |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
15 |
body: JSON.stringify(query), |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
16 |
headers: {'Content-Type': 'application/json'} |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
17 |
} |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
18 |
|
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
19 |
fetch(this.args[0], options) |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
20 |
.then(res => res.json()) |
2996
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
21 |
.then(this.spread_json_data); |
2994
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
22 |
|
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
23 |
} |
2996
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
24 |
dispatch(value) { |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
25 |
this.do_http_request(); |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
26 |
} |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
27 |
on_click(evt) { |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
28 |
this.do_http_request(); |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
29 |
} |
2994
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
30 |
init() { |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
31 |
this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
32 |
} |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
33 |
} |
b6a9ef7f7e43
SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
34 |
|| |
2996
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
35 |
|
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
36 |
template "svg:*", mode="json_table_elt_render" { |
2997
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
37 |
error > JsonTable Widget can't contain element of type «local-name()». |
2996
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
38 |
} |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
39 |
|
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
40 |
template "svg:use", mode="json_table_elt_render" { |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
41 |
param "value_expr"; |
2997
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
42 |
// cloned element must be part of a HMI:List |
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
43 |
const "targetid", "substring-after(@xlink:href,'#')"; |
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
44 |
const "from_list", "$hmi_lists[(@id | */@id) = $targetid]"; |
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
45 |
|
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
46 |
if "count($from_list) = 0" |
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
47 |
error > Clones (svg:use) in JsonTable Widget must point to a valid HMI:List widget or HMI:List item. Reference "«@xlink:href»" is not valid. |
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
48 |
|
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
49 |
| id("«@id»").setAttribute("xlink:href", |
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
50 |
// obtain new target id from HMI:List widget |
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
51 |
| "#"+hmi_widgets["«$from_list/@id»"].items[«$value_expr»]); |
2996
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
52 |
} |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
53 |
|
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
54 |
template "svg:text", mode="json_table_elt_render" { |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
55 |
param "value_expr"; |
2997
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
56 |
| id("«@id»").textContent = String(«$value_expr»); |
2996
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
57 |
} |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
58 |
|
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
59 |
template "svg:*", mode="json_table_render" { |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
60 |
param "objname"; |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
61 |
apply ".", mode="json_table_elt_render" with "value_expr" > «$objname»«@inkscape:label» |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
62 |
} |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
63 |
|
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
64 |
template "svg:g", mode="json_table_render" { |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
65 |
param "objname"; |
2997
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
66 |
| let obj_«@id» = «$objname»«@inkscape:label»; |
2996
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
67 |
apply "*[@inkscape:label]", mode="json_table_render" |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
68 |
with "objname" > obj_«@id» |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
69 |
} |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
70 |
|
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
71 |
template "widget[@type='JsonTable']", mode="widget_defs" { |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
72 |
param "hmi_element"; |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
73 |
labels("data"); |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
74 |
optional_labels("forward backward cursor"); |
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
75 |
const "data_elt", "$result_svg_ns//*[@id = $hmi_element/@id]/*[@inkscape:label = 'data']"; |
2997
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
76 |
| spread_json_data: function(jdata) { |
2996
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
77 |
apply "$data_elt/*", mode="json_table_render" with "objname","'jdata'"; |
2997
2f298089e32e
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2996
diff
changeset
|
78 |
| } |
2996
14635b09d329
SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2994
diff
changeset
|
79 |
} |