svghmi/widget_jsontable.ysl2
author Edouard Tisserant
Tue, 16 Mar 2021 14:18:39 +0100
branchsvghmi
changeset 3189 0733114a2090
parent 3187 ba8ff21fd82b
child 3195 cdd2a032b424
permissions -rw-r--r--
SVGHMI: JsonTable should refresh when re-subscibing, because data might have changed while not on the page we are switching to.
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{
3069
a9b03c2634c5 Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3066
diff changeset
     6
        // arbitrary defaults to avoid missing entries in query
3187
ba8ff21fd82b SVGHMI: change default values for JsonTable, leading to scrollbar initialized at annoying non-zero position
Edouard Tisserant
parents: 3181
diff changeset
     7
        cache = [0,0,0];
3181
50d0fef791d5 SVGHMI: Add generic action buttons to JSON table, with an example in tests/svghmi: wipe alar list.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3150
diff changeset
     8
        init_common() {
3080
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
     9
            this.spread_json_data_bound = this.spread_json_data.bind(this);
3149
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    10
            this.handle_http_response_bound = this.handle_http_response.bind(this);
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    11
            this.fetch_error_bound = this.fetch_error.bind(this);
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    12
            this.promised = false;
3080
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    13
        }
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    14
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    15
        handle_http_response(response) {
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    16
            if (!response.ok) {
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    17
              console.log("HTTP error, status = " + response.status);
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    18
            }
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    19
            return response.json();
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    20
        }
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    21
3149
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    22
        fetch_error(e){
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    23
            console.log("HTTP fetch error, message = " + e.message + "Widget:" + this.element_id);
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    24
        }
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    25
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3043
diff changeset
    26
        do_http_request(...opt) {
3149
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    27
            this.abort_controller = new AbortController();
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
    28
            const query = {
3034
793ce2117258 SVGHMI: JsonTable now makes meaningfull JSON request : all arguments and variables are passed in.
Edouard Tisserant
parents: 3031
diff changeset
    29
                args: this.args,
3065
c369a742443d SVGHMI: non significant cosmetic changes
Edouard Tisserant
parents: 3048
diff changeset
    30
                range: this.cache[1],
c369a742443d SVGHMI: non significant cosmetic changes
Edouard Tisserant
parents: 3048
diff changeset
    31
                position: this.cache[2],
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3043
diff changeset
    32
                visible: this.visible,
3069
a9b03c2634c5 Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3066
diff changeset
    33
                extra: this.cache.slice(4),
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3043
diff changeset
    34
                options: opt
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
    35
            };
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
    36
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
    37
            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
    38
                 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
    39
                 body: JSON.stringify(query),
3149
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    40
                 headers: {'Content-Type': 'application/json'},
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    41
                 signal: this.abort_controller.signal
3034
793ce2117258 SVGHMI: JsonTable now makes meaningfull JSON request : all arguments and variables are passed in.
Edouard Tisserant
parents: 3031
diff changeset
    42
            };
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
    43
3149
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    44
            return fetch(this.args[0], options)
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    45
                    .then(this.handle_http_response_bound)
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    46
                    .then(this.spread_json_data_bound)
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    47
                    .catch(this.fetch_error_bound);
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    48
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    49
        }
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    50
        unsub(){
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    51
            this.abort_controller.abort();
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    52
            super.unsub();
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    53
        }
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    54
3189
0733114a2090 SVGHMI: JsonTable should refresh when re-subscibing, because data might have changed while not on the page we are switching to.
Edouard Tisserant
parents: 3187
diff changeset
    55
        sub(...args){
0733114a2090 SVGHMI: JsonTable should refresh when re-subscibing, because data might have changed while not on the page we are switching to.
Edouard Tisserant
parents: 3187
diff changeset
    56
            this.cache[0] = undefined;
0733114a2090 SVGHMI: JsonTable should refresh when re-subscibing, because data might have changed while not on the page we are switching to.
Edouard Tisserant
parents: 3187
diff changeset
    57
            super.sub(...args);
0733114a2090 SVGHMI: JsonTable should refresh when re-subscibing, because data might have changed while not on the page we are switching to.
Edouard Tisserant
parents: 3187
diff changeset
    58
        }
