From bfb89a5e5aa7d8b12df42e9a2f70903039ae4c21 Mon Sep 17 00:00:00 2001 From: checktheroads Date: Tue, 20 Aug 2019 18:52:29 -0700 Subject: [PATCH] re-add query help --- hyperglass/render/html.py | 62 ++++++++++++++++------ hyperglass/render/templates/base.html.j2 | 2 +- hyperglass/render/templates/footer.html.j2 | 19 +++++-- hyperglass/static/hyperglass.es6 | 34 ++++++++++-- hyperglass/static/overrides.sass | 6 ++- 5 files changed, 97 insertions(+), 26 deletions(-) diff --git a/hyperglass/render/html.py b/hyperglass/render/html.py index 47fecb1..5376c3f 100644 --- a/hyperglass/render/html.py +++ b/hyperglass/render/html.py @@ -105,26 +105,54 @@ ets/traceroute_nanog.pdf" target="_blank">click here. } -def generate_markdown(section, file_name): +default_help = """ +--- +template: default_help +--- +##### BGP Route +Performs BGP table lookup based on IPv4/IPv6 prefix. +
+##### BGP Community +Performs BGP table lookup based on Extended or Large community value. +
+##### BGP AS Path +Performs BGP table lookup based on `AS_PATH` regular expression. +
+##### Ping +Sends 5 ICMP echo requests to the target. +
+##### Traceroute +Performs UDP Based traceroute to the target.
For information about how to \ +interpret traceroute results, click here. +""" + + +def generate_markdown(section, file_name=None): """ Renders markdown as HTML. If file_name exists in appropriate directory, it will be imported and used. If not, the default values will be used. Also renders the Front Matter values within each template. """ - if section == "info": - file = working_directory.joinpath(f"templates/info/{file_name}.md") - defaults = default_info + if section == "help": + file = working_directory.joinpath("templates/info/help.md") + if file.exists(): + with file.open(mode="r") as file_raw: + yaml_raw = file_raw.read() + else: + yaml_raw = default_help elif section == "details": file = working_directory.joinpath(f"templates/info/details/{file_name}.md") - defaults = default_details - if file.exists(): - with file.open(mode="r") as file_raw: - yaml_raw = file_raw.read() - else: - yaml_raw = defaults[file_name] + if file.exists(): + with file.open(mode="r") as file_raw: + yaml_raw = file_raw.read() + else: + yaml_raw = default_details[file_name] _, frontmatter, content = yaml_raw.split("---", 2) - html_classes = {"table": "ui compact table"} + html_classes = {"table": "table"} markdown = Markdown( extras={ "break-on-newline": True, @@ -169,15 +197,17 @@ def render_html(template_name, **kwargs): details_data = generate_markdown("details", details_name) details_dict.update({details_name: details_data}) info_list = ["bgp_route", "bgp_aspath", "bgp_community", "ping", "traceroute"] - info_dict = {} - for info_name in info_list: - info_data = generate_markdown("info", info_name) - info_dict.update({info_name: info_data}) + rendered_help = generate_markdown("help") + logger.debug(rendered_help) try: template_file = f"templates/{template_name}.html.j2" template = env.get_template(template_file) return template.render( - params, info=info_dict, details=details_dict, networks=networks, **kwargs + params, + rendered_help=rendered_help, + details=details_dict, + networks=networks, + **kwargs, ) except jinja2.TemplateNotFound as template_error: logger.error( diff --git a/hyperglass/render/templates/base.html.j2 b/hyperglass/render/templates/base.html.j2 index 75e8c7a..c5b729e 100644 --- a/hyperglass/render/templates/base.html.j2 +++ b/hyperglass/render/templates/base.html.j2 @@ -29,7 +29,7 @@ {% block content %} {% endblock %} - {% include "templates/footer.html.j2" %} diff --git a/hyperglass/render/templates/footer.html.j2 b/hyperglass/render/templates/footer.html.j2 index 74a45c7..e00ac9a 100644 --- a/hyperglass/render/templates/footer.html.j2 +++ b/hyperglass/render/templates/footer.html.j2 @@ -2,16 +2,27 @@