# HG changeset patch # User Edouard Tisserant # Date 1594757147 -7200 # Node ID b6a9ef7f7e43ffa0dd596dc57c9a76aa2235f78c # Parent b76f303ffce6236a5d1502be2ea82c1c02323dcc SVGHMI: minimal JSON Table Widget communication infra + corresponding python code as py_ext code in svghmi test. To be continued. diff -r b76f303ffce6 -r b6a9ef7f7e43 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Mon Jul 13 13:56:42 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Tue Jul 14 22:05:47 2020 +0200 @@ -1,6 +1,6 @@ - - + + @@ -2146,6 +2146,54 @@ }, + + class JsonTableWidget extends Widget{ + + on_click(evt) { + + const query = { + + offset: '42', + + filter: '*powerloss*', + + args: this.args + + }; + + + + const options = { + + method: 'POST', + + body: JSON.stringify(query), + + headers: {'Content-Type': 'application/json'} + + } + + + + fetch(this.args[0], options) + + .then(res => res.json()) + + .then(res => console.log(res)); + + + + } + + init() { + + this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); + + } + + } + + @@ -2793,7 +2841,7 @@ - + diff -r b76f303ffce6 -r b6a9ef7f7e43 svghmi/widget_jsontable.ysl2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/svghmi/widget_jsontable.ysl2 Tue Jul 14 22:05:47 2020 +0200 @@ -0,0 +1,28 @@ +// widget_jsontable.ysl2 + +template "widget[@type='JsonTable']", mode="widget_class" + || + class JsonTableWidget extends Widget{ + on_click(evt) { + const query = { + offset: '42', + filter: '*powerloss*', + args: this.args + }; + + const options = { + method: 'POST', + body: JSON.stringify(query), + headers: {'Content-Type': 'application/json'} + } + + fetch(this.args[0], options) + .then(res => res.json()) + .then(res => console.log(res)); + + } + init() { + this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); + } + } + || diff -r b76f303ffce6 -r b6a9ef7f7e43 tests/svghmi/py_ext_0@py_ext/pyfile.xml --- a/tests/svghmi/py_ext_0@py_ext/pyfile.xml Mon Jul 13 13:56:42 2020 +0200 +++ b/tests/svghmi/py_ext_0@py_ext/pyfile.xml Tue Jul 14 22:05:47 2020 +0200 @@ -5,6 +5,18 @@ diff -r b76f303ffce6 -r b6a9ef7f7e43 tests/svghmi/svghmi_0@svghmi/svghmi.svg --- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Mon Jul 13 13:56:42 2020 +0200 +++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Tue Jul 14 22:05:47 2020 +0200 @@ -16,7 +16,7 @@ version="1.1" id="hmi0" sodipodi:docname="svghmi.svg" - inkscape:version="0.92.3 (2405546, 2018-03-11)"> + inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)"> @@ -142,10 +142,10 @@ showgrid="false" units="px" inkscape:zoom="0.35355339" - inkscape:cx="477.09179" - inkscape:cy="-82.185108" + inkscape:cx="460.66016" + inkscape:cy="-571.17456" inkscape:window-width="1800" - inkscape:window-height="836" + inkscape:window-height="1861" inkscape:window-x="0" inkscape:window-y="27" inkscape:window-maximized="0" @@ -2850,4 +2850,13 @@ sodipodi:role="line">mhe +