99 lines
3.2 KiB
Plaintext
99 lines
3.2 KiB
Plaintext
import os, json, sys
|
|
|
|
global_project_page_ids = {}
|
|
|
|
def get_project_config():
|
|
"""
|
|
Scan each view.json under Detailed_Views (no recursion),
|
|
go one level deeper (coordinateContainer), extract tagProps[0]
|
|
from children, and store as {source_id: view_folder_name}.
|
|
"""
|
|
global global_project_page_ids
|
|
global_project_page_ids.clear()
|
|
|
|
try:
|
|
project_name = system.util.getProjectName()
|
|
base_path = (
|
|
os.getcwd().replace("\\", "/")
|
|
+ "/data/projects/"
|
|
+ project_name
|
|
+ "/com.inductiveautomation.perspective/Views/autStand/Detailed_Views"
|
|
)
|
|
|
|
if not os.path.exists(base_path):
|
|
system.perspective.print("Path not found: " + base_path)
|
|
return {}
|
|
|
|
for view_folder in os.listdir(base_path):
|
|
json_file = os.path.join(base_path, view_folder, "view.json")
|
|
if not os.path.isfile(json_file):
|
|
continue
|
|
|
|
with open(json_file, "r") as fh:
|
|
view_json = json.load(fh)
|
|
|
|
# go one level deeper: root -> children[0] (coordinateContainer) -> its children
|
|
root_children = (view_json.get("root") or {}).get("children") or []
|
|
if not root_children:
|
|
continue
|
|
|
|
# assume first child is the coordinateContainer
|
|
container = root_children[0]
|
|
children = container.get("children") or []
|
|
|
|
# now loop through these children to get tagProps
|
|
for child in children:
|
|
props = child.get("props") or {}
|
|
params = props.get("params") or {}
|
|
tag_props = params.get("tagProps")
|
|
|
|
if isinstance(tag_props, list) and len(tag_props) > 0:
|
|
source_id = str(tag_props[0])
|
|
global_project_page_ids[source_id] = view_folder
|
|
|
|
except:
|
|
whid = system.tag.readBlocking("Configuration/FC")[0].value
|
|
logger = system.util.getLogger("%s-get_project_config" % whid)
|
|
exc_type, exc_obj, tb = sys.exc_info()
|
|
logger.error("Error at line %s: %s" % (tb.tb_lineno, exc_obj))
|
|
|
|
return global_project_page_ids
|
|
|
|
def navigate_to_url(self, source_id, page_id):
|
|
url_to_navigate = "autStand/Detailed_Views/%s" % (page_id)
|
|
system.perspective.navigate(view=url_to_navigate, params={"highlightTagPath": source_id + "||Diagnostic"})
|
|
|
|
|
|
def source_id_lookup(self, source_id):
|
|
"""
|
|
Finds page_id from global_project_page_ids by source_id or by hierarchy,
|
|
then navigates.
|
|
"""
|
|
if not source_id:
|
|
return
|
|
|
|
page_id = global_project_page_ids.get(source_id)
|
|
found = False
|
|
|
|
if page_id:
|
|
found = True
|
|
navigate_to_url(self, source_id, page_id)
|
|
else:
|
|
# Walk hierarchy upwards until we find a match
|
|
items = source_id.split("/")
|
|
while len(items) > 1:
|
|
items.pop()
|
|
source_id = "/".join(items)
|
|
page_id = global_project_page_ids.get(source_id)
|
|
if page_id:
|
|
found = True
|
|
navigate_to_url(self, source_id, page_id)
|
|
break
|
|
|
|
if not found:
|
|
open_pop_up("No page id found")
|
|
|
|
|
|
|
|
|
|
|