Commit f41db75a authored by Alok Saldanha's avatar Alok Saldanha
Browse files

#15 added intermediate index pages

parent 876263c0
......@@ -68,7 +68,7 @@ def recurse_dir(path):
}
elif os.path.isdir(full_path):
return {
"path": full_path,
"path": full_path.replace(env.cellxgene_data, ""),
"name": el,
"type": "directory",
"children": recurse_dir(full_path),
......@@ -88,7 +88,8 @@ def render_entries(entries):
def render_entry(entry):
if entry["type"] == "file":
url = 'view' + '/' + entry['path'].lstrip("/")
url = f"/view/{entry['path'].lstrip('/')}"
return f"<li> <a href='{ url}'>{entry['name']}</a></li>"
elif entry["type"] == "directory":
return f"<li>{entry['name']}{render_entries(entry['children'])}</li>"
url = f"/filecrawl/{entry['path'].lstrip('/')}"
return f"<li><a href='{url}'>{entry['name']}</a>{render_entries(entry['children'])}</li>"
......@@ -168,6 +168,22 @@ def filecrawl():
rendered_html=rendered_html,
)
@app.route("/filecrawl/<path:path>")
def do_filecrawl(path):
filecrawl_path = os.path.join(env.cellxgene_data, path)
if not os.path.isdir(filecrawl_path):
raise CellxgeneException(
"Path is not directory: " + filecrawl_path, status.HTTP_400_BAD_REQUEST
)
entries = recurse_dir(filecrawl_path)
rendered_html = render_entries(entries)
return render_template(
"filecrawl.html",
extra_scripts=get_extra_scripts(),
rendered_html=rendered_html,
path=path,
)
entry_lock = Lock()
@app.route("/view/<path:path>", methods=["GET", "PUT", "POST"])
def do_view(path):
......
......@@ -21,7 +21,11 @@
</head>
<body>
<header class="navbar navbar-expand navbar-dark flex-column flex-md-row bd-navbar">
<h3>Cellxgene Gateway - FILE CRAWLER</h3>
{% if path %}
<h3>Cellxgene Gateway - {{ path }}</h3>
{% else %}
<h3>Cellxgene Gateway - FILE CRAWLER</h3>
{% endif %}
</header>
<br>
......@@ -29,6 +33,15 @@
<br>
{{ rendered_html|safe }}
<p>
Navigation:
<ul>
{% if path %}
<li><a href="/filecrawl.html">top level</a></li>
{% else %}
{% endif %}
<li><a href="/">homepage</a></li>
</ul>
</p>
</body>
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment