From 09928b782019a7c82f1cc53d8a79c29d8632d6bd Mon Sep 17 00:00:00 2001 From: gifrerenom <lluis.gifre@cttc.es> Date: Wed, 23 Nov 2022 19:20:17 +0000 Subject: [PATCH] WebUI component: - updated device detail to show non-dictionary custom configuration rules as plain text --- src/webui/service/__init__.py | 14 ++++++++++---- src/webui/service/templates/device/detail.html | 15 ++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/webui/service/__init__.py b/src/webui/service/__init__.py index d60cca659..beb99a317 100644 --- a/src/webui/service/__init__.py +++ b/src/webui/service/__init__.py @@ -38,8 +38,14 @@ def readiness(): except Exception as e: raise HealthError('Can\'t connect with the service: ' + e.details()) -def from_json(json_str): - return json.loads(json_str) +def from_json(value): + try: + return json.loads(value) + except: + return value + +def is_dict(value): + return isinstance(value, dict) class SetSubAppMiddleware(): def __init__(self, app, web_app_root): @@ -80,10 +86,10 @@ def create_app(use_config=None, web_app_root=None): from webui.service.link.routes import link app.register_blueprint(link) - app.jinja_env.filters['from_json'] = from_json - + app.jinja_env.filters['is_dict'] = is_dict + app.jinja_env.globals.update(get_working_context=get_working_context) app.jinja_env.globals.update(get_working_topology=get_working_topology) diff --git a/src/webui/service/templates/device/detail.html b/src/webui/service/templates/device/detail.html index 69ca93727..2e8f79b87 100644 --- a/src/webui/service/templates/device/detail.html +++ b/src/webui/service/templates/device/detail.html @@ -94,11 +94,16 @@ {{ config.custom.resource_key }} </td> <td> - <ul> - {% for key, value in (config.custom.resource_value | from_json).items() %} - <li><b>{{ key }}:</b> {{ value }}</li> - {% endfor %} - </ul> + {% set json_resource_value = config.custom.resource_value | from_json %} + {% if json_resource_value | is_dict %} + <ul> + {% for key, value in json_resource_value.items() %} + <li><b>{{ key }}:</b> {{ value }}</li> + {% endfor %} + </ul> + {% else %} + {{ json_resource_value }} + {% endif %} </td> </tr> {% endif %} -- GitLab