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

HTML frontend #178

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions backend/PythonClient/server/simulation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def list_reports():
def list_folder_contents(folder_name):
"""
Lists the contents of a specific report folder from GCS,
including generating proxy URLs for HTML files.
including generating proxy URLs for HTML files at any depth.
"""
try:
# Define the prefix for the specific folder
Expand Down Expand Up @@ -145,15 +145,16 @@ def list_folder_contents(folder_name):
else:
process_gcs_directory(prefix, result, "")

# After processing all blobs, collect HTML files
# After processing all blobs, collect HTML files at any depth
html_blobs = bucket.list_blobs(prefix=prefix)
for html_blob in html_blobs:
if html_blob.name.endswith('.html'):
file_name = os.path.basename(html_blob.name)
# Create a proxy URL for the HTML file
proxy_url = f"/serve-html/{folder_name}/{file_name}"
relative_path = os.path.relpath(html_blob.name, prefix)
# Ensure URL is properly formatted
proxy_url = f"/serve-html/{folder_name}/{relative_path.replace(os.sep, '/')}"
result["htmlFiles"].append({
"name": file_name,
"name": os.path.basename(html_blob.name),
"path": relative_path.replace(os.sep, '/'), # Relative path within the folder
Comment on lines +148 to +157
Copy link
Member

Choose a reason for hiding this comment

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

This is needed for HTML's in nested files. Looks good.

"url": proxy_url
})

Expand Down Expand Up @@ -280,7 +281,7 @@ def get_current_running():
@app.route('/report/<path:dir_name>')
def get_report(dir_name=''):
"""
Serves reports from GCS.
Serves reports from GCS. Note: Serving files directly from GCS might require generating signed URLs.
"""
try:
if dir_name:
Expand Down Expand Up @@ -336,14 +337,15 @@ def get_map():
return task_dispatcher.load_cesium_setting()

# === Proxy Endpoint to Serve HTML Files ===
@app.route('/serve-html/<folder_name>/<file_name>', methods=['GET'])
def serve_html(folder_name, file_name):
@app.route('/serve-html/<folder_name>/<path:relative_path>', methods=['GET'])
def serve_html(folder_name, relative_path):
"""
Serves HTML files securely through a proxy route.
Handles HTML files located at any depth within the specified folder.
"""
try:
# Construct the GCS file path
blob_path = f'reports/{folder_name}/{file_name}'
# Construct the full GCS file path
blob_path = f'reports/{folder_name}/{relative_path}'
blob = bucket.blob(blob_path)

# Check if the file exists and is an HTML file
Expand Down
28 changes: 27 additions & 1 deletion frontend/src/components/FuzzyDashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,33 @@ export default function FuzzyDashboard() {
</Box>
</React.Fragment> }
</Box>

<Box sx={{ display: 'flex', flexWrap: 'wrap', m: 1 }}>
<Paper elevation={3} sx={{ margin: '25px', padding: 2, width: '100%' }}>
<Typography variant="h5" component="h2" sx={{ fontFamily: 'sans-serif', fontWeight: 700 }}>
Interactable HTMLs
</Typography>
<ul>
{resp.htmlFiles && resp.htmlFiles.length > 0 ? (
resp.htmlFiles.map((htmlFile, index) => (
<li key={index}>
<Link
href={`http://localhost:5000${encodeURI(htmlFile.url)}`}
target="_blank"
rel="noopener noreferrer"
sx={{ textDecoration: 'none', color: 'blue' }}
>
{htmlFile.name}
</Link>
</li>
))
) : (
<Typography variant="body1" sx={{ fontStyle: 'italic' }}>
No HTML files available for interaction.
</Typography>
)}
</ul>
</Paper>
</Box>
Comment on lines +1357 to +1383
Copy link
Member

Choose a reason for hiding this comment

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

This looks good. It's consistent with the other details on the frontend, and has its own "Interactable HTMLs" section.

{/* end of fuzzy */}
<div>
<Modal
Expand Down
Loading