From 366a7ef071d4993f55073d5cebee93aef5b0ac24 Mon Sep 17 00:00:00 2001 From: Leo Schick Date: Mon, 18 Jul 2022 08:41:16 +0200 Subject: [PATCH] add option to hide system stats in the UI #72 --- mara_pipelines/config.py | 5 +++++ mara_pipelines/ui/last_runs.py | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/mara_pipelines/config.py b/mara_pipelines/config.py index 4595d94..b482eb4 100644 --- a/mara_pipelines/config.py +++ b/mara_pipelines/config.py @@ -68,6 +68,11 @@ def allow_run_from_web_ui() -> bool: return True +def display_system_statistics() -> bool: + """If the system statistics shall be visible in the web UI.""" + return True + + def base_url() -> str: """External url of flask app, for linking nodes in slack messages""" return 'http://127.0.0.1:5000/pipelines' diff --git a/mara_pipelines/ui/last_runs.py b/mara_pipelines/ui/last_runs.py index 956c0f0..21ef10b 100644 --- a/mara_pipelines/ui/last_runs.py +++ b/mara_pipelines/ui/last_runs.py @@ -9,22 +9,26 @@ import mara_db.postgresql from mara_page import bootstrap, html, acl, _ from . import views -from .. import pipelines +from .. import config, pipelines def card(node: pipelines.Node) -> str: """A card that shows the system stats, the time line and output for the last runs or a node""" + statistic_content = [] + if config.display_system_statistics(): + statistic_content.append( + html.asynchronous_content(url=flask.url_for('mara_pipelines.system_stats', path=node.url_path(), run_id=None), + div_id='system-stats')) + return bootstrap.card( id='last-runs-card', header_left=[ 'Last runs ', _.div(style='display:inline-block;margin-left:20px;')[html.asynchronous_content( flask.url_for('mara_pipelines.last_runs_selector', path=node.url_path()))]], - body=[html.spinner_js_function(), - html.asynchronous_content( - url=flask.url_for('mara_pipelines.system_stats', path=node.url_path(), run_id=None), - div_id='system-stats'), - html.asynchronous_content( + body=[html.spinner_js_function()] \ + + statistic_content + \ + [html.asynchronous_content( url=flask.url_for('mara_pipelines.timeline_chart', path=node.url_path(), run_id=None), div_id='timeline-chart'), html.asynchronous_content( @@ -123,6 +127,9 @@ def run_output(path: str, run_id: int, limit: bool): @views.blueprint.route('/system-stats/', defaults={'path': ''}) @acl.require_permission(views.acl_resource, do_abort=False) def system_stats(path: str, run_id: int): + if not config.display_system_statistics(): + return '' + node, __ = pipelines.find_node(path.split('/')) run_id = run_id or _latest_run_id(node.path())