From 003672033ca263f826b064591ec91078c77380c5 Mon Sep 17 00:00:00 2001 From: TomasKulhanek Date: Tue, 14 Sep 2021 12:38:45 +0200 Subject: [PATCH] FIX #22 fire event if input is changed - might be catched by fmi component --- docs/example/hemodynamicsburkhoff.md | 2 +- docs/usersguide/button.md | 5 +-- docs/usersguide/fmi.md | 2 +- docs/usersguide/readdata.md | 65 ++++++++++++++++++++++++++-- src/elements/buttonparams.js | 4 ++ src/elements/readdata.html | 7 ++- src/elements/readdata.js | 24 +++++++++- 7 files changed, 99 insertions(+), 10 deletions(-) diff --git a/docs/example/hemodynamicsburkhoff.md b/docs/example/hemodynamicsburkhoff.md index a5f814d..d18f8ec 100644 --- a/docs/example/hemodynamicsburkhoff.md +++ b/docs/example/hemodynamicsburkhoff.md @@ -17,7 +17,7 @@ Tlačítky můžete pustit a zastavit simulaci, krokovat simulaci a resetovat si tolerance="0.000001" starttime="0" guid="{b5629132-3ba6-4153-87c2-f3ff108e1920}" valuereferences="33554435,637534265,637534241,637534290,16777312,637534466,637534294,637534268,33554438,637534345,33554436,637534290,33554437,637534323,637534348,637534374" valuelabels="Left Ventricle Volume,Pressure in Left Ventricle,Pressure in Aorta, Pressure in Left Atria, Heart Rate, LA elastance,MV open, AOV open, RV volume,RV pressure,LA volume, LA pressure, RA volume,RA pressure,TV open,PV open" - inputs="id1,16777312,1,60;id2,16777312,1,60"> + inputs="id1,16777312,1,60,1.2;id2,16777312,1,60"> range: diff --git a/docs/usersguide/button.md b/docs/usersguide/button.md index 2e400c1..de083f5 100644 --- a/docs/usersguide/button.md +++ b/docs/usersguide/button.md @@ -1,10 +1,9 @@ # BDL-buttonparams button to set multiple values in one click, these attributes -* value * title -* ids -* values +* ids - id of input elements separated by comma. +* values Example: `` diff --git a/docs/usersguide/fmi.md b/docs/usersguide/fmi.md index 1135386..6c2ee29 100644 --- a/docs/usersguide/fmi.md +++ b/docs/usersguide/fmi.md @@ -8,7 +8,7 @@ * `guid` guid as it appears in FMU model description * `valuereferences` references to variables, custom event 'fmidata' with `event.detail` set to `{time: number , data:[number,...]}` where time is timepoint of the current simulation step and data is array of values in same order as in valuereferences - * `inputs` id of component, value reference, optional nominator,denominator to normalize `value * nominator / denominator` all delimited by coma`,`, other inputs delimited by semicolon `;` e.g. `inputs="id1,1677323,1,60;id2,16725364"` cause that the value from id1 will be converted `x= valueid1 *1/60` and value from id2 `x = valueid2*1/1` ; + * `inputs` id of component, value reference, optional nominator,denominator,addend to normalize `value * nominator / denominator + addend` all delimited by coma`,`, other inputs delimited by semicolon `;` e.g. `inputs="id1,1677323,1,60;id2,16725364"` cause that the value from id1 will be converted `x= valueid1 *1/60` and value from id2 `x = valueid2*1/1` ; * `eventlisten` event to listen on input elements - default "input" event - change is fired hen e.g. cursor is moved. You may change it to "change" - it is fired only when user drops the vlaue/ confirms the change. * `otherinputs` ids of components which triggers custom event 'fmiinput', it is expected that in event.detail contains this structure `{ valuereference: number, value: number }` diff --git a/docs/usersguide/readdata.md b/docs/usersguide/readdata.md index 7d77ad1..7e36170 100644 --- a/docs/usersguide/readdata.md +++ b/docs/usersguide/readdata.md @@ -2,7 +2,7 @@ ``` @@ -10,9 +10,68 @@ ``` Reads data from `url` every `timeout` milliseconds, displays data in a view if `display="true"` otherwise the view is hidden and the value might be used -as an input for fmi component. +as an input for fmi component as input element with id's `ids` separated by comma. The endpoint should have CORS enabled - return HTTP headers 'Access-Control-Allow-Origin = '*' and 'Access-Control-Allow-Methods' = 'GET' Demo: +```xml + +``` + +```xml + +``` + + + +```xml + +``` + + - +
+
+chartjs-xy with borders + +
+
+ chartjs-time + +
+
diff --git a/src/elements/buttonparams.js b/src/elements/buttonparams.js index 2e99c72..34f90e0 100644 --- a/src/elements/buttonparams.js +++ b/src/elements/buttonparams.js @@ -62,6 +62,10 @@ export class Buttonparams { //console.log('button.attached() ids2send, values2send', this.ids2send, this.values2send); } + /* + this is fired when the button is pressed, it sets values to the defined state + dispatch the event and if resetvalues is set - then listen fmidata event + */ switchvalues() { if (this.ids2send.length !== this.values2send.length) {console.log('warning ids and values contain different number of items.', this.ids2send, this.values2send); return;} for (let i = 0; i < this.ids2send.length; i++) { diff --git a/src/elements/readdata.html b/src/elements/readdata.html index 2036b02..ff7084c 100644 --- a/src/elements/readdata.html +++ b/src/elements/readdata.html @@ -1,3 +1,8 @@ diff --git a/src/elements/readdata.js b/src/elements/readdata.js index 7811cfc..5db35ef 100644 --- a/src/elements/readdata.js +++ b/src/elements/readdata.js @@ -10,6 +10,10 @@ export class readdata { @bindable display; @bindable url; @bindable timeout; + @bindable ids; + showinputs = false; + previousvalue=0; + fireevent = 'input' constructor(client) { this.httpclient = client; @@ -18,6 +22,11 @@ export class readdata { bind() { this.display = this.display && (this.display === 'true'); if (this.timeout) this.timeout = parseInt(this.timeout, 10); else this.timeout = 0; + //id of input elements + this.ids2send = this.ids.split(','); + this.createids = []; + //create those ids not yet in HTML DOM and put them to createids array + for (let myid of this.ids2send) {if (! document.getElementById(myid)) this.createids.push(myid);} } attached() { @@ -37,7 +46,20 @@ export class readdata { .then(response => response.text()) .then(text => { //set data that was fetched - that.data = text; + that.value = text; + //dispatch event if value differs from previous + if (that.previousvalue !== that.value) { + //if (this.ids2send.length !== this.values2send.length) {console.log('warning ids and values contain different number of items.', this.ids2send, this.values2send); return;} + for (let i = 0; i < that.ids2send.length; i++) { + let inputel = document.getElementById(that.ids2send[i]); + //console.log('readdata.update() debugging that', that); + //console.log('readdata.update() debugging inputel', inputel); + inputel.value = that.value; + let event = new Event(that.fireevent); + inputel.dispatchEvent(event); + } + } + that.previousvalue = that.value; //console.log('readdata.update', that.data); //schedule next call //let that = this;