0733114a2090 SVGHMI: JsonTable should refresh when re-subscibing, because data might have changed while not on the page we are switching to.
Edouard Tisserant
parents: 3187
diff changeset
    59
3034
793ce2117258 SVGHMI: JsonTable now makes meaningfull JSON request : all arguments and variables are passed in.
Edouard Tisserant
parents: 3031
diff changeset
    60
        dispatch(value, oldval, index) {
3149
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    61
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    62
            if(this.cache[index] != value)
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    63
                this.cache[index] = value;
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    64
            else
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    65
                return;
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    66
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    67
            if(!this.promised){
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    68
                this.promised = true;
3150
5a1bb6ec48a0 SVGHMI: JsonTable removed useless promise since fetch() already does one. Updated generated XSLT.
Edouard Tisserant
parents: 3149
diff changeset
    69
                this.do_http_request().finally(() => {
5a1bb6ec48a0 SVGHMI: JsonTable removed useless promise since fetch() already does one. Updated generated XSLT.
Edouard Tisserant
parents: 3149
diff changeset
    70
                    this.promised = false;
5a1bb6ec48a0 SVGHMI: JsonTable removed useless promise since fetch() already does one. Updated generated XSLT.
Edouard Tisserant
parents: 3149
diff changeset
    71
                });
3149
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
    72
            }
2996
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
    73
        }
3080
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    74
        make_on_click(...options){
3081
9e55061c87fa SVGHMI: more attempts to prevent losing memory in JS closure
Edouard Tisserant
parents: 3080
diff changeset
    75
            let that = this;
3080
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    76
            return function(evt){
3081
9e55061c87fa SVGHMI: more attempts to prevent losing memory in JS closure
Edouard Tisserant
parents: 3080
diff changeset
    77
                that.do_http_request(...options);
3080
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    78
            }
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    79
        }
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    80
        // on_click(evt, ...options) {
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    81
        //     this.do_http_request(...options);
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
    82
        // }
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
    83
    }
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
    84
    ||
2996
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
    85
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
    86
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
    87
    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
    88
}
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
    89
3028
72ee99635db7 SVGHMI: HMI:JsonTable also recognize TextStyleList, but parsing of textContent is still not implemented and style is still not updated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2997
diff changeset
    90
72ee99635db7 SVGHMI: HMI:JsonTable also recognize TextStyleList, but parsing of textContent is still not implemented and style is still not updated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2997
diff changeset
    91
const "hmi_textstylelists_descs", "$parsed_widgets/widget[@type = 'TextStyleList']";
72ee99635db7 SVGHMI: HMI:JsonTable also recognize TextStyleList, but parsing of textContent is still not implemented and style is still not updated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2997
diff changeset
    92
const "hmi_textstylelists", "$hmi_elements[@id = $hmi_textstylelists_descs/@id]";
72ee99635db7 SVGHMI: HMI:JsonTable also recognize TextStyleList, but parsing of textContent is still not implemented and style is still not updated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2997
diff changeset
    93
3031
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
    94
const "textstylelist_related" foreach "$hmi_textstylelists" list {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
    95
    attrib "listid" value "@id";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
    96
    foreach "func:refered_elements(.)" elt {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
    97
        attrib "eltid" value "@id";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
    98
    }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
    99
}
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   100
const "textstylelist_related_ns", "exsl:node-set($textstylelist_related)";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   101
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   102
def "func:json_expressions" {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   103
    param "expressions";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   104
    param "label";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   105
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   106
    // compute javascript expressions to access JSON data
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   107
    // desscribed in given svg element's "label"
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   108
    // knowing that parent element already has given "expressions".
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   109
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   110
    choose {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   111
        when "$label" {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   112
            const "suffixes", "str:split($label)";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   113
            const "res" foreach "$suffixes" expression {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   114
                const "suffix",".";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   115
                const "pos","position()";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   116
                // take last available expression (i.e can have more suffixes than expressions)
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   117
                const "expr","$expressions[position() <= $pos][last()]/expression";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   118
                choose {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   119
                    when "contains($suffix,'=')" {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   120
                        const "name", "substring-before($suffix,'=')";
3043
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   121
                        if "$expr/@name[. != $name]"
3031
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   122
                            error > JsonTable : missplaced '=' or inconsistent names in Json data expressions.
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   123
                        attrib "name" value "$name";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   124
                        attrib "content" > «$expr/@content»«substring-after($suffix,'=')»
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   125
                    }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   126
                    otherwise {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   127
                        copy "$expr/@name";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   128
                        attrib "content" > «$expr/@content»«$suffix»
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   129
                    }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   130
                }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   131
            }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   132
            result "exsl:node-set($res)";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   133
        }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   134
        // Empty labels are ignored, expressions are then passed as-is.
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   135
        otherwise result "$expressions";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   136
    }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   137
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   138
}
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   139
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   140
const "initexpr" expression attrib "content" > jdata
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   141
const "initexpr_ns", "exsl:node-set($initexpr)";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   142
2996
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   143
template "svg:use", mode="json_table_elt_render" {
3031
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   144
    param "expressions";
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
   145
    // 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
   146
    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
   147
    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
   148
3028
72ee99635db7 SVGHMI: HMI:JsonTable also recognize TextStyleList, but parsing of textContent is still not implemented and style is still not updated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2997
diff changeset
   149
    choose {
72ee99635db7 SVGHMI: HMI:JsonTable also recognize TextStyleList, but parsing of textContent is still not implemented and style is still not updated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2997
diff changeset
   150
        when "count($from_list) > 0" {
3081
9e55061c87fa SVGHMI: more attempts to prevent losing memory in JS closure
Edouard Tisserant
parents: 3080
diff changeset
   151
            |         id("«@id»").setAttribute("xlink:href",
3028
72ee99635db7 SVGHMI: HMI:JsonTable also recognize TextStyleList, but parsing of textContent is still not implemented and style is still not updated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2997
diff changeset
   152
            // obtain new target id from HMI:List widget
3031
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   153
            |             "#"+hmi_widgets["«$from_list/@id»"].items[«$expressions/expression[1]/@content»]);
3028
72ee99635db7 SVGHMI: HMI:JsonTable also recognize TextStyleList, but parsing of textContent is still not implemented and style is still not updated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2997
diff changeset
   154
        }
72ee99635db7 SVGHMI: HMI:JsonTable also recognize TextStyleList, but parsing of textContent is still not implemented and style is still not updated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2997
diff changeset
   155
        otherwise
3031
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   156
            warning > Clones (svg:use) in JsonTable Widget must point to a valid HMI:List widget or item. Reference "«@xlink:href»" is not valid and will not be updated.
3028
72ee99635db7 SVGHMI: HMI:JsonTable also recognize TextStyleList, but parsing of textContent is still not implemented and style is still not updated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2997
diff changeset
   157
    }
2996
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   158
}
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   159
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   160
template "svg:text", mode="json_table_elt_render" {
3031
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   161
    param "expressions";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   162
    const "value_expr", "$expressions/expression[1]/@content";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   163
    const "original", "@original";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   164
    const "from_textstylelist", "$textstylelist_related_ns/list[elt/@eltid = $original]";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   165
    choose {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   166
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   167
        when "count($from_textstylelist) > 0" {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   168
            const "content_expr", "$expressions/expression[2]/@content";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   169
            if "string-length($content_expr) = 0 or $expressions/expression[2]/@name != 'textContent'"
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   170
                error > Clones (svg:use) in JsonTable Widget pointing to a HMI:TextStyleList widget or item must have a "textContent=.someVal" assignement following value expression in label.
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   171
            |         {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   172
            |           let elt = id("«@id»");
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   173
            |           elt.textContent = String(«$content_expr»);
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   174
            |           elt.style = hmi_widgets["«$from_textstylelist/@listid»"].styles[«$value_expr»];
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   175
            |         }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   176
        }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   177
        otherwise {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   178
            |         id("«@id»").textContent = String(«$value_expr»);
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   179
        }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   180
    }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   181
}
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   182
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   183
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   184
// only labels comming from Json widget are counted in
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   185
def "func:filter_non_widget_label" {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   186
    param "elt";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   187
    param "widget_elts";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   188
    const "eltid" choose {
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   189
        when "$elt/@original" value "$elt/@original";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   190
        otherwise value "$elt/@id";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   191
    }
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   192
    result "$widget_elts[@id=$eltid]/@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
   193
}
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   194
3043
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   195
template "svg:*", mode="json_table_render_except_comments"{
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   196
    param "expressions";
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   197
    param "widget_elts";
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   198
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   199
    const "label", "func:filter_non_widget_label(., $widget_elts)";
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   200
    // filter out "# commented" elements
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   201
    if "not(starts-with($label,'#'))" 
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   202
        apply ".", mode="json_table_render"{
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   203
            with "expressions", "$expressions";
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   204
            with "widget_elts", "$widget_elts";
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   205
            with "label", "$label";
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   206
        }
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   207
}
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   208
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3043
diff changeset
   209
