author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Fri, 29 Oct 2021 18:00:54 +0200 | |
changeset 3377 | c25a752b664e |
parent 3241 | fe945f1f48b7 |
child 3603 | f1a00aa8cb3b |
permissions | -rw-r--r-- |
3241
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
1 |
// widget_foreach.ysl2 |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
2 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
3 |
widget_desc("ForEach") { |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
4 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
5 |
longdesc |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
6 |
|| |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
7 |
ForEach widget is used to span a small set of widget over a larger set of |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
8 |
repeated HMI_NODEs. |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
9 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
10 |
Idea is somewhat similar to relative page, but it all happens inside the |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
11 |
ForEach widget, no page involved. |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
12 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
13 |
Together with relative Jump widgets it can be used to build a menu to reach |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
14 |
relative pages covering many identical HMI_NODES siblings. |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
15 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
16 |
ForEach widget takes a HMI_CLASS name as argument and a HMI_NODE path as |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
17 |
variable. |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
18 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
19 |
Direct sub-elements can be either groups of widget to be spanned, labeled |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
20 |
"ClassName:offset", or buttons to control the spanning, labeled |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
21 |
"ClassName:+/-number". |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
22 |
|| |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
23 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
24 |
shortdesc > span widgets over a set of repeated HMI_NODEs |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
25 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
26 |
arg name="class_name" accepts="string" > HMI_CLASS name |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
27 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
28 |
path name="root" accepts="HMI_NODE" > where to find HMI_NODEs whose HMI_CLASS is class_name |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
29 |
} |
2891
8927ae8326b2
SVGHMI: add widget_foreach.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
30 |
|
3232
7bdb766c2a4d
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3005
diff
changeset
|
31 |
widget_defs("ForEach") { |
2894
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
32 |
|
3005
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
33 |
if "count(path) != 1" error > ForEach widget «$hmi_element/@id» must have one HMI path given. |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
34 |
if "count(arg) != 1" error > ForEach widget «$hmi_element/@id» must have one argument given : a class name. |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
35 |
|
2894
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
36 |
const "class","arg[1]/@value"; |
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
37 |
|
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
38 |
const "base_path","path/@value"; |
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
39 |
const "hmi_index_base", "$indexed_hmitree/*[@hmipath = $base_path]"; |
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
40 |
const "hmi_tree_base", "$hmitree/descendant-or-self::*[@path = $hmi_index_base/@path]"; |
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
41 |
const "hmi_tree_items", "$hmi_tree_base/*[@class = $class]"; |
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
42 |
const "hmi_index_items", "$indexed_hmitree/*[@path = $hmi_tree_items/@path]"; |
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
43 |
const "items_paths", "$hmi_index_items/@hmipath"; |
2893
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
44 |
| index_pool: [ |
2894
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
45 |
foreach "$hmi_index_items" { |
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
46 |
| «@index»`if "position()!=last()" > ,` |
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
47 |
} |
2893
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
48 |
| ], |
2896
99c5335ed59f
SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2895
diff
changeset
|
49 |
| init: function() { |
2893
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
50 |
const "prefix","concat($class,':')"; |
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
51 |
const "buttons_regex","concat('^',$prefix,'[+\-][0-9]+')"; |
2896
99c5335ed59f
SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2895
diff
changeset
|
52 |
const "buttons", "$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]"; |
99c5335ed59f
SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2895
diff
changeset
|
53 |
foreach "$buttons" { |
99c5335ed59f
SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2895
diff
changeset
|
54 |
const "op","substring-after(@inkscape:label, $prefix)"; |
99c5335ed59f
SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2895
diff
changeset
|
55 |
| id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click('«$op»', evt)"); |
2893
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
56 |
} |
2896
99c5335ed59f
SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2895
diff
changeset
|
57 |
| |
2895
89c02b452717
SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents:
2894
diff
changeset
|
58 |
| this.items = [ |
2893
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
59 |
const "items_regex","concat('^',$prefix,'[0-9]+')"; |
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
60 |
const "unordered_items","$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]"; |
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
61 |
foreach "$unordered_items" { |
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
62 |
const "elt_label","concat($prefix, string(position()))"; |
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
63 |
const "elt","$unordered_items[@inkscape:label = $elt_label]"; |
2894
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
64 |
const "pos","position()"; |
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
65 |
const "item_path", "$items_paths[$pos]"; |
2895
89c02b452717
SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents:
2894
diff
changeset
|
66 |
| [ /* item="«$elt_label»" path="«$item_path»" */ |
2893
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
67 |
if "count($elt)=0" error > Missing item labeled «$elt_label» in ForEach widget «$hmi_element/@id» |
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2892
diff
changeset
|
68 |
foreach "func:refered_elements($elt)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" { |
2894
4cf9ad35e6d0
SVGHMI: Easier way to match HMI tree elements to paths. ForEach widget now looks for paths and indexes of all items, and enforce path to be consistent with ForEach items sub widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2893
diff
changeset
|
69 |
if "not(func:is_descendant_path(func:widget(@id)/path/@value, $item_path))" |
2896
99c5335ed59f
SVGHMI: Widget ForEach buttons now call corresponding methods.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2895
diff
changeset
|
70 |
error > Widget id="«@id»" label="«@inkscape:label»" is having wrong path. Accroding to ForEach widget ancestor id="«$hmi_element/@id»", path should be descendant of "«$item_path»". |
2895
89c02b452717
SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents:
2894
diff
changeset
|
71 |
| hmi_widgets["«@id»"]`if "position()!=last()" > ,` |
2892
27dd409fba1d
SVGHMI: ForEach knows its own widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2891
diff
changeset
|
72 |
} |
2895
89c02b452717
SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents:
2894
diff
changeset
|
73 |
| ]`if "position()!=last()" > ,` |
2892
27dd409fba1d
SVGHMI: ForEach knows its own widgets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2891
diff
changeset
|
74 |
} |
2895
89c02b452717
SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents:
2894
diff
changeset
|
75 |
| ] |
89c02b452717
SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents:
2894
diff
changeset
|
76 |
| }, |
89c02b452717
SVGHMI: ForEach now has working (un)subscribe. Fixed PageSwitch that wasn't behaving when jumping to current page with another path.
Edouard Tisserant
parents:
2894
diff
changeset
|
77 |
| item_offset: 0, |
2891
8927ae8326b2
SVGHMI: add widget_foreach.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
78 |
} |
8927ae8326b2
SVGHMI: add widget_foreach.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
79 |
|
3232
7bdb766c2a4d
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3005
diff
changeset
|
80 |
widget_class("ForEach") |
2952
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
81 |
|| |
3005
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
82 |
|
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
83 |
unsub_items(){ |
2952
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
84 |
for(let item of this.items){ |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
85 |
for(let widget of item) { |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
86 |
widget.unsub(); |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
87 |
} |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
88 |
} |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
89 |
} |
2891
8927ae8326b2
SVGHMI: add widget_foreach.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
90 |
|
3005
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
91 |
unsub(){ |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
92 |
this.unsub_items(); |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
93 |
this.offset = 0; |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
94 |
this.relativeness = undefined; |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
95 |
} |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
96 |
|
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
97 |
sub_items(){ |
2952
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
98 |
for(let i = 0; i < this.items.length; i++) { |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
99 |
let item = this.items[i]; |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
100 |
let orig_item_index = this.index_pool[i]; |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
101 |
let item_index = this.index_pool[i+this.item_offset]; |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
102 |
let item_index_offset = item_index - orig_item_index; |
3005
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
103 |
if(this.relativeness[0]) |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
104 |
item_index_offset += this.offset; |
2952
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
105 |
for(let widget of item) { |
3005
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
106 |
/* all variables of all widgets in a ForEach are all relative. |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
107 |
Really. |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
108 |
|
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
109 |
TODO: allow absolute variables in ForEach widgets |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
110 |
*/ |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
111 |
widget.sub(item_index_offset, widget.indexes.map(_=>true)); |
2952
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
112 |
} |
2942
b07ad97e6019
SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
113 |
} |
b07ad97e6019
SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
114 |
} |
b07ad97e6019
SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
115 |
|
3005
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
116 |
sub(new_offset=0, relativeness=[]){ |
3003
9771a724af09
SVGHMI: Better JS code semantic in ForEach widget class. Update lagging generated xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2959
diff
changeset
|
117 |
this.offset = new_offset; |
3005
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
118 |
this.relativeness = relativeness; |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
119 |
this.sub_items(); |
2952
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
120 |
} |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
121 |
|
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
122 |
apply_cache() { |
3005
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
123 |
this.items.forEach(item=>item.forEach(widget=>widget.apply_cache())); |
2952
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
124 |
} |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
125 |
|
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
126 |
on_click(opstr, evt) { |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
127 |
let new_item_offset = eval(String(this.item_offset)+opstr); |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
128 |
if(new_item_offset + this.items.length > this.index_pool.length) { |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
129 |
if(this.item_offset + this.items.length == this.index_pool.length) |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
130 |
new_item_offset = 0; |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
131 |
else |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
132 |
new_item_offset = this.index_pool.length - this.items.length; |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
133 |
} else if(new_item_offset < 0) { |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
134 |
if(this.item_offset == 0) |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
135 |
new_item_offset = this.index_pool.length - this.items.length; |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
136 |
else |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
137 |
new_item_offset = 0; |
2942
b07ad97e6019
SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
138 |
} |
2952
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
139 |
this.item_offset = new_item_offset; |
3005
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
140 |
this.unsub_items(); |
ff9ae4f4e3be
SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3003
diff
changeset
|
141 |
this.sub_items(); |
2952
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
142 |
update_subscriptions(); |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
143 |
need_cache_apply.push(this); |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
144 |
jumps_need_update = true; |
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
145 |
requestHMIAnimation(); |
2942
b07ad97e6019
SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
146 |
} |
2952
2adfce8908b4
SVGHMI: apply per class overloading of sub/unsub to ForEach widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2943
diff
changeset
|
147 |
|| |
2942
b07ad97e6019
SVGHMI: moved JS code of foreach and jump widget in corresponding widget_*.ysl2. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
148 |