Skip to content

Commit

Permalink
Update of web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislavsulc committed Mar 13, 2024
1 parent 7888daa commit d635a20
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 46 deletions.
9 changes: 3 additions & 6 deletions mupifDB/api/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from fastapi import FastAPI, UploadFile, Depends
from fastapi.responses import FileResponse, StreamingResponse
from fastapi.responses import HTMLResponse
Expand Down Expand Up @@ -469,11 +471,6 @@ def get_file(uid: str, tdir=Depends(get_temp_dir)):
wfile = io.BytesIO(foundfile.read())
fn = foundfile.filename
return StreamingResponse(wfile, headers={"Content-Disposition": "attachment; filename=" + fn})
# fullpath = tdir + '/' + fn
# with open(fullpath, "wb") as f:
# f.write(wfile.read())
# f.close()
# return FileResponse(path=fullpath, media_type='application/octet-stream', headers={"Content-Disposition": "attachment; filename=" + fn})


@app.post("/file/", tags=["Files"])
Expand Down Expand Up @@ -506,7 +503,7 @@ def get_property_array_data(fid: str, i_start: int, i_count: int):


@app.get("/field_as_vtu/{fid}", tags=["Additional"])
def get_property_array_data(fid: str, tdir=Depends(get_temp_dir)):
def get_field_as_vtu(fid: str, tdir=Depends(get_temp_dir)):
pfile, fn = mupifDB.restApiControl.getBinaryFileByID(fid)
full_path = tdir + "/file.h5"
f = open(full_path, 'wb')
Expand Down
17 changes: 14 additions & 3 deletions mupifDB/workflowmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,20 @@ def mapOutput(app, eid, name, obj_id, data_id, time, object_type, onto_path=None
else:
raise ValueError('Handling of io param of type %s not implemented' % object_type)

# elif object_type == 'mupif.PyroFile':
# prop = app.get(mupif.DataID[data_id], time, obj_id)
# restApiControl.setExecutionOutputObject(eid, name, obj_id, prop.to_db_dict())
elif object_type == 'mupif.PyroFile':
pf = app.get(mupif.DataID[data_id], time, obj_id)
with tempfile.TemporaryDirectory(dir="/tmp", prefix='mupifDB') as tempDir:
fn = pf.getBasename()
full_path = tempDir + "/" + fn
mupif.PyroFile.copy(pf, full_path)
fileID = None
with open(full_path, 'rb') as f:
fileID = restApiControl.uploadBinaryFile(f)
f.close()
if fileID is not None:
restApiControl.setExecutionOutputObject(eid, name, obj_id, {'FileID': fileID})
else:
print("PyroFile file was not saved")

elif object_type == 'mupif.HeavyStruct':
hs = app.get(mupif.DataID[data_id], time, obj_id)
Expand Down
77 changes: 43 additions & 34 deletions webapi/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def executions():
if 'filter_status' in args:
filter_status = str(args['filter_status'])

html = '<h3>List of workflow executions:</h3>'
html = '<h3>List of workflow executions</h3>'
html += '<form id="filtering_form" action="" style="font-size:12px;" method="get">'
html += 'WorkflowID: <input type="text" name="filter_workflow_id" value="' + filter_workflow_id + '" style="width:100px;"> '
html += 'version: <input type="text" name="filter_workflow_version" value="' + filter_workflow_version + '" style="width:20px;"> '
Expand Down Expand Up @@ -586,7 +586,7 @@ def setExecutionInputs(weid):
if obo_id is not None:
restApiControl.setExecutionOntoBaseObjectID(weid, name=obo.get('Name', ''), value=obo_id)

msg += "</br><a href=\"/workflowexecutions/"+weid+"\">Back to Execution record "+weid+"</a>"
msg += "</br><a href=\"/workflowexecutions/"+weid+"\">Back to Execution detail</a>"
# return my_render_template("basic.html", body=Markup(msg))

execution_record = restApiControl.getExecutionRecord(weid)
Expand All @@ -595,11 +595,18 @@ def setExecutionInputs(weid):
workflow_record = restApiControl.getWorkflowRecord(wid)
winprec = workflow_record["IOCard"]["Inputs"]
# generate input form
form = "<a href=\"/workflowexecutions/"+weid+"\">Back to Execution record "+weid+"</a><br>"
form = "<a href=\"/workflowexecutions/"+weid+"\">Back to Execution detail</a><br>"

form += f"<h3>Workflow: {wid}</h3><br>"
# form += f"<h3>Execution inputs: {wid}</h3><br>"

form += "<table style=\"margin-top: 16px;\" class=\"tableType1\">"
form += "<tr>"
form += "<td>Workflow_ID:</td>"
form += "<td>"
form += str(wid)
form += "</td>"
form += "</tr>"

form += "<table class=\"tableType1\">"
form += "<tr>"
form += "<td>Task_ID:</td>"
form += "<td>"
Expand Down Expand Up @@ -643,8 +650,9 @@ def setExecutionInputs(weid):

show_execution_links = any_execution_link or args.get('show_execution_links', False)

form += "<br>Input record for weid %s<table class=\"tableType1\">" % weid
form += "<tr><th>Name</th><th>Type</th><th>ValueType</th><th>DataID</th><th>Description</th><th>ObjID</th><th>Value</th><th>Units</th>"
form += "<h3>Execution inputs</h3>"
form += "<table class=\"tableType1\">"
form += "<tr><th>Type</th><th>ValueType</th><th>DataID</th><th>Value</th><th>Units</th><th>Name</th><th>Description</th><th>ObjID</th>"
if show_execution_links:
form += "<th>Link_EID</th><th>Link_Name</th><th>Link_ObjID</th>"
if any_edm_path:
Expand All @@ -669,14 +677,12 @@ def setExecutionInputs(weid):
required = ""

form += '<tr>'
form += '<td>' + str(i['Type']).replace('mupif.', '') + '</td>'
form += '<td>' + str(i.get('ValueType', '')) + '</td>'
form += '<td>' + str(i.get('TypeID', '[unknown]')).replace('mupif.DataID.', '') + '</td>'

if input_type == "mupif.Property":
form += '<td>' + str(i['Name']) + '</td>'
form += '<td>' + str(i['Type']) + '</td>'
form += '<td>' + str(i.get('ValueType', '')) + '</td>'
form += '<td>' + str(i.get('TypeID', '[unknown]')).replace('mupif.DataID.', '') + '</td>'
form += '<td>' + str(description) + '</td>'
form += '<td>' + str(i['ObjID']) + '</td>'

form += '<td>'
if execution_record["Status"] == "Created" and i.get('EDMPath', None) is None:
try:
Expand Down Expand Up @@ -706,21 +712,15 @@ def setExecutionInputs(weid):
value = onto_data.get('value', None)
unit = onto_data.get('unit', '')
if value is not None:
form += str(value) + ' ' + str(unit)
form += "<input type=\"text\" name=\"Value_%d\" value=\"%s\" %s/>" % (c, str(value), required)
# form += str(value) + ' ' + str(unit)

else:
if i['Object'].get('Value', None) is not None:
form += str(i['Object']['Value'])
form += "</td>"
form += '<td>' + str(i.get('Units')) + '</td>'

elif input_type == "mupif.String":
form += '<td>' + str(i['Name']) + '</td>'
form += '<td>' + str(i['Type']) + '</td>'
form += '<td>' + str(i.get('ValueType', '')) + '</td>'
form += '<td>' + str(i.get('TypeID', '[unknown]')).replace('mupif.DataID.', '') + '</td>'
form += '<td>' + str(description) + '</td>'
form += '<td>' + str(i['ObjID']) + '</td>'
form += '<td>'
if execution_record["Status"] == "Created" and i.get('EDMPath', None) is None:
try:
Expand Down Expand Up @@ -766,17 +766,15 @@ def setExecutionInputs(weid):
form += str(val)

form += "</td>"
form += '<td>' + str(i.get('Units')) + '</td>'

else:
form += '<td>' + str(i['Name']) + '</td>'
form += '<td>' + str(i['Type']) + '</td>'
form += '<td>' + str(i.get('ValueType', '')) + '</td>'
form += '<td>' + str(i.get('TypeID', '[unknown]')).replace('mupif.DataID.', '') + '</td>'
form += '<td>' + str(description) + '</td>'
form += '<td>' + str(i['ObjID']) + '</td>'
form += '<td>' + str(i.get('Object', {}).get('Value', '')) + '</td>'
form += '<td>' + str(i.get('Units')) + '</td>'

form += '<td>' + str(i.get('Units')) + '</td>'
form += '<td>' + str(i['Name']) + '</td>'

form += '<td>' + str(description) + '</td>'
form += '<td>' + str(i['ObjID']) + '</td>'

if show_execution_links:
if execution_record["Status"] == "Created" and i.get('EDMPath', None) is None:
Expand Down Expand Up @@ -864,10 +862,11 @@ def getExecutionOutputs(weid):

# generate result table form

form = "<a href=\"/workflowexecutions/" + weid + "\">Back to Execution record " + weid + "</a>"
form = "<a href=\"/workflowexecutions/" + weid + "\">Back to Execution detail</a>"

form += f"<h3>Workflow: {wid}</h3>Output record for weid {weid}<table class=\"tableType1\">"
form += "<tr><th>Name</th><th>Type</th><th>ValueType</th><th>DataID</th><th>ObjID</th><th>Value</th><th>Units</th><th>EDMPath</th></tr>"
form += "<h3>Execution outputs</h3>"
form += "<table class=\"tableType1\">"
form += "<tr><th>Type</th><th>ValueType</th><th>DataID</th><th>Value</th><th>Units</th><th>Name</th><th>ObjID</th><th>EDMPath</th></tr>"
for i in execution_outputs:
val = ''

Expand Down Expand Up @@ -903,6 +902,9 @@ def getExecutionOutputs(weid):
except:
pass

if i['Type'] == 'mupif.TemporalProperty':
val = '[...]'

if i['Type'] == 'mupif.String':
if i.get('EDMPath', None) is not None:
onto_path = i.get('EDMPath')
Expand Down Expand Up @@ -938,14 +940,21 @@ def getExecutionOutputs(weid):
except:
pass

if i['Type'] == 'mupif.PyroFile':
try:
if i['Object'].get('FileID') is not None and i['Object'].get('FileID') != '':
val = '<a href="' + RESTserver + 'file/' + str(i['Object'].get('FileID')) + '">download</a>'
except:
pass

form += '<tr>'
form += '<td>' + str(i['Name']) + '</td>'
form += '<td>' + str(i['Type']) + '</td>'
form += '<td>' + str(i.get('ValueType', '')) + '</td>'
form += '<td>' + str(i.get('TypeID', '[unknown]')).replace('mupif.DataID.', '') + '</td>'
form += '<td>' + str(i['ObjID']) + '</td>'
form += '<td>' + str(val) + '</td>'
form += '<td>' + str(escape(i.get('Units'))) + '</td>'
form += '<td>' + str(i['Name']) + '</td>'
form += '<td>' + str(i['ObjID']) + '</td>'
form += '<td>' + str(i.get('EDMPath', '')) + '</td>'
form += "</table>"

Expand Down
Binary file removed webapi/static/images/project-logo.png
Binary file not shown.
2 changes: 1 addition & 1 deletion webapi/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>
<div class="footer">
{% block footer %}
&copy; Copyright 2020 by CTU.
&copy; Copyright CTU in Prague.
{% endblock %}
</div>
</body>
Expand Down
5 changes: 3 additions & 2 deletions webapi/templates/workflows.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{% extends "layout.html" %}
{% block title %} {{ title }} {% endblock %}
{% block content %}
{% block content %}
<h3>List of workflows</h3>
<table class="tableType1">
<tr><th>WID</th><th>UseCaseID</th><th>Description</th><th>Details</th></tr>
<tr><th>WorkflowID</th><th>UseCaseID</th><th>Description</th><th>Detail</th></tr>
{% for item in items %}
<TR>
<TD class="c1">{{item.wid}}</TD>
Expand Down

0 comments on commit d635a20

Please sign in to comment.