2996
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   210
template "svg:*", mode="json_table_render" {
3031
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   211
    param "expressions";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   212
    param "widget_elts";
3043
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   213
    param "label";
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3043
diff changeset
   214
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3043
diff changeset
   215
    const "new_expressions", "func:json_expressions($expressions, $label)";
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3043
diff changeset
   216
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3043
diff changeset
   217
    const "elt",".";
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3043
diff changeset
   218
    foreach "$new_expressions/expression[position() > 1][starts-with(@name,'onClick')]"
3081
9e55061c87fa SVGHMI: more attempts to prevent losing memory in JS closure
Edouard Tisserant
parents: 3080
diff changeset
   219
    |         id("«$elt/@id»").onclick = this.make_on_click('«@name»', «@content»);
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3043
diff changeset
   220
3043
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   221
    apply ".", mode="json_table_elt_render"
3048
d46d545ff7b7 SVGHMI: JsonTable can now have clickable elements, that trigger a request with extra argument whose content is taken from Json data.
Edouard Tisserant
parents: 3043
diff changeset
   222
        with "expressions", "$new_expressions";
2996
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   223
}
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   224
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   225
template "svg:g", mode="json_table_render" {
3031
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   226
    param "expressions";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   227
    param "widget_elts";
3043
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   228
    param "label";
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   229
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   230
    // use intermediate variables for optimization
3149
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
   231
    const "varprefix" > obj_«@id»_
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   232
    |         try {
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   233
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   234
    foreach "$expressions/expression"{
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   235
    |          let «$varprefix»«position()» = «@content»;
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   236
    |          if(«$varprefix»«position()» == undefined) {
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   237
    |               throw null;
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   238
    |          }
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   239
    }
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   240
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   241
    // because we put values in a variables, we can replace corresponding expression with variable name
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   242
    const "new_expressions" foreach "$expressions/expression" xsl:copy {
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   243
        copy "@name";
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   244
        attrib "content" > «$varprefix»«position()»
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   245
    }
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   246
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   247
    // revert hiding in case it did happen before
3080
e5fa1f49f0b9 SVGHMI: WIP trying to reduce memory usage : use .onclick onstead of SetAttribute, avoid useless closure and object creation when possible, etc.
Edouard Tisserant
parents: 3069
diff changeset
   248
    |           id("«@id»").style = "«@style»";
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   249
3043
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   250
    apply "*", mode="json_table_render_except_comments" {
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   251
        with "expressions", "func:json_expressions(exsl:node-set($new_expressions), $label)";
3031
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   252
        with "widget_elts", "$widget_elts";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   253
    }
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   254
    |         } catch(err) {
3149
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
   255
    |           id("«@id»").style = "display:none";
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   256
    |         }
2996
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   257
}
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   258
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   259
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
   260
    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
   261
    labels("data");
