From 719ce04cefe84e62662bca1404776a3f55251cc5 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 1 Dec 2020 23:33:29 +0300 Subject: Remove stale comment --- wqflask/wqflask/markdown_routes.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 601845d7..1e077dd1 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -26,8 +26,6 @@ look for it inside the file system """ if md_content.status_code == 200: return markdown.markdown(md_content.content.decode("utf-8"), extensions=['tables']) - # TODO: Add fallback on our git server by checking the mirror. - # Content not available return (f"\nContent for {file_name} not available. " "Please check " "(here to see where content exists)" -- cgit v1.2.3 From 6a2fb6cced98d79cd1ccbe6490a59393486fdf92 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 1 Dec 2020 23:34:36 +0300 Subject: Add new function to fetch md file from sys paths * wqflask/wqflask/markdown_routes.py: New imports. (get_file_from_python_search_path): New function. --- wqflask/wqflask/markdown_routes.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'wqflask') diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 1e077dd1..e43b9860 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -4,6 +4,8 @@ Render pages from github, or if they are unavailable, look for it else where """ import requests import markdown +import os +import sys from flask import Blueprint from flask import render_template @@ -33,6 +35,14 @@ look for it inside the file system """ "Please reach out to the gn2 team to have a look at this") +def get_file_from_python_search_path(pathname_suffix): + cands = [os.path.join(d, pathname_suffix) for d in sys.path] + try: + return list(filter(os.path.exists, cands))[0] + except IndexError: + return None + + @glossary_blueprint.route('/') def glossary(): return render_template( -- cgit v1.2.3 From e75056aa81c9d66379a3b4823ded69f0781c5374 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 1 Dec 2020 23:36:10 +0300 Subject: Fetch file from systempath when loading "/environments" route * wqflask/wqflask/markdown_routes.py: (render_markdown): Extend function to check whether "file_name" is to be fetched remotely or locally in syspath. (environments): Extend route to fetch from syspath if dependency file exists there; otherwise fetch remotely from Github as a fallback. --- wqflask/wqflask/markdown_routes.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index e43b9860..59a465e7 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -18,16 +18,25 @@ policies_blueprint = Blueprint("policies_blueprint", __name__) facilities_blueprint = Blueprint("facilities_blueprint", __name__) -def render_markdown(file_name): +def render_markdown(file_name, is_remote_file=True): """Try to fetch the file name from Github and if that fails, try to look for it inside the file system """ github_url = ("https://raw.githubusercontent.com/" "genenetwork/gn-docs/master/") + if not is_remote_file: + text = "" + with open(file_name, "r", encoding="utf-8") as input_file: + text = input_file.read() + return markdown.markdown(text, + extensions=['tables']) + md_content = requests.get(f"{github_url}{file_name}") + if md_content.status_code == 200: + return markdown.markdown(md_content.content.decode("utf-8"), + extensions=['tables']) - return markdown.markdown(md_content.content.decode("utf-8"), extensions=['tables']) return (f"\nContent for {file_name} not available. " "Please check " "(here to see where content exists)" @@ -59,7 +68,21 @@ def references(): @environments_blueprint.route("/") def environments(): - return render_template("environment.html", rendered_markdown=render_markdown("general/environments/environments.md")), 200 + md_file = get_file_from_python_search_path("wqflask/DEPENDENCIES.md") + if md_file is not None: + return ( + render_template("environment.html", + rendered_markdown=render_markdown( + md_file, + is_remote_file=False)), + 200 + ) + # Fallback: Fetch file from server + return (render_template( + "environment.html", + rendered_markdown=render_markdown( + "general/environments/environments.md")), + 200) @links_blueprint.route("/") -- cgit v1.2.3 From 1cf0edb0719e4cf1c8410d8a910b199bb10180ef Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Thu, 3 Dec 2020 00:12:04 +0300 Subject: Remove edit button in environments page * wqflask/wqflask/templates/environment.html: Delete edit button. The dependency file is autogenerated from guix. --- wqflask/wqflask/templates/environment.html | 8 -------- 1 file changed, 8 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/templates/environment.html b/wqflask/wqflask/templates/environment.html index 94b31464..34ebf36e 100644 --- a/wqflask/wqflask/templates/environment.html +++ b/wqflask/wqflask/templates/environment.html @@ -8,14 +8,6 @@ {% block content %} -
-
- - Edit Text - - -
-
{{ rendered_markdown|safe }}
-- cgit v1.2.3 From bf4b901fe7ebd02416b026974ed784970d8023dd Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Thu, 3 Dec 2020 00:23:23 +0300 Subject: Move css from environment.html to markdown.css --- wqflask/wqflask/static/new/css/markdown.css | 19 ++++++++++++++++++- wqflask/wqflask/templates/environment.html | 16 ---------------- 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/static/new/css/markdown.css b/wqflask/wqflask/static/new/css/markdown.css index dca3e31d..e10dd9d3 100644 --- a/wqflask/wqflask/static/new/css/markdown.css +++ b/wqflask/wqflask/static/new/css/markdown.css @@ -57,8 +57,25 @@ word-spacing: 0.2em; } +#markdown table { + width: 100%; +} + +#markdown table, +#markdown td, +#markdown th { + border: solid 2px black; +} + +#markdown td, +#markdown th { + padding-top: 8px; + padding-bottom: 8px; + text-align: center; +} + @media(max-width:650px) { .container { width: 100vw; } -} \ No newline at end of file +} diff --git a/wqflask/wqflask/templates/environment.html b/wqflask/wqflask/templates/environment.html index 34ebf36e..cd30e768 100644 --- a/wqflask/wqflask/templates/environment.html +++ b/wqflask/wqflask/templates/environment.html @@ -13,20 +13,4 @@
{{ rendered_markdown|safe }}
- {% endblock %} -- cgit v1.2.3 From 66fb2fa6bf83b8d6e6d1cb7e159ea806bca4aebb Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Thu, 3 Dec 2020 00:28:56 +0300 Subject: Center-align the table header and left-align the table body --- wqflask/wqflask/static/new/css/markdown.css | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/static/new/css/markdown.css b/wqflask/wqflask/static/new/css/markdown.css index e10dd9d3..0c0309fb 100644 --- a/wqflask/wqflask/static/new/css/markdown.css +++ b/wqflask/wqflask/static/new/css/markdown.css @@ -61,6 +61,15 @@ width: 100%; } +#markdown td { + padding: 1em; + text-align: left; +} + +#markdown th { + text-align: center; +} + #markdown table, #markdown td, #markdown th { @@ -71,7 +80,6 @@ #markdown th { padding-top: 8px; padding-bottom: 8px; - text-align: center; } @media(max-width:650px) { -- cgit v1.2.3 From 64bfeadac33e6d22297714544cd96ef16677fe16 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Thu, 3 Dec 2020 23:59:14 +0300 Subject: Display d3js chord dependency diagram of gn2 dependenices * wqflask/wqflask/markdown_routes.py: Add new bs4 import. (references): Filter out javascript from the guix-generated d3js html file and pass it to the jinja template. * wqflask/wqflask/static/new/css/markdown.css: New styles for the graph content. * wqflask/wqflask/templates/environment.html: New graph content. --- wqflask/wqflask/markdown_routes.py | 14 +++ wqflask/wqflask/static/new/css/markdown.css | 14 +++ wqflask/wqflask/templates/environment.html | 134 ++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) (limited to 'wqflask') diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 59a465e7..183f4caa 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -7,6 +7,8 @@ import markdown import os import sys +from bs4 import BeautifulSoup + from flask import Blueprint from flask import render_template @@ -68,10 +70,21 @@ def references(): @environments_blueprint.route("/") def environments(): + md_file = get_file_from_python_search_path("wqflask/DEPENDENCIES.md") + svg_file = get_file_from_python_search_path( + "wqflask/dependency-graph.html") + svg_data = None + if svg_file: + with open(svg_file, 'r') as f: + svg_data = "".join( + BeautifulSoup(f.read(), + 'lxml').body.script.contents) + if md_file is not None: return ( render_template("environment.html", + svg_data=svg_data, rendered_markdown=render_markdown( md_file, is_remote_file=False)), @@ -80,6 +93,7 @@ def environments(): # Fallback: Fetch file from server return (render_template( "environment.html", + svg_data=None, rendered_markdown=render_markdown( "general/environments/environments.md")), 200) diff --git a/wqflask/wqflask/static/new/css/markdown.css b/wqflask/wqflask/static/new/css/markdown.css index 0c0309fb..38d664e2 100644 --- a/wqflask/wqflask/static/new/css/markdown.css +++ b/wqflask/wqflask/static/new/css/markdown.css @@ -57,6 +57,20 @@ word-spacing: 0.2em; } +.graph-legend h1 { + text-align: center; +} + +.graph-legend, +#guix-graph { + width: 90%; + margin: 10px auto; +} + +#guix-graph { + border: solid 2px black; +} + #markdown table { width: 100%; } diff --git a/wqflask/wqflask/templates/environment.html b/wqflask/wqflask/templates/environment.html index cd30e768..5fe01dad 100644 --- a/wqflask/wqflask/templates/environment.html +++ b/wqflask/wqflask/templates/environment.html @@ -13,4 +13,138 @@
{{ rendered_markdown|safe }}
+{% if svg_data %} + +
+

Chord dependency Graph of Genenetwork2

+ Graph generated from genenetwork.scm. You can zoom in and out within the bounding box. +
+ +
+{% endif %} + +{% endblock %} + +{% block js %} + +{% if svg_data %} + + +{% endif %} + {% endblock %} -- cgit v1.2.3