Skip to content
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

Merged
merged 7 commits into from
Jan 31, 2025

Conversation

tomvothecoder
Copy link
Collaborator

@tomvothecoder tomvothecoder commented Jan 28, 2025

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:

Minor Fixes:

  • Corrected a typo in an error message in core_viewer.py.
  • Added missing type annotations and imports in main.py.
  • Updated the insert_data_in_row function to open links in a new tab.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

If applicable:

  • New and existing unit tests pass with my changes (locally and CI/CD build)
  • I have added tests that prove my fix is effective or that my feature works
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have noted that this is a breaking change for a major release (fix or feature that would cause existing functionality to not work as expected)

@tomvothecoder tomvothecoder marked this pull request as draft January 28, 2025 23:27
@tomvothecoder tomvothecoder self-assigned this Jan 28, 2025
@tomvothecoder tomvothecoder added the documentation Files in `docs` modified label Jan 28, 2025
@tomvothecoder tomvothecoder changed the title Add viewer index.html to top level of results direcotry Add viewer index.html to top level of results directory Jan 28, 2025
@tomvothecoder tomvothecoder marked this pull request as ready for review January 29, 2025 22:42
Copy link
Collaborator Author

@tomvothecoder tomvothecoder left a 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.

e3sm_diags/e3sm_diags_driver.py Show resolved Hide resolved
e3sm_diags/viewer/main.py Outdated Show resolved Hide resolved
@tomvothecoder
Copy link
Collaborator Author

@chengzhuzhang Nevermind not ready yet. The .png files aren't linked correctly to the viewer, which is causing the build to break. Converting back to draft.

@tomvothecoder tomvothecoder marked this pull request as draft January 29, 2025 22:54
@tomvothecoder tomvothecoder marked this pull request as ready for review January 30, 2025 00:04
Copy link
Collaborator Author

@tomvothecoder tomvothecoder left a 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.

Comment on lines +144 to +159
# 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))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #928.

Comment on lines -391 to -393
path = os.path.join(parameters_results[0].results_dir, "viewer")
if not os.path.exists(path):
os.makedirs(path)
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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.

Comment on lines +160 to +186
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"))
Copy link
Collaborator Author

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.

Copy link
Contributor

@chengzhuzhang chengzhuzhang left a 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.

@tomvothecoder tomvothecoder merged commit 0e0cacb into main Jan 31, 2025
6 checks passed
@tomvothecoder tomvothecoder deleted the docs/562-index-html branch January 31, 2025 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Files in `docs` modified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: /prov dir does not display properly on browser Add 'index.html' in top directory
2 participants