-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add viewer index.html
to top level of results directory
#927
Conversation
index.html
to top level of results direcotry index.html
to top level of results directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @chengzhuzhang, another small PR ready for your review. Getting these out of the way quick!
PR description contains all the info.
@chengzhuzhang Nevermind not ready yet. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok @chengzhuzhang this PR is actually ready for review now. PR description for more info.
# Create an HTML file to list the contents of the prov dir. | ||
index_html_path = os.path.join(results_dir, "index.html") | ||
|
||
with open(index_html_path, "w") as f: | ||
f.write("<html><body><h1>Provenance Files</h1><ul>") | ||
|
||
for file_name in os.listdir(results_dir): | ||
file_path = os.path.join(results_dir, file_name) | ||
if os.path.isfile(file_path): | ||
f.write( | ||
f'<li><a href="{file_name}" target="_blank">{file_name}</a></li>' | ||
) | ||
|
||
f.write("</ul></body></html>") | ||
|
||
logger.info("Created provenance index HTML file at: {}".format(index_html_path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #928.
path = os.path.join(parameters_results[0].results_dir, "viewer") | ||
if not os.path.exists(path): | ||
os.makedirs(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved logic to /viewer/main.py
create_viewer()
@@ -72,6 +74,7 @@ def insert_data_in_row(row_obj, name, url): | |||
td = soup.new_tag("td") | |||
a = soup.new_tag("a") | |||
a["href"] = url | |||
a["target"] = "_blank" # Open link in a new tab |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now open links in a new tab in main viewer index page.
def _create_root_index(root_dir: str, viewer_index_url: str): | ||
"""Create a root level `index.html` file that redirects to the viewer index. | ||
|
||
Parameters | ||
---------- | ||
root_dir : str | ||
The root directory. | ||
index_url : str | ||
The url to the viewer index.html file. | ||
""" | ||
root_index_path = os.path.join(root_dir, "index.html") | ||
relative_viewer_index_url = os.path.relpath(viewer_index_url, root_dir) | ||
root_soup = BeautifulSoup( | ||
f""" | ||
<html> | ||
<head> | ||
<meta http-equiv='refresh' content='0; url={relative_viewer_index_url}' /> | ||
</head> | ||
<body></body> | ||
</html> | ||
""", | ||
"lxml", | ||
) | ||
|
||
# Write the root index file | ||
with open(root_index_path, "wb") as f: | ||
f.write(root_soup.prettify("utf-8")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creates a root level index.html
that redirects to the /viewer/index.html
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on visual check on code change. This PR is also good to go.
Description
This pull request updates the viewer to generate a top-level
index.html
in the root directory (results_dir
) that redirects to the/viewer/index.html
. It fixes the/prov
index page not displaying properly and makes links open in a new tab for convenience.Example: https://web.lcrc.anl.gov/public/e3sm/cdat-migration-fy24/562-index-html/
HTML Generation Improvements:
e3sm_diags_driver.py
(closes [Bug]:/prov
dir does not display properly on browser #928)create_viewer
function to create a root-levelindex.html
that redirects to the viewer index. [1] [2] (closes Add 'index.html' in top directory #562)Minor Fixes:
core_viewer.py
.main.py
.insert_data_in_row
function to open links in a new tab.Checklist
If applicable: