127 lines
3.8 KiB
Plaintext
127 lines
3.8 KiB
Plaintext
def get_udt_configuration(instance_path, category = None):
|
|
"""
|
|
Scans a UDT instance for members belonging to a UI category
|
|
and returns their display configurations. Optional category argumen,
|
|
if defined, it will returna filtered list.
|
|
Beware of this instruction, it uses system.tag.readBlocking.
|
|
Args:
|
|
instance_path (str): The UDT path
|
|
target_category (str): The filter criteria (e.g., 'Status', 'Control', 'Config').
|
|
|
|
Returns:
|
|
list: A list of UDT items tagpaths and it's custom properties.
|
|
"""
|
|
# 1. Browse for all tags inside the instance
|
|
fltr = {'tagType':'UdtInstance', 'recursive':True}
|
|
results = system.tag.browse(instance_path, fltr)
|
|
|
|
# Identify the properties we need for each tag founf
|
|
property_names = [
|
|
'/parameters.item_label',
|
|
'/parameters.ui_accessLevel',
|
|
'/parameters.ui_format',
|
|
'/parameters.ui_group',
|
|
'/parameters.ui_isHidden',
|
|
'/parameters.ui_isReadOnly',
|
|
'/parameters.ui_order',
|
|
'/parameters.ui_type',
|
|
'/parameters.ui_widget',
|
|
'.ui_states']
|
|
|
|
# 2. Build a flat list of paths to read everything in on Gatewya request
|
|
read_paths = []
|
|
tags_found = [str(r['fullPath']) for r in results]
|
|
|
|
for tag in tags_found:
|
|
for prop in property_names:
|
|
read_paths.append('%s%s' % (tag, prop))
|
|
|
|
all_values = system.tag.readBlocking(read_paths)
|
|
# for value in all_values:
|
|
# print value
|
|
# 3. Process the result in 'chunks'
|
|
# step by the length of properties
|
|
output = []
|
|
|
|
step = len(property_names)
|
|
for i in range(0, len(all_values), step):
|
|
chunk = all_values[i : i + step]
|
|
if category is not None and chunk[7].value != category:
|
|
continue
|
|
subpath = tags_found[i // step].split(instance_path)[-1]
|
|
output.append({
|
|
"sub_path": subpath,
|
|
"item_label": chunk[0].value,
|
|
"access_level": chunk[1].value,
|
|
"format": chunk[2].value,
|
|
"group": chunk[3].value,
|
|
"is_hidden": bool(chunk[4].value),
|
|
"is_read_only": bool(chunk[5].value),
|
|
"order": chunk[6].value,
|
|
"type": chunk[7].value,
|
|
"widget": chunk[8].value,
|
|
"states": chunk[9].value
|
|
})
|
|
return output
|
|
|
|
def generate_flex_array(list_tags, base_path):
|
|
"""
|
|
This function, generates de array for the flex repeater
|
|
in details pages, it hides the elements based on is_hidden property
|
|
and concatenates the dinamyc tagpath with the item sub path
|
|
Args:
|
|
instance_path (str): The UDT path
|
|
|
|
Returns:
|
|
list: A list of tags to be used in detail pages flex repeater.
|
|
"""
|
|
output = []
|
|
for item in list_tags:
|
|
if item['is_hidden'] is True:
|
|
continue
|
|
new_item = dict(item)
|
|
new_item['tagpath'] = base_path + str(item.get('sub_path', ''))
|
|
tag= {'item': new_item}
|
|
output.append(tag)
|
|
|
|
return output
|
|
|
|
def get_udt_menu(instance_path):
|
|
"""
|
|
Scans a UDT instance for members belonging to a UI category
|
|
and returns their display configurations. Optional category argumen,
|
|
if defined, it will returna filtered list.
|
|
Beware of this instruction, it uses system.tag.readBlocking.
|
|
Args:
|
|
instance_path (str): The UDT path
|
|
target_category (str): The filter criteria (e.g., 'Status', 'Control', 'Config').
|
|
|
|
Returns:
|
|
list: A list of UDT items tagpaths and it's custom properties.
|
|
"""
|
|
# 1. Browse for all tags inside the instance
|
|
fltr = {'tagType':'UdtInstance', 'recursive':True}
|
|
results = system.tag.browse(instance_path, fltr)
|
|
|
|
# Identify the properties we need for each tag founf
|
|
property_names = ['/parameters.ui_type']
|
|
|
|
# 2. Build a flat list of paths to read everything in on Gatewya request
|
|
read_paths = []
|
|
tags_found = [str(r['fullPath']) for r in results]
|
|
|
|
for tag in tags_found:
|
|
for prop in property_names:
|
|
read_paths.append('%s%s' % (tag, prop))
|
|
|
|
all_values = system.tag.readBlocking(read_paths)
|
|
# for value in all_values:
|
|
# print value
|
|
# 3. Process the result in 'chunks'
|
|
# step by the length of properties
|
|
output = []
|
|
for i in all_values:
|
|
if i.value not in output:
|
|
output.append(i.value)
|
|
|
|
return output |