Skip to content

Commit

Permalink
Add linked measurements construct
Browse files Browse the repository at this point in the history
  • Loading branch information
UsualSpec committed Jul 1, 2024
1 parent cd83060 commit b87fe72
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
21 changes: 18 additions & 3 deletions server/management/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ def manageRun(runId):
selectedClients = []
for client in clnts:
selectedClients.append(client["client_uid"])

pgcurs.execute("SELECT shared_measurement_id, server_measurement_id FROM measurements WHERE run_id = %(runid)s", {'runid': runId})
pgConnection.commit()
linkedMmts = pgcurs.fetchall()

# only show delete if no measurements are linked
showDelete = not linkedMmts

# Manage timing

Expand All @@ -384,7 +391,7 @@ def manageRun(runId):
stopTime = convertToLocalTime(run["stop_run"]).strftime('%H:%M:%S.%f')[:-3]
stopDate = convertToLocalTime(run["stop_run"]).strftime('%Y-%m-%d')

return render_template("runManagement.html", runId=runId, run=run, duts=duts, clientIds=clientIds, selectedClients=selectedClients, serverTz=get_localzone(), startTime=startTime, startDate=startDate, stopTime=stopTime, stopDate=stopDate, showDelete=True)
return render_template("runManagement.html", runId=runId, run=run, duts=duts, clientIds=clientIds, selectedClients=selectedClients, serverTz=get_localzone(), startTime=startTime, startDate=startDate, stopTime=stopTime, stopDate=stopDate, showDelete=showDelete, linkedMmts=linkedMmts)


@app.route("/runs")
Expand Down Expand Up @@ -437,12 +444,20 @@ def deleteRun(runId):
if not pgcurs.fetchone():
return "This run doesn't exist", 404
try:
pgcurs.execute("SELECT shared_measurement_id FROM measurements WHERE run_id = %(runid)s", {'runid': runId})
pgConnection.commit()
linkedMmts = []
for mmId in pgcurs:
linkedMmts.append(mmId[0])
if linkedMmts != []:
return "Cannot delete run which is still linked to a measurement. Please delete or unlink the measurement(s) " + str(linkedMmts) + " before deleting the run.", 403

pgcurs.execute("DELETE FROM client_runs WHERE run_id = %(runid)s", {'runid': runId})
pgcurs.execute("DELETE FROM runs WHERE run_id = %(runid)s", {'runid': runId})
pgConnection.commit()
except ForeignKeyViolation:
except ForeignKeyViolation as fke:
pgConnection.rollback()
return "Cannot delete run which is still linked to a measurement. Please delete the measurement before deleting the run.", 403
return "Cannot delete run which is still linked to a measurement. Please delete or unlink the measurement(s) before deleting the run. Error: " + str(fke), 403
return str(runId)


Expand Down
9 changes: 9 additions & 0 deletions server/management/templates/runManagement.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
<button id="deleteBtn" class="btn btn-danger mb-2" data-bs-toggle="modal" data-bs-target="#confirmDeletionModal">Delete run</button>
{% endif %}
{% block runheading %}<h2>{{ runId | e}}</h2>{% endblock %}
{% if linkedMmts %}
<div>Linked with
<ul>
{% for mmt in linkedMmts %}
<li><a href="{{ url_for('manageMeasurement', measurementId=mmt.server_measurement_id) }}">{{ mmt.shared_measurement_id | e }}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
<div class="alert p-2" id="runStatus">Enter RUN information</div>
<form id="runForm" method="POST" {% block formaction %}action="{{ url_for('updateRun', runId=runId) }}"{% endblock %} class="bg-light border p-2">
<label for="dut">Device under test</label>
Expand Down

0 comments on commit b87fe72

Please sign in to comment.