Skip to content

Commit

Permalink
Merge pull request #178 from oss-slu/issue175
Browse files Browse the repository at this point in the history
HTML frontend
  • Loading branch information
mohamdlog authored Nov 28, 2024
2 parents b65ae54 + 7f034d4 commit 8f4de86
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
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
"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>
{/* end of fuzzy */}
<div>
<Modal
Expand Down

0 comments on commit 8f4de86

Please sign in to comment.