14635b09d329 SVGHMI: JsonTable now generate working data access code for data/* elements.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2994
diff changeset
   262
    const "data_elt", "$result_svg_ns//*[@id = $hmi_element/@id]/*[@inkscape:label = 'data']";
3036
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   263
    |     visible: «count($data_elt/*[@inkscape:label])»,
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   264
    |     spread_json_data: function(janswer) {
4930455428df SVGHMI: JsonTable now use intermediate variables again to address JSON data without duplicating code or referencing. Using intermediate variables also alows to check for availability of data and stop evaluating early if data is missing. Finally added complete roundtrip example to illustrate use of JSonTable to display "alarms" collected in python from changes on PLC boolean variables.
Edouard Tisserant
parents: 3035
diff changeset
   265
    |         let [range,position,jdata] = janswer;
3149
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
   266
    |         [[1, range], [2, position], [3, this.visible]].map(([i,v]) => {
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
   267
    |              this.apply_hmi_value(i,v);
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
   268
    |              this.cache[i] = v;
d32e6246cd59 SVGHMI: Optimization for JsonTable : reload JSON only when necessary, and avoid concurrent http requests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3081
diff changeset
   269
    |         });
3043
d7b009e49e87 SVGHMI: JsonTable now ignores elements and groups starting with #
Edouard Tisserant
parents: 3041
diff changeset
   270
    apply "$data_elt", mode="json_table_render_except_comments" {
3031
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   271
        with "expressions","$initexpr_ns";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   272
        with "widget_elts","$hmi_element/*[@inkscape:label = 'data']/descendant::svg:*";
440d74319a74 SVGHMI: Refactor the way JsonTable generate javascript code to access json data. Now support multiple assignments, used in the case of text to change both content and style on the same element.
Edouard Tisserant
parents: 3028
diff changeset
   273
    }
3181
50d0fef791d5 SVGHMI: Add generic action buttons to JSON table, with an example in tests/svghmi: wipe alar list.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3150
diff changeset
   274
    |     },
50d0fef791d5 SVGHMI: Add generic action buttons to JSON table, with an example in tests/svghmi: wipe alar list.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3150
diff changeset
   275
    |     init() {
50d0fef791d5 SVGHMI: Add generic action buttons to JSON table, with an example in tests/svghmi: wipe alar list.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3150
diff changeset
   276
    |        this.init_common();
50d0fef791d5 SVGHMI: Add generic action buttons to JSON table, with an example in tests/svghmi: wipe alar list.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3150
diff changeset
   277
    foreach "$hmi_element/*[starts-with(@inkscape:label,'action_')]" {
50d0fef791d5 SVGHMI: Add generic action buttons to JSON table, with an example in tests/svghmi: wipe alar list.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3150
diff changeset
   278
    |         id("«@id»").onclick = this.make_on_click("«func:escape_quotes(@inkscape:label)»");
50d0fef791d5 SVGHMI: Add generic action buttons to JSON table, with an example in tests/svghmi: wipe alar list.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3150
diff changeset
   279
    }
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
   280
    |     }
3181
50d0fef791d5 SVGHMI: Add generic action buttons to JSON table, with an example in tests/svghmi: wipe alar list.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3150
diff changeset
   281
50d0fef791d5 SVGHMI: Add generic action buttons to JSON table, with an example in tests/svghmi: wipe alar list.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3150
diff changeset
   282
}