66 emit "preamble:local-variable-indexes" { |
66 emit "preamble:local-variable-indexes" { |
67 || |
67 || |
68 let hmi_locals = {}; |
68 let hmi_locals = {}; |
69 var last_remote_index = hmitree_types.length - 1; |
69 var last_remote_index = hmitree_types.length - 1; |
70 var next_available_index = hmitree_types.length; |
70 var next_available_index = hmitree_types.length; |
|
71 let cookies = new Map(document.cookie.split("; ").map(s=>s.split("="))); |
71 |
72 |
72 const local_defaults = { |
73 const local_defaults = { |
73 || |
74 || |
74 foreach "$parsed_widgets/widget[@type = 'VarInit']"{ |
75 foreach "$parsed_widgets/widget[starts-with(@type,'VarInit')]"{ |
75 if "count(path) != 1" error > VarInit «@id» must have only one variable given. |
76 if "count(path) != 1" error > VarInit «@id» must have only one variable given. |
76 if "path/@type != 'PAGE_LOCAL' and path/@type != 'HMI_LOCAL'" error > VarInit «@id» only applies to HMI variable. |
77 if "path/@type != 'PAGE_LOCAL' and path/@type != 'HMI_LOCAL'" error > VarInit «@id» only applies to HMI variable. |
77 | "«path/@value»":«arg[1]/@value»`if "position()!=last()" > ,` |
78 > "«path/@value»": |
|
79 choose { |
|
80 when "@type = 'VarInitPersistent'" > cookies.has("«path/@value»")?cookies.get("«path/@value»"):«arg[1]/@value» |
|
81 otherwise > «arg[1]/@value» |
|
82 } |
|
83 > \n |
|
84 if "position()!=last()" > , |
78 } |
85 } |
79 || |
86 || |
80 }; |
87 }; |
|
88 |
|
89 const persistent_locals = new Set([ |
|
90 || |
|
91 foreach "$parsed_widgets/widget[@type='VarInitPersistent']"{ |
|
92 | "«path/@value»"`if "position()!=last()" > ,` |
|
93 } |
|
94 || |
|
95 ]); |
|
96 var persistent_indexes = new Map(); |
81 var cache = hmitree_types.map(_ignored => undefined); |
97 var cache = hmitree_types.map(_ignored => undefined); |
82 |
98 |
83 function page_local_index(varname, pagename){ |
99 function page_local_index(varname, pagename){ |
84 let pagevars = hmi_locals[pagename]; |
100 let pagevars = hmi_locals[pagename]; |
85 let new_index; |
101 let new_index; |
94 |
110 |
95 new_index = next_available_index++; |
111 new_index = next_available_index++; |
96 pagevars[varname] = new_index; |
112 pagevars[varname] = new_index; |
97 } |
113 } |
98 let defaultval = local_defaults[varname]; |
114 let defaultval = local_defaults[varname]; |
99 if(defaultval != undefined) |
115 if(defaultval != undefined) { |
100 cache[new_index] = defaultval; |
116 cache[new_index] = defaultval; |
|
117 if(persistent_locals.has(varname)) |
|
118 persistent_indexes.set(new_index, varname); |
|
119 } |
101 return new_index; |
120 return new_index; |
102 } |
121 } |
103 |
122 |
104 function hmi_local_index(varname){ |
123 function hmi_local_index(varname){ |
105 return page_local_index(varname, "HMI_LOCAL"); |
124 return page_local_index(varname, "HMI_LOCAL"); |
263 } |
282 } |
264 } |
283 } |
265 || |
284 || |
266 } |
285 } |
267 |
286 |
268 const "excluded_types", "str:split('Page VarInit')"; |
287 const "excluded_types", "str:split('Page VarInit VarInitPersistent')"; |
269 |
288 |
270 // Key to filter unique types |
289 // Key to filter unique types |
271 key "TypesKey", "widget", "@type"; |
290 key "TypesKey", "widget", "@type"; |
272 |
291 |
273 emit "declarations:hmi-classes" { |
292 emit "declarations:hmi-classes" { |